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