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