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