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