Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-ibc-stream.c @ 23017:c1d36f2575c7 default tip
lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author | Timo Sirainen <timo.sirainen@open-xchange.com> |
---|---|
date | Thu, 29 Aug 2019 09:55:25 +0300 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22549
diff
changeset
|
1 /* Copyright (c) 2013-2018 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 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
26 #define DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE (1024*128) |
14584 | 27 |
28 #define DSYNC_PROTOCOL_VERSION_MAJOR 3 | |
22264
e95435889161
dsync: Use header hashing version 3
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22043
diff
changeset
|
29 #define DSYNC_PROTOCOL_VERSION_MINOR 5 |
e95435889161
dsync: Use header hashing version 3
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22043
diff
changeset
|
30 #define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t5\n" |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
31 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
32 #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
|
33 #define DSYNC_PROTOCOL_MINOR_HAVE_SAVE_GUID 2 |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
34 #define DSYNC_PROTOCOL_MINOR_HAVE_FINISH 3 |
19646
25f06710e671
dsync: When comparing headers' hashes to match messages, try to normalize the input.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
35 #define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2 4 |
22264
e95435889161
dsync: Use header hashing version 3
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22043
diff
changeset
|
36 #define DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3 5 |
14584 | 37 |
38 enum item_type { | |
39 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
|
40 ITEM_DONE, |
14584 | 41 |
42 ITEM_HANDSHAKE, | |
43 ITEM_MAILBOX_STATE, | |
44 ITEM_MAILBOX_TREE_NODE, | |
45 ITEM_MAILBOX_DELETE, | |
46 ITEM_MAILBOX, | |
47 | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
48 ITEM_MAILBOX_ATTRIBUTE, |
14584 | 49 ITEM_MAIL_CHANGE, |
50 ITEM_MAIL_REQUEST, | |
51 ITEM_MAIL, | |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
52 ITEM_FINISH, |
14584 | 53 |
54 ITEM_MAILBOX_CACHE_FIELD, | |
55 | |
56 ITEM_END_OF_LIST | |
57 }; | |
58 | |
59 #define END_OF_LIST_LINE "." | |
60 static const struct { | |
61 /* full human readable name of the item */ | |
62 const char *name; | |
63 /* unique character identifying the item */ | |
64 char chr; | |
65 const char *required_keys; | |
66 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
|
67 unsigned int min_minor_version; |
14584 | 68 } 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
|
69 { 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
|
70 { .name = "done", |
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
71 .chr = 'X', |
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
72 .optional_keys = "" |
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
73 }, |
14584 | 74 { .name = "handshake", |
75 .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
|
76 .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
|
77 .optional_keys = "sync_ns_prefix sync_box sync_box_guid sync_type " |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
78 "debug sync_visible_namespaces exclude_mailboxes " |
16563
c2c09416d8a4
dsync: Recent changes broke remote dsync
Timo Sirainen <tss@iki.fi>
parents:
16561
diff
changeset
|
79 "send_mail_requests backup_send backup_recv lock_timeout " |
19021
3fc9658c9712
dsync: Added -D parameter to disable mailbox renaming.
Timo Sirainen <tss@iki.fi>
parents:
19014
diff
changeset
|
80 "no_mail_sync no_mailbox_renames no_backup_overwrite purge_remote " |
22547
ae84a2f539bf
dsync: Add missing space to handshake optional keys
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22494
diff
changeset
|
81 "no_notify sync_since_timestamp sync_max_size sync_flags sync_until_timestamp " |
22549
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
82 "virtual_all_box empty_hdr_workaround import_commit_msgs_interval " |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
83 "hashed_headers" |
14584 | 84 }, |
85 { .name = "mailbox_state", | |
86 .chr = 'S', | |
87 .required_keys = "mailbox_guid last_uidvalidity last_common_uid " | |
17284
cd6079c61c2b
dsync: Fixed new dsync versions to work again with older versions.
Timo Sirainen <tss@iki.fi>
parents:
17282
diff
changeset
|
88 "last_common_modseq last_common_pvt_modseq", |
cd6079c61c2b
dsync: Fixed new dsync versions to work again with older versions.
Timo Sirainen <tss@iki.fi>
parents:
17282
diff
changeset
|
89 .optional_keys = "last_messages_count changes_during_sync" |
14584 | 90 }, |
91 { .name = "mailbox_tree_node", | |
92 .chr = 'N', | |
93 .required_keys = "name existence", | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
94 .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
|
95 "last_renamed_or_created subscribed last_subscription_change" |
14584 | 96 }, |
97 { .name = "mailbox_delete", | |
98 .chr = 'D', | |
99 .required_keys = "hierarchy_sep", | |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
100 .optional_keys = "mailboxes dirs unsubscribes" |
14584 | 101 }, |
102 { .name = "mailbox", | |
103 .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
|
104 .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
|
105 "first_recent_uid highest_modseq highest_pvt_modseq", |
22494
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
106 .optional_keys = "mailbox_lost mailbox_ignore " |
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
107 "cache_fields have_guids have_save_guids have_only_guid128" |
14584 | 108 }, |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
109 { .name = "mailbox_attribute", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
110 .chr = 'A', |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
111 .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
|
112 .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
|
113 .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
|
114 }, |
14584 | 115 { .name = "mail_change", |
116 .chr = 'C', | |
117 .required_keys = "type uid", | |
17296
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
118 .optional_keys = "guid hdr_hash modseq pvt_modseq " |
14584 | 119 "add_flags remove_flags final_flags " |
20641
5c0470a8b5a7
dsync: Added missing fields to ibc-stream.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20633
diff
changeset
|
120 "keywords_reset keyword_changes received_timestamp virtual_size" |
14584 | 121 }, |
122 { .name = "mail_request", | |
123 .chr = 'R', | |
124 .optional_keys = "guid uid" | |
125 }, | |
126 { .name = "mail", | |
127 .chr = 'M', | |
17296
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
128 .optional_keys = "guid uid pop3_uidl pop3_order received_date saved_date stream" |
14584 | 129 }, |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
130 { .name = "finish", |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
131 .chr = 'F', |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
132 .optional_keys = "error mail_error require_full_resync", |
18394
89cbb9347de7
dsync: Don't try to use the new "finish" state with old dsync versions.
Timo Sirainen <tss@iki.fi>
parents:
18375
diff
changeset
|
133 .min_minor_version = DSYNC_PROTOCOL_MINOR_HAVE_FINISH |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
134 }, |
14584 | 135 { .name = "mailbox_cache_field", |
136 .chr = 'c', | |
137 .required_keys = "name decision", | |
138 .optional_keys = "last_used" | |
139 }, | |
140 | |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
141 { "end_of_list", '\0', NULL, NULL, 0 } |
14584 | 142 }; |
143 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
144 struct dsync_ibc_stream { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
145 struct dsync_ibc ibc; |
14584 | 146 |
147 char *name, *temp_path_prefix; | |
19014
11b107c8dc05
dsync: Added -T parameter to specify the I/O stall timeout.
Timo Sirainen <tss@iki.fi>
parents:
18394
diff
changeset
|
148 unsigned int timeout_secs; |
14584 | 149 struct istream *input; |
150 struct ostream *output; | |
151 struct io *io; | |
152 struct timeout *to; | |
153 | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
154 unsigned int minor_version; |
14584 | 155 struct dsync_serializer *serializers[ITEM_END_OF_LIST]; |
156 struct dsync_deserializer *deserializers[ITEM_END_OF_LIST]; | |
157 | |
158 pool_t ret_pool; | |
159 struct dsync_deserializer_decoder *cur_decoder; | |
160 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
161 struct istream *value_output, *value_input; |
14584 | 162 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
|
163 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
|
164 char value_output_last; |
14584 | 165 |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
166 enum item_type last_recv_item, last_sent_item; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
167 unsigned int last_recv_item_eol:1; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
168 unsigned int last_sent_item_eol:1; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
169 |
14584 | 170 unsigned int version_received:1; |
171 unsigned int handshake_received:1; | |
172 unsigned int has_pending_data:1; | |
20197
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
173 unsigned int finish_received:1; |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
174 unsigned int done_received:1; |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
175 unsigned int stopped:1; |
14584 | 176 }; |
177 | |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
178 static const char *dsync_ibc_stream_get_state(struct dsync_ibc_stream *ibc) |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
179 { |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
180 if (!ibc->version_received) |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
181 return "version not received"; |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
182 else if (!ibc->handshake_received) |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
183 return "handshake not received"; |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
184 |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
185 return t_strdup_printf("last sent=%s%s, last recv=%s%s", |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
186 items[ibc->last_sent_item].name, |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
187 ibc->last_sent_item_eol ? " (EOL)" : "", |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
188 items[ibc->last_recv_item].name, |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
189 ibc->last_recv_item_eol ? " (EOL)" : ""); |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
190 } |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
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_stop(struct dsync_ibc_stream *ibc) |
14584 | 193 { |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
194 ibc->stopped = TRUE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
195 i_stream_close(ibc->input); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
196 o_stream_close(ibc->output); |
14584 | 197 io_loop_stop(current_ioloop); |
198 } | |
199 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
200 static int dsync_ibc_stream_read_mail_stream(struct dsync_ibc_stream *ibc) |
14584 | 201 { |
15483
fc6873897e8b
dsync: Minor (probably unnecessary) fix for i_stream_read() API usage.
Timo Sirainen <tss@iki.fi>
parents:
15482
diff
changeset
|
202 do { |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
203 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
|
204 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
|
205 } 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
|
206 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
|
207 if (ibc->value_input->stream_errno != 0) { |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
208 i_error("dsync(%s): read(%s) failed: %s (%s)", ibc->name, |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
209 i_stream_get_name(ibc->value_input), |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
210 i_stream_get_error(ibc->value_input), |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
211 dsync_ibc_stream_get_state(ibc)); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
212 dsync_ibc_stream_stop(ibc); |
14584 | 213 return -1; |
214 } | |
215 /* 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
|
216 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
|
217 i_stream_seek(ibc->value_input, 0); |
15463
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
218 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
|
219 ibc->value_input = NULL; |
14584 | 220 return 1; |
221 } | |
222 return 0; | |
223 } | |
224 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
225 static void dsync_ibc_stream_input(struct dsync_ibc_stream *ibc) |
14584 | 226 { |
17777
647162da8423
dsync: Reset I/O timeout every time when receiving input.
Timo Sirainen <tss@iki.fi>
parents:
17497
diff
changeset
|
227 timeout_reset(ibc->to); |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
228 if (ibc->value_input != NULL) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
229 if (dsync_ibc_stream_read_mail_stream(ibc) == 0) |
14584 | 230 return; |
231 } | |
15594
5bb80a6491eb
dsync: Fixes to handling output stream buffering.
Timo Sirainen <tss@iki.fi>
parents:
15592
diff
changeset
|
232 o_stream_cork(ibc->output); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
233 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
|
234 o_stream_uncork(ibc->output); |
14584 | 235 } |
236 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
237 static int dsync_ibc_stream_send_value_stream(struct dsync_ibc_stream *ibc) |
14584 | 238 { |
239 const unsigned char *data; | |
240 unsigned char add; | |
241 size_t i, size; | |
242 int ret; | |
243 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
244 while ((ret = i_stream_read_data(ibc->value_output, |
14584 | 245 &data, &size, 0)) > 0) { |
246 add = '\0'; | |
247 for (i = 0; i < size; i++) { | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
248 if (data[i] == '.' && |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
249 ((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
|
250 (i > 0 && data[i-1] == '\n'))) { |
14584 | 251 /* escape the dot */ |
252 add = '.'; | |
253 break; | |
254 } | |
255 } | |
256 | |
257 if (i > 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
258 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
|
259 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
|
260 i_stream_skip(ibc->value_output, i); |
14584 | 261 } |
262 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
263 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
|
264 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
|
265 dsync_ibc_stream_stop(ibc); |
14584 | 266 return -1; |
267 } | |
268 if (ret == 0) { | |
269 /* continue later */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
270 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 271 return 0; |
272 } | |
273 } | |
274 | |
275 if (add != '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
276 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
|
277 ibc->value_output_last = add; |
14584 | 278 } |
279 } | |
280 i_assert(ret == -1); | |
281 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
282 if (ibc->value_output->stream_errno != 0) { |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
283 i_error("dsync(%s): read(%s) failed: %s (%s)", |
16940
38f404297728
dsync: Use i_stream_get_error() instead of just errno in stream error messages.
Timo Sirainen <tss@iki.fi>
parents:
16801
diff
changeset
|
284 ibc->name, i_stream_get_name(ibc->value_output), |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
285 i_stream_get_error(ibc->value_output), |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
286 dsync_ibc_stream_get_state(ibc)); |
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 return -1; |
289 } | |
290 | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
291 /* 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
|
292 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
|
293 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
|
294 i_stream_unref(&ibc->value_output); |
14584 | 295 return 1; |
296 } | |
297 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
298 static int dsync_ibc_stream_output(struct dsync_ibc_stream *ibc) |
14584 | 299 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
300 struct ostream *output = ibc->output; |
14584 | 301 int ret; |
302 | |
15482
6f940b2bfbe6
dsync: Fixed hang when sending mail stream to remote dsync.
Timo Sirainen <tss@iki.fi>
parents:
15481
diff
changeset
|
303 o_stream_cork(ibc->output); |
14584 | 304 if ((ret = o_stream_flush(output)) < 0) |
305 ret = 1; | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
306 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
|
307 if (dsync_ibc_stream_send_value_stream(ibc) < 0) |
14584 | 308 ret = 1; |
309 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
310 timeout_reset(ibc->to); |
14584 | 311 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
312 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
|
313 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
|
314 o_stream_uncork(ibc->output); |
14584 | 315 return ret; |
316 } | |
317 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
318 static void dsync_ibc_stream_timeout(struct dsync_ibc_stream *ibc) |
14584 | 319 { |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
320 i_error("dsync(%s): I/O has stalled, no activity for %u seconds (%s)", |
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
321 ibc->name, ibc->timeout_secs, dsync_ibc_stream_get_state(ibc)); |
15986
f6377e089dee
dsync: If I/O gets stalled, log the state in which it happened.
Timo Sirainen <tss@iki.fi>
parents:
15836
diff
changeset
|
322 ibc->ibc.timeout = TRUE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
323 dsync_ibc_stream_stop(ibc); |
14584 | 324 } |
325 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
326 static void dsync_ibc_stream_init(struct dsync_ibc_stream *ibc) |
14584 | 327 { |
328 unsigned int i; | |
329 | |
17192
a1c153c70bb9
Use io_add_istream() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
17170
diff
changeset
|
330 ibc->io = io_add_istream(ibc->input, dsync_ibc_stream_input, ibc); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
331 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
|
332 o_stream_set_flush_callback(ibc->output, dsync_ibc_stream_output, ibc); |
19014
11b107c8dc05
dsync: Added -T parameter to specify the I/O stall timeout.
Timo Sirainen <tss@iki.fi>
parents:
18394
diff
changeset
|
333 ibc->to = timeout_add(ibc->timeout_secs * 1000, |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
334 dsync_ibc_stream_timeout, ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
335 o_stream_cork(ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
336 o_stream_nsend_str(ibc->output, DSYNC_HANDSHAKE_VERSION); |
14584 | 337 |
338 /* 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
|
339 for (i = ITEM_DONE + 1; i < ITEM_END_OF_LIST; i++) T_BEGIN { |
14584 | 340 const char *keys; |
341 | |
342 keys = items[i].required_keys == NULL ? items[i].optional_keys : | |
343 t_strconcat(items[i].required_keys, " ", | |
344 items[i].optional_keys, NULL); | |
345 if (keys != NULL) { | |
346 i_assert(items[i].chr != '\0'); | |
347 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
348 ibc->serializers[i] = |
14584 | 349 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
|
350 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
|
351 o_stream_nsend_str(ibc->output, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
352 dsync_serializer_encode_header_line(ibc->serializers[i])); |
14584 | 353 } |
354 } T_END; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
355 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
|
356 o_stream_uncork(ibc->output); |
14584 | 357 } |
358 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
359 static void dsync_ibc_stream_deinit(struct dsync_ibc *_ibc) |
14584 | 360 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
361 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
16669
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
362 unsigned int i; |
14584 | 363 |
16669
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
364 for (i = ITEM_DONE + 1; i < ITEM_END_OF_LIST; i++) { |
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
365 if (ibc->serializers[i] != NULL) |
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
366 dsync_serializer_deinit(&ibc->serializers[i]); |
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
367 if (ibc->deserializers[i] != NULL) |
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
368 dsync_deserializer_deinit(&ibc->deserializers[i]); |
960f827b7579
dsync: Memory leak fix at deinit.
Timo Sirainen <tss@iki.fi>
parents:
16665
diff
changeset
|
369 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
370 if (ibc->cur_decoder != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
371 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
|
372 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
|
373 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
|
374 else { |
20197
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
375 /* If the remote has not told us that they are closing we |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
376 notify remote that we're closing. this is mainly to avoid |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
377 "read() failed: EOF" errors on failing dsyncs. |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
378 |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
379 Avoid a race condition: |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
380 We do not tell the remote we are closing if they have |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
381 already told us because they close the |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
382 connection after sending ITEM_DONE and will |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
383 not be ever receive anything else from us unless |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
384 it just happens to get combined into the same packet |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
385 as a previous response and is already in the buffer. |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
386 */ |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
387 if (!ibc->done_received && !ibc->finish_received) { |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
388 o_stream_nsend_str(ibc->output, |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
389 t_strdup_printf("%c\n", items[ITEM_DONE].chr)); |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
390 } |
17497
de20b4fa60ac
Added (void) prefix for ignoring return values we don't care about.
Timo Sirainen <tss@iki.fi>
parents:
17296
diff
changeset
|
391 (void)o_stream_nfinish(ibc->output); |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
392 } |
14584 | 393 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
394 timeout_remove(&ibc->to); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
395 if (ibc->io != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
396 io_remove(&ibc->io); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
397 i_stream_destroy(&ibc->input); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
398 o_stream_destroy(&ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
399 pool_unref(&ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
400 i_free(ibc->temp_path_prefix); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
401 i_free(ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
402 i_free(ibc); |
14584 | 403 } |
404 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
405 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
|
406 const char **line_r) |
14584 | 407 { |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
408 string_t *error; |
14584 | 409 const char *line; |
17252 | 410 ssize_t ret; |
14584 | 411 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
412 line = i_stream_next_line(ibc->input); |
14584 | 413 if (line != NULL) { |
414 *line_r = line; | |
415 return 1; | |
416 } | |
417 /* try reading some */ | |
17252 | 418 if ((ret = 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
|
419 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
|
420 return -1; |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
421 error = t_str_new(128); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
422 if (ibc->input->stream_errno != 0) { |
16940
38f404297728
dsync: Use i_stream_get_error() instead of just errno in stream error messages.
Timo Sirainen <tss@iki.fi>
parents:
16801
diff
changeset
|
423 str_printfa(error, "read(%s) failed: %s", ibc->name, |
38f404297728
dsync: Use i_stream_get_error() instead of just errno in stream error messages.
Timo Sirainen <tss@iki.fi>
parents:
16801
diff
changeset
|
424 i_stream_get_error(ibc->input)); |
14584 | 425 } else { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
426 i_assert(ibc->input->eof); |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
427 str_printfa(error, "read(%s) failed: EOF", ibc->name); |
14584 | 428 } |
19090
3abdcbde7f39
dsync: If remote disconnects, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19089
diff
changeset
|
429 str_printfa(error, " (%s)", dsync_ibc_stream_get_state(ibc)); |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
430 i_error("%s", str_c(error)); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
431 dsync_ibc_stream_stop(ibc); |
14584 | 432 return -1; |
433 } | |
17252 | 434 i_assert(ret >= 0); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
435 *line_r = i_stream_next_line(ibc->input); |
14584 | 436 if (*line_r == NULL) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
437 ibc->has_pending_data = FALSE; |
14584 | 438 return 0; |
439 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
440 ibc->has_pending_data = TRUE; |
14584 | 441 return 1; |
442 } | |
443 | |
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
|
444 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
|
445 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
|
446 struct dsync_deserializer_decoder *decoder, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
447 const char *fmt, ...) |
14584 | 448 { |
449 va_list args; | |
450 const char *error; | |
451 | |
452 va_start(args, fmt); | |
453 error = t_strdup_vprintf(fmt, args); | |
454 if (decoder == NULL) | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
455 i_error("dsync(%s): %s", ibc->name, error); |
14584 | 456 else { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
457 i_error("dsync(%s): %s: %s", ibc->name, |
14584 | 458 dsync_deserializer_decoder_get_name(decoder), error); |
459 } | |
460 va_end(args); | |
461 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
462 dsync_ibc_stream_stop(ibc); |
14584 | 463 } |
464 | |
465 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
466 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
|
467 const string_t *str) |
14584 | 468 { |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
469 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
|
470 o_stream_nsend(ibc->output, str_data(str), str_len(str)); |
14584 | 471 } |
472 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
473 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
|
474 { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
475 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
|
476 string_t *path; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
477 int fd; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
478 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
479 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
|
480 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
|
481 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
|
482 if (fd == -1) { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
483 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
|
484 return -1; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
485 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
486 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
487 /* we just want the fd, unlink it */ |
19136
fefaa6d09a81
Replaced unlink() calls with i_unlink*() wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
19090
diff
changeset
|
488 if (i_unlink(str_c(path)) < 0) { |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
489 /* shouldn't happen.. */ |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
490 i_close_fd(&fd); |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
491 return -1; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
492 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
493 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
494 *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
|
495 return fd; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
496 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
497 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
498 static struct istream * |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
499 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
|
500 { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
501 struct istream *inputs[2]; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
502 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
503 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
|
504 inputs[1] = NULL; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
505 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
|
506 seekable_fd_callback, ibc); |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
507 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
|
508 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
509 return ibc->value_input; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
510 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
511 |
15036
5943cace4e05
dsync: Renamed "io" slave to "stream".
Timo Sirainen <tss@iki.fi>
parents:
15035
diff
changeset
|
512 static int |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
513 dsync_ibc_check_missing_deserializers(struct dsync_ibc_stream *ibc) |
14584 | 514 { |
515 unsigned int i; | |
516 int ret = 0; | |
517 | |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
518 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
|
519 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
|
520 ibc->minor_version >= items[i].min_minor_version && |
14584 | 521 (items[i].required_keys != NULL || |
522 items[i].optional_keys != NULL)) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
523 dsync_ibc_input_error(ibc, NULL, |
14584 | 524 "Remote didn't handshake deserializer for %s", |
525 items[i].name); | |
526 ret = -1; | |
527 } | |
528 } | |
529 return ret; | |
530 } | |
531 | |
532 static bool | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
533 dsync_ibc_stream_handshake(struct dsync_ibc_stream *ibc, const char *line) |
14584 | 534 { |
535 enum item_type item = ITEM_NONE; | |
536 const char *const *required_keys, *error; | |
537 unsigned int i; | |
538 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
539 if (ibc->handshake_received) |
14584 | 540 return TRUE; |
541 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
542 if (!ibc->version_received) { |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
543 if (!version_string_verify_full(line, "dsync", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
544 DSYNC_PROTOCOL_VERSION_MAJOR, |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
545 &ibc->minor_version)) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
546 dsync_ibc_input_error(ibc, NULL, |
14584 | 547 "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
|
548 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 549 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
550 ibc->version_received = TRUE; |
14584 | 551 return FALSE; |
552 } | |
553 | |
554 if (strcmp(line, END_OF_LIST_LINE) == 0) { | |
555 /* finished handshaking */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
556 if (dsync_ibc_check_missing_deserializers(ibc) < 0) |
14584 | 557 return FALSE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
558 ibc->handshake_received = TRUE; |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
559 ibc->last_recv_item = ITEM_HANDSHAKE; |
14584 | 560 return FALSE; |
561 } | |
562 | |
563 for (i = 1; i < ITEM_END_OF_LIST; i++) { | |
564 if (items[i].chr == line[0]) { | |
565 item = i; | |
566 break; | |
567 } | |
568 } | |
569 if (item == ITEM_NONE) { | |
570 /* unknown deserializer, ignore */ | |
571 return FALSE; | |
572 } | |
573 | |
574 required_keys = items[item].required_keys == NULL ? NULL : | |
575 t_strsplit(items[item].required_keys, " "); | |
576 if (dsync_deserializer_init(items[item].name, | |
577 required_keys, line + 1, | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
578 &ibc->deserializers[item], &error) < 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
579 dsync_ibc_input_error(ibc, NULL, |
14584 | 580 "Remote sent invalid handshake for %s: %s", |
581 items[item].name, error); | |
582 } | |
583 return FALSE; | |
584 } | |
585 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
586 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
587 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
|
588 struct dsync_deserializer_decoder **decoder_r) |
14584 | 589 { |
590 enum item_type line_item = ITEM_NONE; | |
591 const char *line, *error; | |
592 unsigned int i; | |
593 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
594 i_assert(ibc->value_input == NULL); |
14584 | 595 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
596 timeout_reset(ibc->to); |
14584 | 597 |
598 do { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
599 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
|
600 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
601 } while (!dsync_ibc_stream_handshake(ibc, line)); |
14584 | 602 |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
603 ibc->last_recv_item = item; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
604 ibc->last_recv_item_eol = FALSE; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
605 |
14584 | 606 if (strcmp(line, END_OF_LIST_LINE) == 0) { |
607 /* end of this list */ | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
608 ibc->last_recv_item_eol = TRUE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
609 return DSYNC_IBC_RECV_RET_FINISHED; |
14584 | 610 } |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
611 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
|
612 /* 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
|
613 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
|
614 log any stream errors anyway after this. */ |
20197
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
615 ibc->done_received = TRUE; |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
616 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
|
617 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
|
618 |
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
619 } |
14584 | 620 for (i = 1; i < ITEM_END_OF_LIST; i++) { |
621 if (*line == items[i].chr) { | |
622 line_item = i; | |
623 break; | |
624 } | |
625 } | |
626 if (line_item != item) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
627 dsync_ibc_input_error(ibc, NULL, |
14584 | 628 "Received unexpected input %c != %c", |
629 *line, items[item].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
630 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 631 } |
632 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
633 if (ibc->cur_decoder != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
634 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
|
635 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
|
636 line+1, &ibc->cur_decoder, |
14584 | 637 &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
638 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
|
639 items[item].name, error); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
640 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 641 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
642 *decoder_r = ibc->cur_decoder; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
643 return DSYNC_IBC_RECV_RET_OK; |
14584 | 644 } |
645 | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
646 static struct dsync_serializer_encoder * |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
647 dsync_ibc_send_encode_begin(struct dsync_ibc_stream *ibc, enum item_type item) |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
648 { |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
649 ibc->last_sent_item = item; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
650 ibc->last_sent_item_eol = FALSE; |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
651 return dsync_serializer_encode_begin(ibc->serializers[item]); |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
652 } |
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
653 |
14584 | 654 static void |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
655 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
|
656 const struct dsync_ibc_settings *set) |
14584 | 657 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
658 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 659 struct dsync_serializer_encoder *encoder; |
660 string_t *str = t_str_new(128); | |
661 char sync_type[2]; | |
662 | |
663 str_append_c(str, items[ITEM_HANDSHAKE].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
664 encoder = dsync_ibc_send_encode_begin(ibc, 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
|
665 dsync_serializer_encode_add(encoder, "hostname", set->hostname); |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
666 if (set->sync_ns_prefixes != NULL) { |
14584 | 667 dsync_serializer_encode_add(encoder, "sync_ns_prefix", |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
668 set->sync_ns_prefixes); |
14584 | 669 } |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
670 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
|
671 dsync_serializer_encode_add(encoder, "sync_box", set->sync_box); |
18180
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
672 if (set->virtual_all_box != NULL) { |
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
673 dsync_serializer_encode_add(encoder, "virtual_all_box", |
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
674 set->virtual_all_box); |
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
675 } |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
676 if (set->exclude_mailboxes != NULL) { |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
677 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
|
678 unsigned int i; |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
679 |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
680 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
|
681 if (i != 0) |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
682 str_append_c(substr, '\t'); |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
683 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
|
684 } |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
685 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
|
686 str_c(substr)); |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
687 } |
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
|
688 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
|
689 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
|
690 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
|
691 } |
14584 | 692 |
693 sync_type[0] = sync_type[1] = '\0'; | |
694 switch (set->sync_type) { | |
695 case DSYNC_BRAIN_SYNC_TYPE_UNKNOWN: | |
696 break; | |
697 case DSYNC_BRAIN_SYNC_TYPE_FULL: | |
698 sync_type[0] = 'f'; | |
699 break; | |
700 case DSYNC_BRAIN_SYNC_TYPE_CHANGED: | |
701 sync_type[0] = 'c'; | |
702 break; | |
703 case DSYNC_BRAIN_SYNC_TYPE_STATE: | |
704 sync_type[0] = 's'; | |
705 break; | |
706 } | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
707 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
|
708 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
|
709 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
|
710 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
|
711 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
|
712 } |
22043
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
713 if (set->import_commit_msgs_interval > 0) { |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
714 dsync_serializer_encode_add(encoder, "import_commit_msgs_interval", |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
715 t_strdup_printf("%u", set->import_commit_msgs_interval)); |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
716 } |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
717 if (set->sync_since_timestamp > 0) { |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
718 dsync_serializer_encode_add(encoder, "sync_since_timestamp", |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
719 t_strdup_printf("%ld", (long)set->sync_since_timestamp)); |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
720 } |
20831
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
721 if (set->sync_until_timestamp > 0) { |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
722 dsync_serializer_encode_add(encoder, "sync_until_timestamp", |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
723 t_strdup_printf("%ld", (long)set->sync_since_timestamp)); |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
724 } |
20633
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
725 if (set->sync_max_size > 0) { |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
726 dsync_serializer_encode_add(encoder, "sync_max_size", |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
727 t_strdup_printf("%llu", (unsigned long long)set->sync_max_size)); |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
728 } |
18181
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
729 if (set->sync_flags != NULL) { |
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
730 dsync_serializer_encode_add(encoder, "sync_flags", |
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
731 set->sync_flags); |
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
732 } |
15744
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
733 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
|
734 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
|
735 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
|
736 dsync_serializer_encode_add(encoder, "backup_send", ""); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
737 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
|
738 dsync_serializer_encode_add(encoder, "backup_recv", ""); |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 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
|
744 dsync_serializer_encode_add(encoder, "no_mail_sync", ""); |
19021
3fc9658c9712
dsync: Added -D parameter to disable mailbox renaming.
Timo Sirainen <tss@iki.fi>
parents:
19014
diff
changeset
|
745 if ((set->brain_flags & DSYNC_BRAIN_FLAG_NO_MAILBOX_RENAMES) != 0) |
3fc9658c9712
dsync: Added -D parameter to disable mailbox renaming.
Timo Sirainen <tss@iki.fi>
parents:
19014
diff
changeset
|
746 dsync_serializer_encode_add(encoder, "no_mailbox_renames", ""); |
16561
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16560
diff
changeset
|
747 if ((set->brain_flags & DSYNC_BRAIN_FLAG_NO_BACKUP_OVERWRITE) != 0) |
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16560
diff
changeset
|
748 dsync_serializer_encode_add(encoder, "no_backup_overwrite", ""); |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16681
diff
changeset
|
749 if ((set->brain_flags & DSYNC_BRAIN_FLAG_PURGE_REMOTE) != 0) |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16681
diff
changeset
|
750 dsync_serializer_encode_add(encoder, "purge_remote", ""); |
19318
f9a143c630a5
dsync: Added DSYNC_BRAIN_FLAG_NO_NOTIFY to enable MAILBOX_TRANSACTION_FLAG_NO_NOTIFY
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
751 if ((set->brain_flags & DSYNC_BRAIN_FLAG_NO_NOTIFY) != 0) |
f9a143c630a5
dsync: Added DSYNC_BRAIN_FLAG_NO_NOTIFY to enable MAILBOX_TRANSACTION_FLAG_NO_NOTIFY
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
752 dsync_serializer_encode_add(encoder, "no_notify", ""); |
20595
40ce04c672a4
dsync: Add support for features
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20458
diff
changeset
|
753 if ((set->brain_flags & DSYNC_BRAIN_FLAG_EMPTY_HDR_WORKAROUND) != 0) |
40ce04c672a4
dsync: Add support for features
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20458
diff
changeset
|
754 dsync_serializer_encode_add(encoder, "empty_hdr_workaround", ""); |
22549
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
755 /* this can be NULL in slave */ |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
756 string_t *str2 = t_str_new(32); |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
757 if (set->hashed_headers != NULL) { |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
758 for(const char *const *ptr = set->hashed_headers; *ptr != NULL; ptr++) { |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
759 str_append_tabescaped(str2, *ptr); |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
760 str_append_c(str2, '\t'); |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
761 } |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
762 } |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
763 dsync_serializer_encode_add(encoder, "hashed_headers", str_c(str2)); |
14584 | 764 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
|
765 dsync_ibc_stream_send_string(ibc, str); |
14584 | 766 } |
767 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
768 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
769 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
|
770 const struct dsync_ibc_settings **set_r) |
14584 | 771 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
772 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 773 struct dsync_deserializer_decoder *decoder; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
774 struct dsync_ibc_settings *set; |
14584 | 775 const char *value; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
776 pool_t pool = ibc->ret_pool; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
777 enum dsync_ibc_recv_ret ret; |
14584 | 778 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
779 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
|
780 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
|
781 if (ret != DSYNC_IBC_RECV_RET_TRYAGAIN) { |
14584 | 782 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
|
783 ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
784 dsync_ibc_stream_stop(ibc); |
14584 | 785 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
786 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 787 } |
788 | |
789 p_clear(pool); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
790 set = p_new(pool, struct dsync_ibc_settings, 1); |
14584 | 791 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
792 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
|
793 set->hostname = p_strdup(pool, value); |
16665
7057d4ad8891
dsync: After reading remote hostname, use it for the log messages instead of IP.
Timo Sirainen <tss@iki.fi>
parents:
16563
diff
changeset
|
794 /* now that we know the remote's hostname, use it for the |
7057d4ad8891
dsync: After reading remote hostname, use it for the log messages instead of IP.
Timo Sirainen <tss@iki.fi>
parents:
16563
diff
changeset
|
795 stream's name */ |
7057d4ad8891
dsync: After reading remote hostname, use it for the log messages instead of IP.
Timo Sirainen <tss@iki.fi>
parents:
16563
diff
changeset
|
796 i_free(ibc->name); |
7057d4ad8891
dsync: After reading remote hostname, use it for the log messages instead of IP.
Timo Sirainen <tss@iki.fi>
parents:
16563
diff
changeset
|
797 ibc->name = i_strdup(set->hostname); |
7057d4ad8891
dsync: After reading remote hostname, use it for the log messages instead of IP.
Timo Sirainen <tss@iki.fi>
parents:
16563
diff
changeset
|
798 |
14584 | 799 if (dsync_deserializer_decode_try(decoder, "sync_ns_prefix", &value)) |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
800 set->sync_ns_prefixes = 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
|
801 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
|
802 set->sync_box = p_strdup(pool, value); |
18180
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
803 if (dsync_deserializer_decode_try(decoder, "virtual_all_box", &value)) |
39d00448490f
dsync: If same GUID already exists in storage, try to copy it instead of recreating the mail.
Timo Sirainen <tss@iki.fi>
parents:
18177
diff
changeset
|
804 set->virtual_all_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
|
805 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
|
806 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
|
807 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
|
808 "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
|
809 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
|
810 } |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
811 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
|
812 *value != '\0') { |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
813 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
|
814 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
|
815 } |
14584 | 816 if (dsync_deserializer_decode_try(decoder, "sync_type", &value)) { |
817 switch (value[0]) { | |
818 case 'f': | |
819 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL; | |
820 break; | |
821 case 'c': | |
822 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_CHANGED; | |
823 break; | |
824 case 's': | |
825 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_STATE; | |
826 break; | |
827 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
828 dsync_ibc_input_error(ibc, decoder, |
14584 | 829 "Unknown sync_type: %s", value); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
830 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 831 } |
832 } | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
833 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
|
834 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
|
835 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
|
836 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
|
837 "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
|
838 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
|
839 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
840 } |
22043
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
841 if (dsync_deserializer_decode_try(decoder, "import_commit_msgs_interval", &value)) { |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
842 if (str_to_uint(value, &set->import_commit_msgs_interval) < 0 || |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
843 set->import_commit_msgs_interval == 0) { |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
844 dsync_ibc_input_error(ibc, decoder, |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
845 "Invalid import_commit_msgs_interval: %s", value); |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
846 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
847 } |
81e013b3207d
dsync: Try to commit transactions every dsync_commit_msgs_interval messages
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21971
diff
changeset
|
848 } |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
849 if (dsync_deserializer_decode_try(decoder, "sync_since_timestamp", &value)) { |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
850 if (str_to_time(value, &set->sync_since_timestamp) < 0 || |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
851 set->sync_since_timestamp == 0) { |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
852 dsync_ibc_input_error(ibc, decoder, |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
853 "Invalid sync_since_timestamp: %s", value); |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
854 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
855 } |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
856 } |
20831
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
857 if (dsync_deserializer_decode_try(decoder, "sync_until_timestamp", &value)) { |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
858 if (str_to_time(value, &set->sync_until_timestamp) < 0 || |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
859 set->sync_until_timestamp == 0) { |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
860 dsync_ibc_input_error(ibc, decoder, |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
861 "Invalid sync_until_timestamp: %s", value); |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
862 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
863 } |
0c4e5c2725a3
doveadm-sync: Add end-date support
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20642
diff
changeset
|
864 } |
20633
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
865 if (dsync_deserializer_decode_try(decoder, "sync_max_size", &value)) { |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
866 if (str_to_uoff(value, &set->sync_max_size) < 0 || |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
867 set->sync_max_size == 0) { |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
868 dsync_ibc_input_error(ibc, decoder, |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
869 "Invalid sync_max_size: %s", value); |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
870 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
871 } |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
872 } |
18181
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
873 if (dsync_deserializer_decode_try(decoder, "sync_flags", &value)) |
35e4a6ae8d85
dsync: Added -F parameter to sync only mails with[out] specific flag.
Timo Sirainen <tss@iki.fi>
parents:
18180
diff
changeset
|
874 set->sync_flags = p_strdup(pool, value); |
15744
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
875 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
|
876 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
|
877 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
|
878 set->brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_SEND; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
879 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
|
880 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
|
881 if (dsync_deserializer_decode_try(decoder, "debug", &value)) |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
882 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
|
883 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
|
884 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
|
885 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
|
886 set->brain_flags |= DSYNC_BRAIN_FLAG_NO_MAIL_SYNC; |
19021
3fc9658c9712
dsync: Added -D parameter to disable mailbox renaming.
Timo Sirainen <tss@iki.fi>
parents:
19014
diff
changeset
|
887 if (dsync_deserializer_decode_try(decoder, "no_mailbox_renames", &value)) |
3fc9658c9712
dsync: Added -D parameter to disable mailbox renaming.
Timo Sirainen <tss@iki.fi>
parents:
19014
diff
changeset
|
888 set->brain_flags |= DSYNC_BRAIN_FLAG_NO_MAILBOX_RENAMES; |
16561
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16560
diff
changeset
|
889 if (dsync_deserializer_decode_try(decoder, "no_backup_overwrite", &value)) |
0144704e1b99
dsync: Added -1 parameter to do a "one way sync" without reverting changes.
Timo Sirainen <tss@iki.fi>
parents:
16560
diff
changeset
|
890 set->brain_flags |= DSYNC_BRAIN_FLAG_NO_BACKUP_OVERWRITE; |
16801
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16681
diff
changeset
|
891 if (dsync_deserializer_decode_try(decoder, "purge_remote", &value)) |
56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
Timo Sirainen <tss@iki.fi>
parents:
16681
diff
changeset
|
892 set->brain_flags |= DSYNC_BRAIN_FLAG_PURGE_REMOTE; |
19318
f9a143c630a5
dsync: Added DSYNC_BRAIN_FLAG_NO_NOTIFY to enable MAILBOX_TRANSACTION_FLAG_NO_NOTIFY
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
893 if (dsync_deserializer_decode_try(decoder, "no_notify", &value)) |
f9a143c630a5
dsync: Added DSYNC_BRAIN_FLAG_NO_NOTIFY to enable MAILBOX_TRANSACTION_FLAG_NO_NOTIFY
Timo Sirainen <tss@iki.fi>
parents:
19191
diff
changeset
|
894 set->brain_flags |= DSYNC_BRAIN_FLAG_NO_NOTIFY; |
20595
40ce04c672a4
dsync: Add support for features
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20458
diff
changeset
|
895 if (dsync_deserializer_decode_try(decoder, "empty_hdr_workaround", &value)) |
40ce04c672a4
dsync: Add support for features
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
20458
diff
changeset
|
896 set->brain_flags |= DSYNC_BRAIN_FLAG_EMPTY_HDR_WORKAROUND; |
22549
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
897 if (dsync_deserializer_decode_try(decoder, "hashed_headers", &value)) |
400ff84f109d
dsync: Add hashed_headers setting
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22547
diff
changeset
|
898 set->hashed_headers = (const char*const*)p_strsplit_tabescaped(pool, value); |
19646
25f06710e671
dsync: When comparing headers' hashes to match messages, try to normalize the input.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
899 set->hdr_hash_v2 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V2; |
22264
e95435889161
dsync: Use header hashing version 3
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22043
diff
changeset
|
900 set->hdr_hash_v3 = ibc->minor_version >= DSYNC_PROTOCOL_MINOR_HAVE_HDR_HASH_V3; |
14584 | 901 |
902 *set_r = set; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
903 return DSYNC_IBC_RECV_RET_OK; |
14584 | 904 } |
905 | |
906 static void | |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
907 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
|
908 enum dsync_ibc_eol_type type) |
14584 | 909 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
910 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 911 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
912 i_assert(ibc->value_output == NULL); |
14584 | 913 |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
914 switch (type) { |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
915 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
|
916 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
|
917 return; |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
918 break; |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
919 default: |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
920 break; |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
921 } |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
922 |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
923 ibc->last_sent_item_eol = TRUE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
924 o_stream_nsend_str(ibc->output, END_OF_LIST_LINE"\n"); |
14584 | 925 } |
926 | |
927 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
928 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
|
929 const struct dsync_mailbox_state *state) |
14584 | 930 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
931 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 932 struct dsync_serializer_encoder *encoder; |
933 string_t *str = t_str_new(128); | |
934 | |
935 str_append_c(str, items[ITEM_MAILBOX_STATE].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
936 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAILBOX_STATE); |
14584 | 937 dsync_serializer_encode_add(encoder, "mailbox_guid", |
938 guid_128_to_string(state->mailbox_guid)); | |
939 dsync_serializer_encode_add(encoder, "last_uidvalidity", | |
940 dec2str(state->last_uidvalidity)); | |
941 dsync_serializer_encode_add(encoder, "last_common_uid", | |
942 dec2str(state->last_common_uid)); | |
943 dsync_serializer_encode_add(encoder, "last_common_modseq", | |
944 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
|
945 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
|
946 dec2str(state->last_common_pvt_modseq)); |
17282
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17252
diff
changeset
|
947 dsync_serializer_encode_add(encoder, "last_messages_count", |
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17252
diff
changeset
|
948 dec2str(state->last_messages_count)); |
15783
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
949 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
|
950 dsync_serializer_encode_add(encoder, "changes_during_sync", ""); |
14584 | 951 |
952 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
|
953 dsync_ibc_stream_send_string(ibc, str); |
14584 | 954 } |
955 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
956 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
957 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
|
958 struct dsync_mailbox_state *state_r) |
14584 | 959 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
960 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 961 struct dsync_deserializer_decoder *decoder; |
962 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
963 enum dsync_ibc_recv_ret ret; |
14584 | 964 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
20831
diff
changeset
|
965 i_zero(state_r); |
14584 | 966 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
967 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
|
968 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 969 return ret; |
970 | |
971 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
972 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
|
973 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
|
974 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 975 } |
976 value = dsync_deserializer_decode_get(decoder, "last_uidvalidity"); | |
977 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
|
978 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
|
979 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 980 } |
981 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
|
982 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
|
983 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
|
984 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 985 } |
986 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
|
987 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
|
988 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
|
989 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 990 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
991 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
|
992 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
|
993 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
|
994 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
|
995 } |
17286
507aee5fef6d
dsync: Yet another fix to working with old versions.
Timo Sirainen <tss@iki.fi>
parents:
17284
diff
changeset
|
996 if (dsync_deserializer_decode_try(decoder, "last_messages_count", &value) && |
507aee5fef6d
dsync: Yet another fix to working with old versions.
Timo Sirainen <tss@iki.fi>
parents:
17284
diff
changeset
|
997 str_to_uint32(value, &state_r->last_messages_count) < 0) { |
17282
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17252
diff
changeset
|
998 dsync_ibc_input_error(ibc, decoder, "Invalid last_messages_count"); |
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17252
diff
changeset
|
999 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
9669c9a8984f
dsync: Include messages_count in the mailbox states.
Timo Sirainen <tss@iki.fi>
parents:
17252
diff
changeset
|
1000 } |
15783
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
1001 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
|
1002 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
|
1003 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1004 } |
1005 | |
1006 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1007 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
|
1008 const char *const *name, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1009 const struct dsync_mailbox_node *node) |
14584 | 1010 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1011 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1012 struct dsync_serializer_encoder *encoder; |
1013 string_t *str, *namestr; | |
1014 | |
1015 i_assert(*name != NULL); | |
1016 | |
1017 str = t_str_new(128); | |
1018 str_append_c(str, items[ITEM_MAILBOX_TREE_NODE].chr); | |
1019 | |
1020 /* convert all hierarchy separators to tabs. mailbox names really | |
1021 aren't supposed to have any tabs, but escape them anyway if there | |
1022 are. */ | |
1023 namestr = t_str_new(128); | |
1024 for (; *name != NULL; name++) { | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
1025 str_append_tabescaped(namestr, *name); |
14584 | 1026 str_append_c(namestr, '\t'); |
1027 } | |
1028 str_truncate(namestr, str_len(namestr)-1); | |
1029 | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1030 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAILBOX_TREE_NODE); |
14584 | 1031 dsync_serializer_encode_add(encoder, "name", str_c(namestr)); |
1032 switch (node->existence) { | |
1033 case DSYNC_MAILBOX_NODE_NONEXISTENT: | |
1034 dsync_serializer_encode_add(encoder, "existence", "n"); | |
1035 break; | |
1036 case DSYNC_MAILBOX_NODE_EXISTS: | |
1037 dsync_serializer_encode_add(encoder, "existence", "y"); | |
1038 break; | |
1039 case DSYNC_MAILBOX_NODE_DELETED: | |
1040 dsync_serializer_encode_add(encoder, "existence", "d"); | |
1041 break; | |
1042 } | |
1043 | |
1044 if (!guid_128_is_empty(node->mailbox_guid)) { | |
1045 dsync_serializer_encode_add(encoder, "mailbox_guid", | |
1046 guid_128_to_string(node->mailbox_guid)); | |
1047 } | |
1048 if (node->uid_validity != 0) { | |
1049 dsync_serializer_encode_add(encoder, "uid_validity", | |
1050 dec2str(node->uid_validity)); | |
1051 } | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1052 if (node->uid_next != 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1053 dsync_serializer_encode_add(encoder, "uid_next", |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1054 dec2str(node->uid_next)); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1055 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1056 if (node->last_renamed_or_created != 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1057 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
|
1058 dec2str(node->last_renamed_or_created)); |
14584 | 1059 } |
1060 if (node->last_subscription_change != 0) { | |
1061 dsync_serializer_encode_add(encoder, "last_subscription_change", | |
1062 dec2str(node->last_subscription_change)); | |
1063 } | |
1064 if (node->subscribed) | |
1065 dsync_serializer_encode_add(encoder, "subscribed", ""); | |
1066 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
|
1067 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1068 } |
1069 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1070 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1071 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
|
1072 const char *const **name_r, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1073 const struct dsync_mailbox_node **node_r) |
14584 | 1074 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1075 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1076 struct dsync_deserializer_decoder *decoder; |
1077 struct dsync_mailbox_node *node; | |
1078 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1079 enum dsync_ibc_recv_ret ret; |
14584 | 1080 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1081 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
|
1082 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1083 return ret; |
1084 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1085 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1086 node = p_new(ibc->ret_pool, struct dsync_mailbox_node, 1); |
14584 | 1087 |
1088 value = dsync_deserializer_decode_get(decoder, "name"); | |
1089 if (*value == '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1090 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
|
1091 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1092 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1093 *name_r = (void *)p_strsplit_tabescaped(ibc->ret_pool, value); |
14584 | 1094 |
1095 value = dsync_deserializer_decode_get(decoder, "existence"); | |
1096 switch (*value) { | |
1097 case 'n': | |
1098 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT; | |
1099 break; | |
1100 case 'y': | |
1101 node->existence = DSYNC_MAILBOX_NODE_EXISTS; | |
1102 break; | |
1103 case 'd': | |
1104 node->existence = DSYNC_MAILBOX_NODE_DELETED; | |
1105 break; | |
1106 } | |
1107 | |
1108 if (dsync_deserializer_decode_try(decoder, "mailbox_guid", &value) && | |
1109 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
|
1110 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
|
1111 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1112 } |
1113 if (dsync_deserializer_decode_try(decoder, "uid_validity", &value) && | |
1114 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
|
1115 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
|
1116 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1117 } |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1118 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
|
1119 str_to_uint32(value, &node->uid_next) < 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1120 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
|
1121 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
1122 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1123 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
|
1124 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
|
1125 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
|
1126 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1127 } |
1128 if (dsync_deserializer_decode_try(decoder, "last_subscription_change", &value) && | |
1129 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
|
1130 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
|
1131 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1132 } |
1133 if (dsync_deserializer_decode_try(decoder, "subscribed", &value)) | |
1134 node->subscribed = TRUE; | |
1135 | |
1136 *node_r = node; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1137 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1138 } |
1139 | |
1140 static void | |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1141 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
|
1142 struct dsync_serializer_encoder *encoder, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1143 const struct dsync_mailbox_delete *deletes, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1144 unsigned int count, const char *key, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1145 enum dsync_mailbox_delete_type type) |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1146 { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1147 unsigned int i; |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1148 |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1149 str_truncate(str, 0); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1150 for (i = 0; i < count; i++) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1151 if (deletes[i].type == type) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1152 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
|
1153 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
|
1154 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1155 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1156 if (str_len(str) > 0) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1157 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
|
1158 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
|
1159 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1160 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1161 |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1162 static void |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1163 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
|
1164 const struct dsync_mailbox_delete *deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1165 unsigned int count, char hierarchy_sep) |
14584 | 1166 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1167 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1168 struct dsync_serializer_encoder *encoder; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1169 string_t *str, *substr; |
14584 | 1170 char sep[2]; |
1171 | |
1172 str = t_str_new(128); | |
1173 str_append_c(str, items[ITEM_MAILBOX_DELETE].chr); | |
1174 | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1175 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAILBOX_DELETE); |
14584 | 1176 sep[0] = hierarchy_sep; sep[1] = '\0'; |
1177 dsync_serializer_encode_add(encoder, "hierarchy_sep", sep); | |
1178 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1179 substr = t_str_new(128); |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1180 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
|
1181 "mailboxes", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1182 DSYNC_MAILBOX_DELETE_TYPE_MAILBOX); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1183 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
|
1184 "dirs", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1185 DSYNC_MAILBOX_DELETE_TYPE_DIR); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1186 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
|
1187 "unsubscribes", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1188 DSYNC_MAILBOX_DELETE_TYPE_UNSUBSCRIBE); |
14584 | 1189 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
|
1190 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1191 } |
1192 | |
1193 ARRAY_DEFINE_TYPE(dsync_mailbox_delete, struct dsync_mailbox_delete); | |
1194 static int | |
1195 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
|
1196 const char *value, enum dsync_mailbox_delete_type type) |
14584 | 1197 { |
1198 struct dsync_mailbox_delete *del; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1199 const char *const *tmp; |
14584 | 1200 unsigned int i; |
1201 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1202 tmp = t_strsplit(value, " "); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1203 for (i = 0; tmp[i] != NULL; i += 2) { |
14584 | 1204 del = array_append_space(deletes); |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1205 del->type = type; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1206 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
|
1207 return -1; |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1208 if (tmp[i+1] == NULL || |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1209 str_to_time(tmp[i+1], &del->timestamp) < 0) |
14584 | 1210 return -1; |
1211 } | |
1212 return 0; | |
1213 } | |
1214 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1215 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1216 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
|
1217 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
|
1218 unsigned int *count_r, char *hierarchy_sep_r) |
14584 | 1219 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1220 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1221 struct dsync_deserializer_decoder *decoder; |
1222 ARRAY_TYPE(dsync_mailbox_delete) deletes; | |
1223 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1224 enum dsync_ibc_recv_ret ret; |
14584 | 1225 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1226 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
|
1227 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1228 return ret; |
1229 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1230 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1231 p_array_init(&deletes, ibc->ret_pool, 16); |
14584 | 1232 |
1233 value = dsync_deserializer_decode_get(decoder, "hierarchy_sep"); | |
1234 if (strlen(value) != 1) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1235 dsync_ibc_input_error(ibc, decoder, "Invalid hierarchy_sep"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1236 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1237 } |
1238 *hierarchy_sep_r = value[0]; | |
1239 | |
1240 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
|
1241 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1242 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
|
1243 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
|
1244 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1245 } |
1246 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
|
1247 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1248 DSYNC_MAILBOX_DELETE_TYPE_DIR) < 0) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1249 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
|
1250 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1251 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1252 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
|
1253 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1254 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
|
1255 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
|
1256 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1257 } |
1258 *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
|
1259 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1260 } |
1261 | |
1262 static const char * | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1263 get_cache_fields(struct dsync_ibc_stream *ibc, |
14584 | 1264 const struct dsync_mailbox *dsync_box) |
1265 { | |
1266 struct dsync_serializer_encoder *encoder; | |
1267 string_t *str; | |
1268 const struct mailbox_cache_field *cache_fields; | |
1269 unsigned int i, count; | |
1270 char decision[3]; | |
1271 | |
1272 cache_fields = array_get(&dsync_box->cache_fields, &count); | |
1273 if (count == 0) | |
1274 return ""; | |
1275 | |
1276 str = t_str_new(128); | |
1277 for (i = 0; i < count; i++) { | |
1278 const struct mailbox_cache_field *field = &cache_fields[i]; | |
1279 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1280 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_CACHE_FIELD]); |
14584 | 1281 dsync_serializer_encode_add(encoder, "name", field->name); |
1282 | |
1283 memset(decision, 0, sizeof(decision)); | |
1284 switch (field->decision & ~MAIL_CACHE_DECISION_FORCED) { | |
1285 case MAIL_CACHE_DECISION_NO: | |
1286 decision[0] = 'n'; | |
1287 break; | |
1288 case MAIL_CACHE_DECISION_TEMP: | |
1289 decision[0] = 't'; | |
1290 break; | |
1291 case MAIL_CACHE_DECISION_YES: | |
1292 decision[0] = 'y'; | |
1293 break; | |
1294 } | |
1295 i_assert(decision[0] != '\0'); | |
1296 if ((field->decision & MAIL_CACHE_DECISION_FORCED) != 0) | |
1297 decision[1] = 'F'; | |
1298 dsync_serializer_encode_add(encoder, "decision", decision); | |
1299 if (field->last_used != 0) { | |
1300 dsync_serializer_encode_add(encoder, "last_used", | |
1301 dec2str(field->last_used)); | |
1302 } | |
1303 dsync_serializer_encode_finish(&encoder, str); | |
1304 } | |
1305 if (i > 0) { | |
1306 /* remove the trailing LF */ | |
1307 str_truncate(str, str_len(str)-1); | |
1308 } | |
1309 return str_c(str); | |
1310 } | |
1311 | |
1312 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1313 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
|
1314 const struct dsync_mailbox *dsync_box) |
14584 | 1315 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1316 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1317 struct dsync_serializer_encoder *encoder; |
1318 string_t *str = t_str_new(128); | |
1319 const char *value; | |
1320 | |
1321 str_append_c(str, items[ITEM_MAILBOX].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1322 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAILBOX); |
14584 | 1323 dsync_serializer_encode_add(encoder, "mailbox_guid", |
1324 guid_128_to_string(dsync_box->mailbox_guid)); | |
1325 | |
1326 if (dsync_box->mailbox_lost) | |
1327 dsync_serializer_encode_add(encoder, "mailbox_lost", ""); | |
22494
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
1328 if (dsync_box->mailbox_ignore) |
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
1329 dsync_serializer_encode_add(encoder, "mailbox_ignore", ""); |
15750
5a1fc3723371
dsync: Automatically figure out which mailboxes can sync with message GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
15744
diff
changeset
|
1330 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
|
1331 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
|
1332 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
|
1333 dsync_serializer_encode_add(encoder, "have_save_guids", ""); |
16977
8a7ecddca4ad
dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
16940
diff
changeset
|
1334 if (dsync_box->have_only_guid128) |
8a7ecddca4ad
dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
16940
diff
changeset
|
1335 dsync_serializer_encode_add(encoder, "have_only_guid128", ""); |
14584 | 1336 dsync_serializer_encode_add(encoder, "uid_validity", |
1337 dec2str(dsync_box->uid_validity)); | |
1338 dsync_serializer_encode_add(encoder, "uid_next", | |
1339 dec2str(dsync_box->uid_next)); | |
1340 dsync_serializer_encode_add(encoder, "messages_count", | |
1341 dec2str(dsync_box->messages_count)); | |
1342 dsync_serializer_encode_add(encoder, "first_recent_uid", | |
1343 dec2str(dsync_box->first_recent_uid)); | |
1344 dsync_serializer_encode_add(encoder, "highest_modseq", | |
1345 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
|
1346 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
|
1347 dec2str(dsync_box->highest_pvt_modseq)); |
14584 | 1348 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1349 value = get_cache_fields(ibc, dsync_box); |
14584 | 1350 if (value != NULL) |
1351 dsync_serializer_encode_add(encoder, "cache_fields", value); | |
1352 | |
1353 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
|
1354 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1355 } |
1356 | |
1357 static int | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1358 parse_cache_field(struct dsync_ibc_stream *ibc, struct dsync_mailbox *box, |
14584 | 1359 const char *value) |
1360 { | |
1361 struct dsync_deserializer_decoder *decoder; | |
1362 struct mailbox_cache_field field; | |
1363 const char *error; | |
1364 int ret = 0; | |
1365 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1366 if (dsync_deserializer_decode_begin(ibc->deserializers[ITEM_MAILBOX_CACHE_FIELD], |
14584 | 1367 value, &decoder, &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1368 dsync_ibc_input_error(ibc, NULL, |
14584 | 1369 "cache_field: Invalid input: %s", error); |
1370 return -1; | |
1371 } | |
1372 | |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
20831
diff
changeset
|
1373 i_zero(&field); |
14584 | 1374 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
|
1375 field.name = p_strdup(ibc->ret_pool, value); |
14584 | 1376 |
1377 value = dsync_deserializer_decode_get(decoder, "decision"); | |
1378 switch (*value) { | |
1379 case 'n': | |
1380 field.decision = MAIL_CACHE_DECISION_NO; | |
1381 break; | |
1382 case 't': | |
1383 field.decision = MAIL_CACHE_DECISION_TEMP; | |
1384 break; | |
1385 case 'y': | |
1386 field.decision = MAIL_CACHE_DECISION_YES; | |
1387 break; | |
1388 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1389 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
|
1390 value); |
14584 | 1391 ret = -1; |
1392 break; | |
1393 } | |
1394 if (value[1] == 'F') | |
1395 field.decision |= MAIL_CACHE_DECISION_FORCED; | |
1396 | |
1397 if (dsync_deserializer_decode_try(decoder, "last_used", &value) && | |
1398 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
|
1399 dsync_ibc_input_error(ibc, decoder, "Invalid last_used"); |
14584 | 1400 ret = -1; |
1401 } | |
1402 array_append(&box->cache_fields, &field, 1); | |
1403 | |
1404 dsync_deserializer_decode_finish(&decoder); | |
1405 return ret; | |
1406 } | |
1407 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1408 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1409 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
|
1410 const struct dsync_mailbox **dsync_box_r) |
14584 | 1411 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1412 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
|
1413 pool_t pool = ibc->ret_pool; |
14584 | 1414 struct dsync_deserializer_decoder *decoder; |
1415 struct dsync_mailbox *box; | |
1416 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1417 enum dsync_ibc_recv_ret ret; |
14584 | 1418 |
1419 p_clear(pool); | |
1420 box = p_new(pool, struct dsync_mailbox, 1); | |
1421 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1422 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAILBOX, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1423 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1424 return ret; |
1425 | |
1426 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
1427 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
|
1428 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
|
1429 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1430 } |
1431 | |
1432 if (dsync_deserializer_decode_try(decoder, "mailbox_lost", &value)) | |
1433 box->mailbox_lost = TRUE; | |
22494
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
1434 if (dsync_deserializer_decode_try(decoder, "mailbox_ignore", &value)) |
1f8b784712e1
dsync: Ignore missing remote mailbox when doing unidirectional sync
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22311
diff
changeset
|
1435 box->mailbox_ignore = TRUE; |
15750
5a1fc3723371
dsync: Automatically figure out which mailboxes can sync with message GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
15744
diff
changeset
|
1436 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
|
1437 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
|
1438 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
|
1439 (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
|
1440 box->have_save_guids = TRUE; |
16977
8a7ecddca4ad
dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
16940
diff
changeset
|
1441 if (dsync_deserializer_decode_try(decoder, "have_only_guid128", &value)) |
8a7ecddca4ad
dsync: Support syncing storages with 128bit GUIDs <-> string GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
16940
diff
changeset
|
1442 box->have_only_guid128 = TRUE; |
14584 | 1443 value = dsync_deserializer_decode_get(decoder, "uid_validity"); |
1444 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
|
1445 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
|
1446 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1447 } |
1448 value = dsync_deserializer_decode_get(decoder, "uid_next"); | |
1449 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
|
1450 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
|
1451 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1452 } |
1453 value = dsync_deserializer_decode_get(decoder, "messages_count"); | |
1454 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
|
1455 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
|
1456 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1457 } |
1458 value = dsync_deserializer_decode_get(decoder, "first_recent_uid"); | |
1459 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
|
1460 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
|
1461 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1462 } |
1463 value = dsync_deserializer_decode_get(decoder, "highest_modseq"); | |
1464 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
|
1465 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
|
1466 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1467 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1468 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
|
1469 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
|
1470 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
|
1471 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
|
1472 } |
14584 | 1473 |
1474 p_array_init(&box->cache_fields, pool, 32); | |
1475 if (dsync_deserializer_decode_try(decoder, "cache_fields", &value)) { | |
1476 const char *const *fields = t_strsplit(value, "\n"); | |
1477 for (; *fields != NULL; fields++) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1478 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
|
1479 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1480 } |
1481 } | |
1482 | |
1483 *dsync_box_r = box; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1484 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1485 } |
1486 | |
1487 static void | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1488 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
|
1489 const struct dsync_mailbox_attribute *attr) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1490 { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1491 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
|
1492 struct dsync_serializer_encoder *encoder; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1493 string_t *str = t_str_new(128); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1494 char type[2]; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1495 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1496 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
|
1497 return; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1498 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1499 str_append_c(str, items[ITEM_MAILBOX_ATTRIBUTE].chr); |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1500 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAILBOX_ATTRIBUTE); |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1501 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1502 type[0] = type[1] = '\0'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1503 switch (attr->type) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1504 case MAIL_ATTRIBUTE_TYPE_PRIVATE: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1505 type[0] = 'p'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1506 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1507 case MAIL_ATTRIBUTE_TYPE_SHARED: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1508 type[0] = 's'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1509 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1510 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1511 i_assert(type[0] != '\0'); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1512 dsync_serializer_encode_add(encoder, "type", type); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1513 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
|
1514 if (attr->value != NULL) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1515 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
|
1516 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
|
1517 dsync_serializer_encode_add(encoder, "stream", ""); |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1518 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1519 if (attr->deleted) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1520 dsync_serializer_encode_add(encoder, "deleted", ""); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1521 if (attr->last_change != 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1522 dsync_serializer_encode_add(encoder, "last_change", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1523 dec2str(attr->last_change)); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1524 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1525 if (attr->modseq != 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1526 dsync_serializer_encode_add(encoder, "modseq", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1527 dec2str(attr->modseq)); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1528 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1529 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1530 dsync_serializer_encode_finish(&encoder, str); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1531 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
|
1532 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1533 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
|
1534 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
|
1535 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
|
1536 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
|
1537 (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
|
1538 } |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1539 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1540 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1541 static enum dsync_ibc_recv_ret |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1542 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
|
1543 const struct dsync_mailbox_attribute **attr_r) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1544 { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1545 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
|
1546 pool_t pool = ibc->ret_pool; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1547 struct dsync_deserializer_decoder *decoder; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1548 struct dsync_mailbox_attribute *attr; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1549 const char *value; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1550 enum dsync_ibc_recv_ret ret; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1551 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1552 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
|
1553 return DSYNC_IBC_RECV_RET_FINISHED; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1554 |
16109
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1555 if (ibc->value_input != NULL) { |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1556 /* wait until the mail's stream has been read */ |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1557 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1558 } |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1559 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1560 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
|
1561 /* 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
|
1562 *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
|
1563 ibc->cur_attr = NULL; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1564 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
|
1565 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1566 |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1567 p_clear(pool); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1568 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
|
1569 |
16051
46b223892373
dsync: Fixed sending mailbox attributes with stream ibc.
Timo Sirainen <tss@iki.fi>
parents:
16025
diff
changeset
|
1570 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
|
1571 if (ret != DSYNC_IBC_RECV_RET_OK) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1572 return ret; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1573 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1574 value = dsync_deserializer_decode_get(decoder, "type"); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1575 switch (*value) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1576 case 'p': |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1577 attr->type = MAIL_ATTRIBUTE_TYPE_PRIVATE; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1578 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1579 case 's': |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1580 attr->type = MAIL_ATTRIBUTE_TYPE_SHARED; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1581 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1582 default: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1583 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
|
1584 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1585 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1586 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1587 value = dsync_deserializer_decode_get(decoder, "key"); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1588 attr->key = p_strdup(pool, value); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1589 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1590 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
|
1591 attr->deleted = TRUE; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1592 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
|
1593 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
|
1594 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
|
1595 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1596 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1597 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
|
1598 str_to_uint64(value, &attr->modseq) < 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1599 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
|
1600 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1601 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1602 |
21702
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1603 /* NOTE: stream reading must be the last here, because reading a large |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1604 stream will be finished later by return TRYAGAIN. We need to |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1605 deserialize all the other fields before that or they'll get lost. */ |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1606 if (dsync_deserializer_decode_try(decoder, "stream", &value)) { |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1607 attr->value_stream = dsync_ibc_stream_input_stream(ibc); |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1608 if (dsync_ibc_stream_read_mail_stream(ibc) <= 0) { |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1609 ibc->cur_attr = attr; |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1610 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1611 } |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1612 /* already finished reading the stream */ |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1613 i_assert(ibc->value_input == NULL); |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1614 } else if (dsync_deserializer_decode_try(decoder, "value", &value)) |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1615 attr->value = p_strdup(pool, value); |
23398ba09ac2
dsync: Fix syncing attributes with large values.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
1616 |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1617 *attr_r = attr; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1618 return DSYNC_IBC_RECV_RET_OK; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1619 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1620 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1621 static void |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1622 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
|
1623 const struct dsync_mail_change *change) |
14584 | 1624 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1625 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1626 struct dsync_serializer_encoder *encoder; |
1627 string_t *str = t_str_new(128); | |
1628 char type[2]; | |
1629 | |
1630 str_append_c(str, items[ITEM_MAIL_CHANGE].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1631 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAIL_CHANGE); |
14584 | 1632 |
1633 type[0] = type[1] = '\0'; | |
1634 switch (change->type) { | |
1635 case DSYNC_MAIL_CHANGE_TYPE_SAVE: | |
1636 type[0] = 's'; | |
1637 break; | |
1638 case DSYNC_MAIL_CHANGE_TYPE_EXPUNGE: | |
1639 type[0] = 'e'; | |
1640 break; | |
1641 case DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE: | |
1642 type[0] = 'f'; | |
1643 break; | |
1644 } | |
1645 i_assert(type[0] != '\0'); | |
1646 dsync_serializer_encode_add(encoder, "type", type); | |
1647 dsync_serializer_encode_add(encoder, "uid", dec2str(change->uid)); | |
1648 if (change->guid != NULL) | |
1649 dsync_serializer_encode_add(encoder, "guid", change->guid); | |
1650 if (change->hdr_hash != NULL) { | |
1651 dsync_serializer_encode_add(encoder, "hdr_hash", | |
1652 change->hdr_hash); | |
1653 } | |
1654 if (change->modseq != 0) { | |
1655 dsync_serializer_encode_add(encoder, "modseq", | |
1656 dec2str(change->modseq)); | |
1657 } | |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1658 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
|
1659 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
|
1660 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
|
1661 } |
14584 | 1662 if (change->add_flags != 0) { |
1663 dsync_serializer_encode_add(encoder, "add_flags", | |
1664 t_strdup_printf("%x", change->add_flags)); | |
1665 } | |
1666 if (change->remove_flags != 0) { | |
1667 dsync_serializer_encode_add(encoder, "remove_flags", | |
1668 t_strdup_printf("%x", change->remove_flags)); | |
1669 } | |
1670 if (change->final_flags != 0) { | |
1671 dsync_serializer_encode_add(encoder, "final_flags", | |
1672 t_strdup_printf("%x", change->final_flags)); | |
1673 } | |
1674 if (change->keywords_reset) | |
1675 dsync_serializer_encode_add(encoder, "keywords_reset", ""); | |
1676 | |
1677 if (array_is_created(&change->keyword_changes) && | |
1678 array_count(&change->keyword_changes) > 0) { | |
1679 string_t *kw_str = t_str_new(128); | |
1680 const char *const *changes; | |
1681 unsigned int i, count; | |
1682 | |
1683 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
|
1684 str_append_tabescaped(kw_str, changes[0]); |
14584 | 1685 for (i = 1; i < count; i++) { |
1686 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
|
1687 str_append_tabescaped(kw_str, changes[i]); |
14584 | 1688 } |
1689 dsync_serializer_encode_add(encoder, "keyword_changes", | |
1690 str_c(kw_str)); | |
1691 } | |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
1692 if (change->received_timestamp > 0) { |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
1693 dsync_serializer_encode_add(encoder, "received_timestamp", |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
1694 t_strdup_printf("%lx", (unsigned long)change->received_timestamp)); |
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
1695 } |
20633
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
1696 if (change->virtual_size > 0) { |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
1697 dsync_serializer_encode_add(encoder, "virtual_size", |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
1698 t_strdup_printf("%llx", (unsigned long long)change->virtual_size)); |
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
1699 } |
14584 | 1700 |
1701 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
|
1702 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1703 } |
1704 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1705 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1706 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
|
1707 const struct dsync_mail_change **change_r) |
14584 | 1708 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1709 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
|
1710 pool_t pool = ibc->ret_pool; |
14584 | 1711 struct dsync_deserializer_decoder *decoder; |
1712 struct dsync_mail_change *change; | |
1713 const char *value; | |
19038
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1714 unsigned int uintval; |
20642
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1715 unsigned long long ullongval; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1716 enum dsync_ibc_recv_ret ret; |
14584 | 1717 |
1718 p_clear(pool); | |
1719 change = p_new(pool, struct dsync_mail_change, 1); | |
1720 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1721 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
|
1722 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1723 return ret; |
1724 | |
1725 value = dsync_deserializer_decode_get(decoder, "type"); | |
1726 switch (*value) { | |
1727 case 's': | |
1728 change->type = DSYNC_MAIL_CHANGE_TYPE_SAVE; | |
1729 break; | |
1730 case 'e': | |
1731 change->type = DSYNC_MAIL_CHANGE_TYPE_EXPUNGE; | |
1732 break; | |
1733 case 'f': | |
1734 change->type = DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE; | |
1735 break; | |
1736 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1737 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
|
1738 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1739 } |
1740 | |
1741 value = dsync_deserializer_decode_get(decoder, "uid"); | |
1742 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
|
1743 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
|
1744 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1745 } |
1746 | |
1747 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1748 change->guid = p_strdup(pool, value); | |
1749 if (dsync_deserializer_decode_try(decoder, "hdr_hash", &value)) | |
1750 change->hdr_hash = p_strdup(pool, value); | |
1751 if (dsync_deserializer_decode_try(decoder, "modseq", &value) && | |
1752 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
|
1753 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
|
1754 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1755 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1756 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
|
1757 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
|
1758 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
|
1759 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
|
1760 } |
14584 | 1761 |
19038
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1762 if (dsync_deserializer_decode_try(decoder, "add_flags", &value)) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1763 if (str_to_uint_hex(value, &uintval) < 0 || |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1764 uintval > (uint8_t)-1) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1765 dsync_ibc_input_error(ibc, decoder, |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1766 "Invalid add_flags: %s", value); |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1767 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1768 } |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1769 change->add_flags = uintval; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1770 } |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1771 if (dsync_deserializer_decode_try(decoder, "remove_flags", &value)) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1772 if (str_to_uint_hex(value, &uintval) < 0 || |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1773 uintval > (uint8_t)-1) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1774 dsync_ibc_input_error(ibc, decoder, |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1775 "Invalid remove_flags: %s", value); |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1776 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1777 } |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1778 change->remove_flags = uintval; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1779 } |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1780 if (dsync_deserializer_decode_try(decoder, "final_flags", &value)) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1781 if (str_to_uint_hex(value, &uintval) < 0 || |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1782 uintval > (uint8_t)-1) { |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1783 dsync_ibc_input_error(ibc, decoder, |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1784 "Invalid final_flags: %s", value); |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1785 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1786 } |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1787 change->final_flags = uintval; |
f8ab4f979e92
Removed all invocations of strtoll() and friends.
Stephan Bosch <stephan@rename-it.nl>
parents:
19021
diff
changeset
|
1788 } |
14584 | 1789 if (dsync_deserializer_decode_try(decoder, "keywords_reset", &value)) |
1790 change->keywords_reset = TRUE; | |
1791 | |
1792 if (dsync_deserializer_decode_try(decoder, "keyword_changes", &value) && | |
1793 *value != '\0') { | |
22311
25af9d4dad59
global: Replaced t_strsplit_tab() calls with t_strsplit_tabescaped()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22264
diff
changeset
|
1794 const char *const *changes = t_strsplit_tabescaped(value); |
14584 | 1795 unsigned int i, count = str_array_length(changes); |
1796 | |
1797 p_array_init(&change->keyword_changes, pool, count); | |
1798 for (i = 0; i < count; i++) { | |
1799 value = p_strdup(pool, changes[i]); | |
1800 array_append(&change->keyword_changes, &value, 1); | |
1801 } | |
1802 } | |
20642
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1803 if (dsync_deserializer_decode_try(decoder, "received_timestamp", &value)) { |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1804 if (str_to_ullong_hex(value, &ullongval) < 0) { |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1805 dsync_ibc_input_error(ibc, decoder, "Invalid received_timestamp"); |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1806 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1807 } |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1808 change->received_timestamp = ullongval; |
18177
f393f63764e0
dsync: Added -t <timestamp> parameter to save only mails newer than <timestamp>
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
1809 } |
20642
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1810 if (dsync_deserializer_decode_try(decoder, "virtual_size", &value)) { |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1811 if (str_to_ullong_hex(value, &ullongval) < 0) { |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1812 dsync_ibc_input_error(ibc, decoder, "Invalid virtual_size"); |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1813 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1814 } |
ba69e914d71a
dsync: Further fixes to received_timestamp and virtual_size parsing (-t and -S parameters)
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20641
diff
changeset
|
1815 change->virtual_size = ullongval; |
20633
d54651ba988a
doveadm sync/backup: Added -S <max size> parameter to skip too large mails.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20595
diff
changeset
|
1816 } |
14584 | 1817 |
1818 *change_r = change; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1819 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1820 } |
1821 | |
1822 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1823 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
|
1824 const struct dsync_mail_request *request) |
14584 | 1825 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1826 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1827 struct dsync_serializer_encoder *encoder; |
1828 string_t *str = t_str_new(128); | |
1829 | |
1830 str_append_c(str, items[ITEM_MAIL_REQUEST].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1831 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAIL_REQUEST); |
14584 | 1832 if (request->guid != NULL) |
1833 dsync_serializer_encode_add(encoder, "guid", request->guid); | |
1834 if (request->uid != 0) { | |
1835 dsync_serializer_encode_add(encoder, "uid", | |
1836 dec2str(request->uid)); | |
1837 } | |
1838 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
|
1839 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1840 } |
1841 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1842 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1843 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
|
1844 const struct dsync_mail_request **request_r) |
14584 | 1845 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1846 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1847 struct dsync_deserializer_decoder *decoder; |
1848 struct dsync_mail_request *request; | |
1849 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1850 enum dsync_ibc_recv_ret ret; |
14584 | 1851 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1852 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1853 request = p_new(ibc->ret_pool, struct dsync_mail_request, 1); |
14584 | 1854 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1855 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
|
1856 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1857 return ret; |
1858 | |
1859 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
|
1860 request->guid = p_strdup(ibc->ret_pool, value); |
14584 | 1861 if (dsync_deserializer_decode_try(decoder, "uid", &value) && |
1862 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
|
1863 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
|
1864 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1865 } |
1866 | |
1867 *request_r = request; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1868 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1869 } |
1870 | |
1871 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1872 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
|
1873 const struct dsync_mail *mail) |
14584 | 1874 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1875 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1876 struct dsync_serializer_encoder *encoder; |
1877 string_t *str = t_str_new(128); | |
1878 | |
17845
d2e1b3f6d13b
dsync: Added DSYNC_BRAIN_FLAG_NO_MAIL_PREFETCH to avoid opening mails unnecessarily.
Timo Sirainen <tss@iki.fi>
parents:
17777
diff
changeset
|
1879 i_assert(!mail->minimal_fields); |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1880 i_assert(ibc->value_output == NULL); |
14584 | 1881 |
1882 str_append_c(str, items[ITEM_MAIL].chr); | |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1883 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_MAIL); |
14584 | 1884 if (mail->guid != NULL) |
1885 dsync_serializer_encode_add(encoder, "guid", mail->guid); | |
1886 if (mail->uid != 0) | |
1887 dsync_serializer_encode_add(encoder, "uid", dec2str(mail->uid)); | |
1888 if (mail->pop3_uidl != NULL) { | |
1889 dsync_serializer_encode_add(encoder, "pop3_uidl", | |
1890 mail->pop3_uidl); | |
1891 } | |
1892 if (mail->pop3_order > 0) { | |
1893 dsync_serializer_encode_add(encoder, "pop3_order", | |
1894 dec2str(mail->pop3_order)); | |
1895 } | |
1896 if (mail->received_date > 0) { | |
1897 dsync_serializer_encode_add(encoder, "received_date", | |
1898 dec2str(mail->received_date)); | |
1899 } | |
17296
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1900 if (mail->saved_date != 0) { |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1901 dsync_serializer_encode_add(encoder, "saved_date", |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1902 dec2str(mail->saved_date)); |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1903 } |
14584 | 1904 if (mail->input != NULL) |
1905 dsync_serializer_encode_add(encoder, "stream", ""); | |
1906 | |
1907 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
|
1908 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1909 |
1910 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
|
1911 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
|
1912 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
|
1913 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
|
1914 (void)dsync_ibc_stream_send_value_stream(ibc); |
14584 | 1915 } |
1916 } | |
1917 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1918 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1919 dsync_ibc_stream_recv_mail(struct dsync_ibc *_ibc, struct dsync_mail **mail_r) |
14584 | 1920 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1921 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
|
1922 pool_t pool = ibc->ret_pool; |
14584 | 1923 struct dsync_deserializer_decoder *decoder; |
1924 struct dsync_mail *mail; | |
1925 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1926 enum dsync_ibc_recv_ret ret; |
14584 | 1927 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1928 if (ibc->value_input != NULL) { |
14584 | 1929 /* 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
|
1930 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1931 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1932 if (ibc->cur_mail != NULL) { |
14584 | 1933 /* 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
|
1934 *mail_r = ibc->cur_mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1935 ibc->cur_mail = NULL; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1936 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1937 } |
1938 | |
1939 p_clear(pool); | |
1940 mail = p_new(pool, struct dsync_mail, 1); | |
1941 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1942 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
|
1943 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1944 return ret; |
1945 | |
1946 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1947 mail->guid = p_strdup(pool, value); | |
1948 if (dsync_deserializer_decode_try(decoder, "uid", &value) && | |
1949 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
|
1950 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
|
1951 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1952 } |
1953 if (dsync_deserializer_decode_try(decoder, "pop3_uidl", &value)) | |
1954 mail->pop3_uidl = p_strdup(pool, value); | |
1955 if (dsync_deserializer_decode_try(decoder, "pop3_order", &value) && | |
1956 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
|
1957 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
|
1958 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1959 } |
1960 if (dsync_deserializer_decode_try(decoder, "received_date", &value) && | |
1961 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
|
1962 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
|
1963 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1964 } |
17296
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1965 if (dsync_deserializer_decode_try(decoder, "saved_date", &value) && |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1966 str_to_time(value, &mail->saved_date) < 0) { |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1967 dsync_ibc_input_error(ibc, decoder, "Invalid saved_date"); |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1968 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
99a4788770cb
dsync: saved-date doesn't need to be looked up until mail body is being read.
Timo Sirainen <tss@iki.fi>
parents:
17286
diff
changeset
|
1969 } |
14584 | 1970 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
|
1971 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
|
1972 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
|
1973 ibc->cur_mail = mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1974 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1975 } |
1976 /* 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
|
1977 i_assert(ibc->value_input == NULL); |
14584 | 1978 } |
1979 | |
1980 *mail_r = mail; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1981 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1982 } |
1983 | |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1984 static void |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
1985 dsync_ibc_stream_send_finish(struct dsync_ibc *_ibc, const char *error, |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
1986 enum mail_error mail_error, |
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
1987 bool require_full_resync) |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1988 { |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1989 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1990 struct dsync_serializer_encoder *encoder; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1991 string_t *str = t_str_new(128); |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1992 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1993 str_append_c(str, items[ITEM_FINISH].chr); |
19089
3ab749f1ed71
dsync: If we disconnect with I/O timeout, log the last sent/recv state.
Timo Sirainen <tss@iki.fi>
parents:
19038
diff
changeset
|
1994 encoder = dsync_ibc_send_encode_begin(ibc, ITEM_FINISH); |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1995 if (error != NULL) |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
1996 dsync_serializer_encode_add(encoder, "error", error); |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
1997 if (mail_error != 0) { |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
1998 dsync_serializer_encode_add(encoder, "mail_error", |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
1999 dec2str(mail_error)); |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2000 } |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2001 if (require_full_resync) |
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2002 dsync_serializer_encode_add(encoder, "require_full_resync", ""); |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2003 dsync_serializer_encode_finish(&encoder, str); |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2004 dsync_ibc_stream_send_string(ibc, str); |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2005 } |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2006 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2007 static enum dsync_ibc_recv_ret |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2008 dsync_ibc_stream_recv_finish(struct dsync_ibc *_ibc, const char **error_r, |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2009 enum mail_error *mail_error_r, |
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2010 bool *require_full_resync_r) |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2011 { |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2012 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2013 struct dsync_deserializer_decoder *decoder; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2014 const char *value; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2015 enum dsync_ibc_recv_ret ret; |
18375
cf74e2179dce
dsync: Fixed returning wrong mail_error in some remote dsync.
Timo Sirainen <tss@iki.fi>
parents:
18371
diff
changeset
|
2016 int i = 0; |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2017 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2018 *error_r = NULL; |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2019 *mail_error_r = 0; |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2020 *require_full_resync_r = FALSE; |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2021 |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2022 p_clear(ibc->ret_pool); |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2023 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2024 if (ibc->minor_version < DSYNC_PROTOCOL_MINOR_HAVE_FINISH) |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2025 return DSYNC_IBC_RECV_RET_OK; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2026 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2027 ret = dsync_ibc_stream_input_next(ibc, ITEM_FINISH, &decoder); |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2028 if (ret != DSYNC_IBC_RECV_RET_OK) |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2029 return ret; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2030 |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2031 if (dsync_deserializer_decode_try(decoder, "error", &value)) |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2032 *error_r = p_strdup(ibc->ret_pool, value); |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2033 if (dsync_deserializer_decode_try(decoder, "mail_error", &value) && |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2034 str_to_int(value, &i) < 0) { |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2035 dsync_ibc_input_error(ibc, decoder, "Invalid mail_error"); |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2036 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2037 } |
20458
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2038 if (dsync_deserializer_decode_try(decoder, "require_full_resync", &value)) |
16f9c0a46cbb
dsync: When full resync is wanted in a stateful sync, output empty state.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
20197
diff
changeset
|
2039 *require_full_resync_r = TRUE; |
18371
b900b50085fc
dsync: Use storage's mail_error to choose the doveadm exit code.
Timo Sirainen <tss@iki.fi>
parents:
18351
diff
changeset
|
2040 *mail_error_r = i; |
20197
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
2041 |
dbe3a138adb1
dsync: race condition where done/finish is received after one side has closed
J. Nick Koston <nick@cpanel.net>
parents:
19646
diff
changeset
|
2042 ibc->finish_received = TRUE; |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2043 return DSYNC_IBC_RECV_RET_OK; |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2044 } |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2045 |
15632
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
2046 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
|
2047 { |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
2048 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
|
2049 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
2050 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
|
2051 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
|
2052 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
|
2053 } |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
2054 } |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
2055 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2056 static bool dsync_ibc_stream_is_send_queue_full(struct dsync_ibc *_ibc) |
14584 | 2057 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2058 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 2059 size_t bytes; |
2060 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
2061 if (ibc->value_output != NULL) |
14584 | 2062 return TRUE; |
2063 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2064 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
|
2065 if (bytes < DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE) |
14584 | 2066 return FALSE; |
2067 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2068 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 2069 return TRUE; |
2070 } | |
2071 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2072 static bool dsync_ibc_stream_has_pending_data(struct dsync_ibc *_ibc) |
14584 | 2073 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2074 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 2075 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2076 return ibc->has_pending_data; |
14584 | 2077 } |
2078 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2079 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
|
2080 dsync_ibc_stream_deinit, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2081 dsync_ibc_stream_send_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2082 dsync_ibc_stream_recv_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2083 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
|
2084 dsync_ibc_stream_send_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2085 dsync_ibc_stream_recv_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2086 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
|
2087 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
|
2088 dsync_ibc_stream_send_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2089 dsync_ibc_stream_recv_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2090 dsync_ibc_stream_send_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2091 dsync_ibc_stream_recv_mailbox, |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
2092 dsync_ibc_stream_send_mailbox_attribute, |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
2093 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
|
2094 dsync_ibc_stream_send_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2095 dsync_ibc_stream_recv_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2096 dsync_ibc_stream_send_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2097 dsync_ibc_stream_recv_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2098 dsync_ibc_stream_send_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2099 dsync_ibc_stream_recv_mail, |
18351
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2100 dsync_ibc_stream_send_finish, |
b4dbe64c0032
dsync: Added an extra "finish" state to allow slave-dsync to report error to master-dsync.
Timo Sirainen <tss@iki.fi>
parents:
18181
diff
changeset
|
2101 dsync_ibc_stream_recv_finish, |
15632
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
2102 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
|
2103 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
|
2104 dsync_ibc_stream_has_pending_data |
14584 | 2105 }; |
2106 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2107 struct dsync_ibc * |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
2108 dsync_ibc_init_stream(struct istream *input, struct ostream *output, |
19014
11b107c8dc05
dsync: Added -T parameter to specify the I/O stall timeout.
Timo Sirainen <tss@iki.fi>
parents:
18394
diff
changeset
|
2109 const char *name, const char *temp_path_prefix, |
11b107c8dc05
dsync: Added -T parameter to specify the I/O stall timeout.
Timo Sirainen <tss@iki.fi>
parents:
18394
diff
changeset
|
2110 unsigned int timeout_secs) |
14584 | 2111 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2112 struct dsync_ibc_stream *ibc; |
14584 | 2113 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2114 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
|
2115 ibc->ibc.v = dsync_ibc_stream_vfuncs; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
2116 ibc->input = input; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
2117 ibc->output = output; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2118 ibc->name = i_strdup(name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2119 ibc->temp_path_prefix = i_strdup(temp_path_prefix); |
19014
11b107c8dc05
dsync: Added -T parameter to specify the I/O stall timeout.
Timo Sirainen <tss@iki.fi>
parents:
18394
diff
changeset
|
2120 ibc->timeout_secs = timeout_secs; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2121 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
|
2122 dsync_ibc_stream_init(ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
2123 return &ibc->ibc; |
14584 | 2124 } |