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