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