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