Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-ibc-stream.c @ 15470:01ba0511d04d
dsync: Error handling fix when mailbox is unexpectedly lost.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 15 Dec 2012 12:31:56 +0200 |
parents | 05d83c4df130 |
children | 88ac919f8afe |
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', | |
15469
05d83c4df130
dsync: Added -a parameter to sync all namespaces, not just the default one.
Timo Sirainen <tss@iki.fi>
parents:
15464
diff
changeset
|
63 .optional_keys = "sync_ns_prefix 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 } | |
517 | |
518 sync_type[0] = sync_type[1] = '\0'; | |
519 switch (set->sync_type) { | |
520 case DSYNC_BRAIN_SYNC_TYPE_UNKNOWN: | |
521 break; | |
522 case DSYNC_BRAIN_SYNC_TYPE_FULL: | |
523 sync_type[0] = 'f'; | |
524 break; | |
525 case DSYNC_BRAIN_SYNC_TYPE_CHANGED: | |
526 sync_type[0] = 'c'; | |
527 break; | |
528 case DSYNC_BRAIN_SYNC_TYPE_STATE: | |
529 sync_type[0] = 's'; | |
530 break; | |
531 } | |
532 i_assert(sync_type[0] != '\0'); | |
533 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
|
534 if ((set->brain_flags & DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS) != 0) |
14584 | 535 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
|
536 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
|
537 dsync_serializer_encode_add(encoder, "send_guid_requests", ""); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
538 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
|
539 dsync_serializer_encode_add(encoder, "backup_send", ""); |
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_RECV) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
541 dsync_serializer_encode_add(encoder, "backup_recv", ""); |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 dsync_serializer_encode_add(encoder, "sync_all_namespaces", ""); |
14584 | 546 |
547 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
|
548 dsync_ibc_stream_send_string(ibc, str); |
14584 | 549 } |
550 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
551 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
552 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
|
553 const struct dsync_ibc_settings **set_r) |
14584 | 554 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
555 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 556 struct dsync_deserializer_decoder *decoder; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
557 struct dsync_ibc_settings *set; |
14584 | 558 const char *value; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
559 pool_t pool = ibc->ret_pool; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
560 enum dsync_ibc_recv_ret ret; |
14584 | 561 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
562 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
|
563 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
|
564 if (ret != DSYNC_IBC_RECV_RET_TRYAGAIN) { |
14584 | 565 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
|
566 ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
567 dsync_ibc_stream_stop(ibc); |
14584 | 568 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
569 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 570 } |
571 | |
572 p_clear(pool); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
573 set = p_new(pool, struct dsync_ibc_settings, 1); |
14584 | 574 |
575 if (dsync_deserializer_decode_try(decoder, "sync_ns_prefix", &value)) | |
576 set->sync_ns_prefix = p_strdup(pool, value); | |
577 if (dsync_deserializer_decode_try(decoder, "sync_type", &value)) { | |
578 switch (value[0]) { | |
579 case 'f': | |
580 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL; | |
581 break; | |
582 case 'c': | |
583 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_CHANGED; | |
584 break; | |
585 case 's': | |
586 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_STATE; | |
587 break; | |
588 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
589 dsync_ibc_input_error(ibc, decoder, |
14584 | 590 "Unknown sync_type: %s", value); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
591 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 592 } |
593 } | |
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 set->brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_SEND; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
600 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
|
601 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
|
602 if (dsync_deserializer_decode_try(decoder, "debug", &value)) |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
603 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
|
604 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
|
605 set->brain_flags |= DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES; |
14584 | 606 |
607 *set_r = set; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
608 return DSYNC_IBC_RECV_RET_OK; |
14584 | 609 } |
610 | |
611 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
612 dsync_ibc_stream_send_end_of_list(struct dsync_ibc *_ibc) |
14584 | 613 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
614 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 615 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
616 i_assert(ibc->mail_output == NULL); |
14584 | 617 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
618 o_stream_nsend_str(ibc->output, END_OF_LIST_LINE"\n"); |
14584 | 619 } |
620 | |
621 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
622 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
|
623 const struct dsync_mailbox_state *state) |
14584 | 624 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
625 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 626 struct dsync_serializer_encoder *encoder; |
627 string_t *str = t_str_new(128); | |
628 | |
629 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
|
630 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_STATE]); |
14584 | 631 dsync_serializer_encode_add(encoder, "mailbox_guid", |
632 guid_128_to_string(state->mailbox_guid)); | |
633 dsync_serializer_encode_add(encoder, "last_uidvalidity", | |
634 dec2str(state->last_uidvalidity)); | |
635 dsync_serializer_encode_add(encoder, "last_common_uid", | |
636 dec2str(state->last_common_uid)); | |
637 dsync_serializer_encode_add(encoder, "last_common_modseq", | |
638 dec2str(state->last_common_modseq)); | |
639 | |
640 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
|
641 dsync_ibc_stream_send_string(ibc, str); |
14584 | 642 } |
643 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
644 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
645 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
|
646 struct dsync_mailbox_state *state_r) |
14584 | 647 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
648 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 649 struct dsync_deserializer_decoder *decoder; |
650 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
651 enum dsync_ibc_recv_ret ret; |
14584 | 652 |
653 memset(state_r, 0, sizeof(*state_r)); | |
654 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
655 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
|
656 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 657 return ret; |
658 | |
659 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
660 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
|
661 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
|
662 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 663 } |
664 value = dsync_deserializer_decode_get(decoder, "last_uidvalidity"); | |
665 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
|
666 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
|
667 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 668 } |
669 value = dsync_deserializer_decode_get(decoder, "last_common_uid"); | |
670 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
|
671 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
|
672 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 673 } |
674 value = dsync_deserializer_decode_get(decoder, "last_common_modseq"); | |
675 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
|
676 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
|
677 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 678 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
679 return DSYNC_IBC_RECV_RET_OK; |
14584 | 680 } |
681 | |
682 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
683 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
|
684 const char *const *name, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
685 const struct dsync_mailbox_node *node) |
14584 | 686 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
687 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 688 struct dsync_serializer_encoder *encoder; |
689 string_t *str, *namestr; | |
690 | |
691 i_assert(*name != NULL); | |
692 | |
693 str = t_str_new(128); | |
694 str_append_c(str, items[ITEM_MAILBOX_TREE_NODE].chr); | |
695 | |
696 /* convert all hierarchy separators to tabs. mailbox names really | |
697 aren't supposed to have any tabs, but escape them anyway if there | |
698 are. */ | |
699 namestr = t_str_new(128); | |
700 for (; *name != NULL; name++) { | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
701 str_append_tabescaped(namestr, *name); |
14584 | 702 str_append_c(namestr, '\t'); |
703 } | |
704 str_truncate(namestr, str_len(namestr)-1); | |
705 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
706 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_TREE_NODE]); |
14584 | 707 dsync_serializer_encode_add(encoder, "name", str_c(namestr)); |
708 switch (node->existence) { | |
709 case DSYNC_MAILBOX_NODE_NONEXISTENT: | |
710 dsync_serializer_encode_add(encoder, "existence", "n"); | |
711 break; | |
712 case DSYNC_MAILBOX_NODE_EXISTS: | |
713 dsync_serializer_encode_add(encoder, "existence", "y"); | |
714 break; | |
715 case DSYNC_MAILBOX_NODE_DELETED: | |
716 dsync_serializer_encode_add(encoder, "existence", "d"); | |
717 break; | |
718 } | |
719 | |
720 if (!guid_128_is_empty(node->mailbox_guid)) { | |
721 dsync_serializer_encode_add(encoder, "mailbox_guid", | |
722 guid_128_to_string(node->mailbox_guid)); | |
723 } | |
724 if (node->uid_validity != 0) { | |
725 dsync_serializer_encode_add(encoder, "uid_validity", | |
726 dec2str(node->uid_validity)); | |
727 } | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
728 if (node->uid_next != 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
729 dsync_serializer_encode_add(encoder, "uid_next", |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
730 dec2str(node->uid_next)); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
731 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
732 if (node->last_renamed_or_created != 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
733 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
|
734 dec2str(node->last_renamed_or_created)); |
14584 | 735 } |
736 if (node->last_subscription_change != 0) { | |
737 dsync_serializer_encode_add(encoder, "last_subscription_change", | |
738 dec2str(node->last_subscription_change)); | |
739 } | |
740 if (node->subscribed) | |
741 dsync_serializer_encode_add(encoder, "subscribed", ""); | |
742 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
|
743 dsync_ibc_stream_send_string(ibc, str); |
14584 | 744 } |
745 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
746 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
747 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
|
748 const char *const **name_r, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
749 const struct dsync_mailbox_node **node_r) |
14584 | 750 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
751 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 752 struct dsync_deserializer_decoder *decoder; |
753 struct dsync_mailbox_node *node; | |
754 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
755 enum dsync_ibc_recv_ret ret; |
14584 | 756 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
757 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
|
758 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 759 return ret; |
760 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
761 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
762 node = p_new(ibc->ret_pool, struct dsync_mailbox_node, 1); |
14584 | 763 |
764 value = dsync_deserializer_decode_get(decoder, "name"); | |
765 if (*value == '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
766 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
|
767 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 768 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
769 *name_r = (void *)p_strsplit_tabescaped(ibc->ret_pool, value); |
14584 | 770 |
771 value = dsync_deserializer_decode_get(decoder, "existence"); | |
772 switch (*value) { | |
773 case 'n': | |
774 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT; | |
775 break; | |
776 case 'y': | |
777 node->existence = DSYNC_MAILBOX_NODE_EXISTS; | |
778 break; | |
779 case 'd': | |
780 node->existence = DSYNC_MAILBOX_NODE_DELETED; | |
781 break; | |
782 } | |
783 | |
784 if (dsync_deserializer_decode_try(decoder, "mailbox_guid", &value) && | |
785 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
|
786 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
|
787 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 788 } |
789 if (dsync_deserializer_decode_try(decoder, "uid_validity", &value) && | |
790 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
|
791 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
|
792 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 793 } |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
794 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
|
795 str_to_uint32(value, &node->uid_next) < 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
796 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
|
797 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
798 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
799 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
|
800 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
|
801 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
|
802 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 803 } |
804 if (dsync_deserializer_decode_try(decoder, "last_subscription_change", &value) && | |
805 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
|
806 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
|
807 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 808 } |
809 if (dsync_deserializer_decode_try(decoder, "subscribed", &value)) | |
810 node->subscribed = TRUE; | |
811 | |
812 *node_r = node; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
813 return DSYNC_IBC_RECV_RET_OK; |
14584 | 814 } |
815 | |
816 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
817 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
|
818 const struct dsync_mailbox_delete *deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
819 unsigned int count, char hierarchy_sep) |
14584 | 820 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
821 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 822 struct dsync_serializer_encoder *encoder; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
823 string_t *str, *substr; |
14584 | 824 char sep[2]; |
825 unsigned int i; | |
826 | |
827 str = t_str_new(128); | |
828 str_append_c(str, items[ITEM_MAILBOX_DELETE].chr); | |
829 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
830 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_DELETE]); |
14584 | 831 sep[0] = hierarchy_sep; sep[1] = '\0'; |
832 dsync_serializer_encode_add(encoder, "hierarchy_sep", sep); | |
833 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
834 substr = t_str_new(128); |
14584 | 835 for (i = 0; i < count; i++) { |
836 if (deletes[i].delete_mailbox) { | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
837 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
|
838 str_printfa(substr, " %ld ", (long)deletes[i].timestamp); |
14584 | 839 } |
840 } | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
841 if (str_len(substr) > 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
842 str_truncate(substr, str_len(substr)-1); |
14584 | 843 dsync_serializer_encode_add(encoder, "mailboxes", |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
844 str_c(substr)); |
14584 | 845 } |
846 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
847 str_truncate(substr, 0); |
14584 | 848 for (i = 0; i < count; i++) { |
849 if (!deletes[i].delete_mailbox) { | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
850 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
|
851 str_printfa(substr, " %ld ", (long)deletes[i].timestamp); |
14584 | 852 } |
853 } | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
854 if (str_len(substr) > 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
855 str_truncate(substr, str_len(substr)-1); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
856 dsync_serializer_encode_add(encoder, "dirs", str_c(substr)); |
14584 | 857 } |
858 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
|
859 dsync_ibc_stream_send_string(ibc, str); |
14584 | 860 } |
861 | |
862 ARRAY_DEFINE_TYPE(dsync_mailbox_delete, struct dsync_mailbox_delete); | |
863 static int | |
864 decode_mailbox_deletes(ARRAY_TYPE(dsync_mailbox_delete) *deletes, | |
865 const char *value, bool delete_mailbox) | |
866 { | |
867 struct dsync_mailbox_delete *del; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
868 const char *const *tmp; |
14584 | 869 unsigned int i; |
870 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
871 tmp = t_strsplit(value, " "); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
872 for (i = 0; tmp[i] != NULL; i += 2) { |
14584 | 873 del = array_append_space(deletes); |
874 del->delete_mailbox = delete_mailbox; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
875 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
|
876 return -1; |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
877 if (tmp[i+1] == NULL || |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
878 str_to_time(tmp[i+1], &del->timestamp) < 0) |
14584 | 879 return -1; |
880 } | |
881 return 0; | |
882 } | |
883 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
884 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
885 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
|
886 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
|
887 unsigned int *count_r, char *hierarchy_sep_r) |
14584 | 888 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
889 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 890 struct dsync_deserializer_decoder *decoder; |
891 ARRAY_TYPE(dsync_mailbox_delete) deletes; | |
892 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
893 enum dsync_ibc_recv_ret ret; |
14584 | 894 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
895 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
|
896 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 897 return ret; |
898 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
899 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
900 p_array_init(&deletes, ibc->ret_pool, 16); |
14584 | 901 |
902 value = dsync_deserializer_decode_get(decoder, "hierarchy_sep"); | |
903 if (strlen(value) != 1) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
904 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
|
905 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 906 } |
907 *hierarchy_sep_r = value[0]; | |
908 | |
909 if (dsync_deserializer_decode_try(decoder, "mailboxes", &value) && | |
910 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
|
911 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
|
912 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 913 } |
914 if (dsync_deserializer_decode_try(decoder, "dirs", &value) && | |
915 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
|
916 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
|
917 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 918 } |
919 *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
|
920 return DSYNC_IBC_RECV_RET_OK; |
14584 | 921 } |
922 | |
923 static const char * | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
924 get_cache_fields(struct dsync_ibc_stream *ibc, |
14584 | 925 const struct dsync_mailbox *dsync_box) |
926 { | |
927 struct dsync_serializer_encoder *encoder; | |
928 string_t *str; | |
929 const struct mailbox_cache_field *cache_fields; | |
930 unsigned int i, count; | |
931 char decision[3]; | |
932 | |
933 cache_fields = array_get(&dsync_box->cache_fields, &count); | |
934 if (count == 0) | |
935 return ""; | |
936 | |
937 str = t_str_new(128); | |
938 for (i = 0; i < count; i++) { | |
939 const struct mailbox_cache_field *field = &cache_fields[i]; | |
940 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
941 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_CACHE_FIELD]); |
14584 | 942 dsync_serializer_encode_add(encoder, "name", field->name); |
943 | |
944 memset(decision, 0, sizeof(decision)); | |
945 switch (field->decision & ~MAIL_CACHE_DECISION_FORCED) { | |
946 case MAIL_CACHE_DECISION_NO: | |
947 decision[0] = 'n'; | |
948 break; | |
949 case MAIL_CACHE_DECISION_TEMP: | |
950 decision[0] = 't'; | |
951 break; | |
952 case MAIL_CACHE_DECISION_YES: | |
953 decision[0] = 'y'; | |
954 break; | |
955 } | |
956 i_assert(decision[0] != '\0'); | |
957 if ((field->decision & MAIL_CACHE_DECISION_FORCED) != 0) | |
958 decision[1] = 'F'; | |
959 dsync_serializer_encode_add(encoder, "decision", decision); | |
960 if (field->last_used != 0) { | |
961 dsync_serializer_encode_add(encoder, "last_used", | |
962 dec2str(field->last_used)); | |
963 } | |
964 dsync_serializer_encode_finish(&encoder, str); | |
965 } | |
966 if (i > 0) { | |
967 /* remove the trailing LF */ | |
968 str_truncate(str, str_len(str)-1); | |
969 } | |
970 return str_c(str); | |
971 } | |
972 | |
973 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
974 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
|
975 const struct dsync_mailbox *dsync_box) |
14584 | 976 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
977 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 978 struct dsync_serializer_encoder *encoder; |
979 string_t *str = t_str_new(128); | |
980 const char *value; | |
981 | |
982 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
|
983 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX]); |
14584 | 984 dsync_serializer_encode_add(encoder, "mailbox_guid", |
985 guid_128_to_string(dsync_box->mailbox_guid)); | |
986 | |
987 if (dsync_box->mailbox_lost) | |
988 dsync_serializer_encode_add(encoder, "mailbox_lost", ""); | |
989 dsync_serializer_encode_add(encoder, "uid_validity", | |
990 dec2str(dsync_box->uid_validity)); | |
991 dsync_serializer_encode_add(encoder, "uid_next", | |
992 dec2str(dsync_box->uid_next)); | |
993 dsync_serializer_encode_add(encoder, "messages_count", | |
994 dec2str(dsync_box->messages_count)); | |
995 dsync_serializer_encode_add(encoder, "first_recent_uid", | |
996 dec2str(dsync_box->first_recent_uid)); | |
997 dsync_serializer_encode_add(encoder, "highest_modseq", | |
998 dec2str(dsync_box->highest_modseq)); | |
999 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1000 value = get_cache_fields(ibc, dsync_box); |
14584 | 1001 if (value != NULL) |
1002 dsync_serializer_encode_add(encoder, "cache_fields", value); | |
1003 | |
1004 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
|
1005 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1006 } |
1007 | |
1008 static int | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1009 parse_cache_field(struct dsync_ibc_stream *ibc, struct dsync_mailbox *box, |
14584 | 1010 const char *value) |
1011 { | |
1012 struct dsync_deserializer_decoder *decoder; | |
1013 struct mailbox_cache_field field; | |
1014 const char *error; | |
1015 int ret = 0; | |
1016 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1017 if (dsync_deserializer_decode_begin(ibc->deserializers[ITEM_MAILBOX_CACHE_FIELD], |
14584 | 1018 value, &decoder, &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1019 dsync_ibc_input_error(ibc, NULL, |
14584 | 1020 "cache_field: Invalid input: %s", error); |
1021 return -1; | |
1022 } | |
1023 | |
1024 memset(&field, 0, sizeof(field)); | |
1025 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
|
1026 field.name = p_strdup(ibc->ret_pool, value); |
14584 | 1027 |
1028 value = dsync_deserializer_decode_get(decoder, "decision"); | |
1029 switch (*value) { | |
1030 case 'n': | |
1031 field.decision = MAIL_CACHE_DECISION_NO; | |
1032 break; | |
1033 case 't': | |
1034 field.decision = MAIL_CACHE_DECISION_TEMP; | |
1035 break; | |
1036 case 'y': | |
1037 field.decision = MAIL_CACHE_DECISION_YES; | |
1038 break; | |
1039 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1040 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
|
1041 value); |
14584 | 1042 ret = -1; |
1043 break; | |
1044 } | |
1045 if (value[1] == 'F') | |
1046 field.decision |= MAIL_CACHE_DECISION_FORCED; | |
1047 | |
1048 if (dsync_deserializer_decode_try(decoder, "last_used", &value) && | |
1049 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
|
1050 dsync_ibc_input_error(ibc, decoder, "Invalid last_used"); |
14584 | 1051 ret = -1; |
1052 } | |
1053 array_append(&box->cache_fields, &field, 1); | |
1054 | |
1055 dsync_deserializer_decode_finish(&decoder); | |
1056 return ret; | |
1057 } | |
1058 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1059 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1060 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
|
1061 const struct dsync_mailbox **dsync_box_r) |
14584 | 1062 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1063 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
|
1064 pool_t pool = ibc->ret_pool; |
14584 | 1065 struct dsync_deserializer_decoder *decoder; |
1066 struct dsync_mailbox *box; | |
1067 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1068 enum dsync_ibc_recv_ret ret; |
14584 | 1069 |
1070 p_clear(pool); | |
1071 box = p_new(pool, struct dsync_mailbox, 1); | |
1072 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1073 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
|
1074 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1075 return ret; |
1076 | |
1077 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
1078 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
|
1079 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
|
1080 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1081 } |
1082 | |
1083 if (dsync_deserializer_decode_try(decoder, "mailbox_lost", &value)) | |
1084 box->mailbox_lost = TRUE; | |
1085 value = dsync_deserializer_decode_get(decoder, "uid_validity"); | |
1086 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
|
1087 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
|
1088 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1089 } |
1090 value = dsync_deserializer_decode_get(decoder, "uid_next"); | |
1091 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
|
1092 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
|
1093 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1094 } |
1095 value = dsync_deserializer_decode_get(decoder, "messages_count"); | |
1096 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
|
1097 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
|
1098 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1099 } |
1100 value = dsync_deserializer_decode_get(decoder, "first_recent_uid"); | |
1101 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
|
1102 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
|
1103 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1104 } |
1105 value = dsync_deserializer_decode_get(decoder, "highest_modseq"); | |
1106 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
|
1107 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
|
1108 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1109 } |
1110 | |
1111 p_array_init(&box->cache_fields, pool, 32); | |
1112 if (dsync_deserializer_decode_try(decoder, "cache_fields", &value)) { | |
1113 const char *const *fields = t_strsplit(value, "\n"); | |
1114 for (; *fields != NULL; fields++) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1115 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
|
1116 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1117 } |
1118 } | |
1119 | |
1120 *dsync_box_r = box; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1121 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1122 } |
1123 | |
1124 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1125 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
|
1126 const struct dsync_mail_change *change) |
14584 | 1127 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1128 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1129 struct dsync_serializer_encoder *encoder; |
1130 string_t *str = t_str_new(128); | |
1131 char type[2]; | |
1132 | |
1133 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
|
1134 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_CHANGE]); |
14584 | 1135 |
1136 type[0] = type[1] = '\0'; | |
1137 switch (change->type) { | |
1138 case DSYNC_MAIL_CHANGE_TYPE_SAVE: | |
1139 type[0] = 's'; | |
1140 break; | |
1141 case DSYNC_MAIL_CHANGE_TYPE_EXPUNGE: | |
1142 type[0] = 'e'; | |
1143 break; | |
1144 case DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE: | |
1145 type[0] = 'f'; | |
1146 break; | |
1147 } | |
1148 i_assert(type[0] != '\0'); | |
1149 dsync_serializer_encode_add(encoder, "type", type); | |
1150 dsync_serializer_encode_add(encoder, "uid", dec2str(change->uid)); | |
1151 if (change->guid != NULL) | |
1152 dsync_serializer_encode_add(encoder, "guid", change->guid); | |
1153 if (change->hdr_hash != NULL) { | |
1154 dsync_serializer_encode_add(encoder, "hdr_hash", | |
1155 change->hdr_hash); | |
1156 } | |
1157 if (change->modseq != 0) { | |
1158 dsync_serializer_encode_add(encoder, "modseq", | |
1159 dec2str(change->modseq)); | |
1160 } | |
1161 if (change->save_timestamp != 0) { | |
1162 dsync_serializer_encode_add(encoder, "save_timestamp", | |
1163 dec2str(change->save_timestamp)); | |
1164 } | |
1165 if (change->add_flags != 0) { | |
1166 dsync_serializer_encode_add(encoder, "add_flags", | |
1167 t_strdup_printf("%x", change->add_flags)); | |
1168 } | |
1169 if (change->remove_flags != 0) { | |
1170 dsync_serializer_encode_add(encoder, "remove_flags", | |
1171 t_strdup_printf("%x", change->remove_flags)); | |
1172 } | |
1173 if (change->final_flags != 0) { | |
1174 dsync_serializer_encode_add(encoder, "final_flags", | |
1175 t_strdup_printf("%x", change->final_flags)); | |
1176 } | |
1177 if (change->keywords_reset) | |
1178 dsync_serializer_encode_add(encoder, "keywords_reset", ""); | |
1179 | |
1180 if (array_is_created(&change->keyword_changes) && | |
1181 array_count(&change->keyword_changes) > 0) { | |
1182 string_t *kw_str = t_str_new(128); | |
1183 const char *const *changes; | |
1184 unsigned int i, count; | |
1185 | |
1186 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
|
1187 str_append_tabescaped(kw_str, changes[0]); |
14584 | 1188 for (i = 1; i < count; i++) { |
1189 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
|
1190 str_append_tabescaped(kw_str, changes[i]); |
14584 | 1191 } |
1192 dsync_serializer_encode_add(encoder, "keyword_changes", | |
1193 str_c(kw_str)); | |
1194 } | |
1195 | |
1196 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
|
1197 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1198 } |
1199 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1200 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1201 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
|
1202 const struct dsync_mail_change **change_r) |
14584 | 1203 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1204 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
|
1205 pool_t pool = ibc->ret_pool; |
14584 | 1206 struct dsync_deserializer_decoder *decoder; |
1207 struct dsync_mail_change *change; | |
1208 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1209 enum dsync_ibc_recv_ret ret; |
14584 | 1210 |
1211 p_clear(pool); | |
1212 change = p_new(pool, struct dsync_mail_change, 1); | |
1213 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1214 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
|
1215 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1216 return ret; |
1217 | |
1218 value = dsync_deserializer_decode_get(decoder, "type"); | |
1219 switch (*value) { | |
1220 case 's': | |
1221 change->type = DSYNC_MAIL_CHANGE_TYPE_SAVE; | |
1222 break; | |
1223 case 'e': | |
1224 change->type = DSYNC_MAIL_CHANGE_TYPE_EXPUNGE; | |
1225 break; | |
1226 case 'f': | |
1227 change->type = DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE; | |
1228 break; | |
1229 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1230 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
|
1231 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1232 } |
1233 | |
1234 value = dsync_deserializer_decode_get(decoder, "uid"); | |
1235 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
|
1236 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
|
1237 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1238 } |
1239 | |
1240 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1241 change->guid = p_strdup(pool, value); | |
1242 if (dsync_deserializer_decode_try(decoder, "hdr_hash", &value)) | |
1243 change->hdr_hash = p_strdup(pool, value); | |
1244 if (dsync_deserializer_decode_try(decoder, "modseq", &value) && | |
1245 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
|
1246 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
|
1247 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1248 } |
1249 if (dsync_deserializer_decode_try(decoder, "save_timestamp", &value) && | |
1250 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
|
1251 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
|
1252 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1253 } |
1254 | |
1255 if (dsync_deserializer_decode_try(decoder, "add_flags", &value)) | |
1256 change->add_flags = strtoul(value, NULL, 16); | |
1257 if (dsync_deserializer_decode_try(decoder, "remove_flags", &value)) | |
1258 change->remove_flags = strtoul(value, NULL, 16); | |
1259 if (dsync_deserializer_decode_try(decoder, "final_flags", &value)) | |
1260 change->final_flags = strtoul(value, NULL, 16); | |
1261 if (dsync_deserializer_decode_try(decoder, "keywords_reset", &value)) | |
1262 change->keywords_reset = TRUE; | |
1263 | |
1264 if (dsync_deserializer_decode_try(decoder, "keyword_changes", &value) && | |
1265 *value != '\0') { | |
1266 const char *const *changes = t_strsplit_tab(value); | |
1267 unsigned int i, count = str_array_length(changes); | |
1268 | |
1269 p_array_init(&change->keyword_changes, pool, count); | |
1270 for (i = 0; i < count; i++) { | |
1271 value = p_strdup(pool, changes[i]); | |
1272 array_append(&change->keyword_changes, &value, 1); | |
1273 } | |
1274 } | |
1275 | |
1276 *change_r = change; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1277 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1278 } |
1279 | |
1280 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1281 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
|
1282 const struct dsync_mail_request *request) |
14584 | 1283 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1284 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1285 struct dsync_serializer_encoder *encoder; |
1286 string_t *str = t_str_new(128); | |
1287 | |
1288 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
|
1289 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_REQUEST]); |
14584 | 1290 if (request->guid != NULL) |
1291 dsync_serializer_encode_add(encoder, "guid", request->guid); | |
1292 if (request->uid != 0) { | |
1293 dsync_serializer_encode_add(encoder, "uid", | |
1294 dec2str(request->uid)); | |
1295 } | |
1296 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
|
1297 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1298 } |
1299 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1300 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1301 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
|
1302 const struct dsync_mail_request **request_r) |
14584 | 1303 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1304 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1305 struct dsync_deserializer_decoder *decoder; |
1306 struct dsync_mail_request *request; | |
1307 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1308 enum dsync_ibc_recv_ret ret; |
14584 | 1309 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1310 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1311 request = p_new(ibc->ret_pool, struct dsync_mail_request, 1); |
14584 | 1312 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1313 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
|
1314 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1315 return ret; |
1316 | |
1317 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
|
1318 request->guid = p_strdup(ibc->ret_pool, value); |
14584 | 1319 if (dsync_deserializer_decode_try(decoder, "uid", &value) && |
1320 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
|
1321 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
|
1322 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1323 } |
1324 | |
1325 *request_r = request; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1326 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1327 } |
1328 | |
1329 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1330 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
|
1331 const struct dsync_mail *mail) |
14584 | 1332 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1333 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1334 struct dsync_serializer_encoder *encoder; |
1335 string_t *str = t_str_new(128); | |
1336 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1337 i_assert(ibc->mail_output == NULL); |
14584 | 1338 |
1339 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
|
1340 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL]); |
14584 | 1341 if (mail->guid != NULL) |
1342 dsync_serializer_encode_add(encoder, "guid", mail->guid); | |
1343 if (mail->uid != 0) | |
1344 dsync_serializer_encode_add(encoder, "uid", dec2str(mail->uid)); | |
1345 if (mail->pop3_uidl != NULL) { | |
1346 dsync_serializer_encode_add(encoder, "pop3_uidl", | |
1347 mail->pop3_uidl); | |
1348 } | |
1349 if (mail->pop3_order > 0) { | |
1350 dsync_serializer_encode_add(encoder, "pop3_order", | |
1351 dec2str(mail->pop3_order)); | |
1352 } | |
1353 if (mail->received_date > 0) { | |
1354 dsync_serializer_encode_add(encoder, "received_date", | |
1355 dec2str(mail->received_date)); | |
1356 } | |
1357 if (mail->input != NULL) | |
1358 dsync_serializer_encode_add(encoder, "stream", ""); | |
1359 | |
1360 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
|
1361 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1362 |
1363 if (mail->input != NULL) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1364 ibc->mail_output_last = '\0'; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1365 ibc->mail_output = mail->input; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1366 i_stream_ref(ibc->mail_output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1367 (void)dsync_ibc_stream_send_mail_stream(ibc); |
14584 | 1368 } |
1369 } | |
1370 | |
1371 static int seekable_fd_callback(const char **path_r, void *context) | |
1372 { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1373 struct dsync_ibc_stream *ibc = context; |
14584 | 1374 string_t *path; |
1375 int fd; | |
1376 | |
1377 path = t_str_new(128); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1378 str_append(path, ibc->temp_path_prefix); |
14584 | 1379 fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1); |
1380 if (fd == -1) { | |
1381 i_error("safe_mkstemp(%s) failed: %m", str_c(path)); | |
1382 return -1; | |
1383 } | |
1384 | |
1385 /* we just want the fd, unlink it */ | |
1386 if (unlink(str_c(path)) < 0) { | |
1387 /* shouldn't happen.. */ | |
1388 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
|
1389 i_close_fd(&fd); |
14584 | 1390 return -1; |
1391 } | |
1392 | |
1393 *path_r = str_c(path); | |
1394 return fd; | |
1395 } | |
1396 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1397 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1398 dsync_ibc_stream_recv_mail(struct dsync_ibc *_ibc, struct dsync_mail **mail_r) |
14584 | 1399 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1400 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
|
1401 pool_t pool = ibc->ret_pool; |
14584 | 1402 struct dsync_deserializer_decoder *decoder; |
1403 struct dsync_mail *mail; | |
1404 struct istream *inputs[2]; | |
1405 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1406 enum dsync_ibc_recv_ret ret; |
14584 | 1407 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1408 if (ibc->mail_input != NULL) { |
14584 | 1409 /* 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
|
1410 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1411 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1412 if (ibc->cur_mail != NULL) { |
14584 | 1413 /* 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
|
1414 *mail_r = ibc->cur_mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1415 ibc->cur_mail = NULL; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1416 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1417 } |
1418 | |
1419 p_clear(pool); | |
1420 mail = p_new(pool, struct dsync_mail, 1); | |
1421 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1422 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
|
1423 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1424 return ret; |
1425 | |
1426 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1427 mail->guid = p_strdup(pool, value); | |
1428 if (dsync_deserializer_decode_try(decoder, "uid", &value) && | |
1429 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
|
1430 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
|
1431 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1432 } |
1433 if (dsync_deserializer_decode_try(decoder, "pop3_uidl", &value)) | |
1434 mail->pop3_uidl = p_strdup(pool, value); | |
1435 if (dsync_deserializer_decode_try(decoder, "pop3_order", &value) && | |
1436 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
|
1437 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
|
1438 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1439 } |
1440 if (dsync_deserializer_decode_try(decoder, "received_date", &value) && | |
1441 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
|
1442 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
|
1443 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1444 } |
1445 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
|
1446 inputs[0] = i_stream_create_dot(ibc->input, FALSE); |
14584 | 1447 inputs[1] = NULL; |
1448 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
|
1449 MAIL_READ_FULL_BLOCK_SIZE, seekable_fd_callback, ibc); |
14584 | 1450 i_stream_unref(&inputs[0]); |
1451 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1452 ibc->mail_input = mail->input; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1453 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
|
1454 ibc->cur_mail = mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1455 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1456 } |
1457 /* already finished reading the stream */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1458 i_assert(ibc->mail_input == NULL); |
14584 | 1459 } |
1460 | |
1461 *mail_r = mail; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1462 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1463 } |
1464 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1465 static void dsync_ibc_stream_flush(struct dsync_ibc *_ibc) |
14584 | 1466 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1467 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1468 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1469 o_stream_uncork(ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1470 o_stream_cork(ibc->output); |
14584 | 1471 } |
1472 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1473 static bool dsync_ibc_stream_is_send_queue_full(struct dsync_ibc *_ibc) |
14584 | 1474 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1475 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1476 size_t bytes; |
1477 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1478 if (ibc->mail_output != NULL) |
14584 | 1479 return TRUE; |
1480 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1481 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
|
1482 if (bytes < DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE) |
14584 | 1483 return FALSE; |
1484 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1485 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 1486 return TRUE; |
1487 } | |
1488 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1489 static bool dsync_ibc_stream_has_pending_data(struct dsync_ibc *_ibc) |
14584 | 1490 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1491 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1492 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1493 return ibc->has_pending_data; |
14584 | 1494 } |
1495 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1496 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
|
1497 dsync_ibc_stream_deinit, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1498 dsync_ibc_stream_send_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1499 dsync_ibc_stream_recv_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1500 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
|
1501 dsync_ibc_stream_send_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1502 dsync_ibc_stream_recv_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1503 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
|
1504 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
|
1505 dsync_ibc_stream_send_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1506 dsync_ibc_stream_recv_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1507 dsync_ibc_stream_send_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1508 dsync_ibc_stream_recv_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1509 dsync_ibc_stream_send_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1510 dsync_ibc_stream_recv_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1511 dsync_ibc_stream_send_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1512 dsync_ibc_stream_recv_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1513 dsync_ibc_stream_send_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1514 dsync_ibc_stream_recv_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1515 dsync_ibc_stream_flush, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1516 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
|
1517 dsync_ibc_stream_has_pending_data |
14584 | 1518 }; |
1519 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1520 struct dsync_ibc * |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1521 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
|
1522 const char *name, const char *temp_path_prefix) |
14584 | 1523 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1524 struct dsync_ibc_stream *ibc; |
14584 | 1525 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1526 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
|
1527 ibc->ibc.v = dsync_ibc_stream_vfuncs; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1528 ibc->input = input; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1529 ibc->output = output; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1530 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
|
1531 ibc->name = i_strdup(name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1532 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
|
1533 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
|
1534 dsync_ibc_stream_init(ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1535 return &ibc->ibc; |
14584 | 1536 } |