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