Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-ibc-stream.c @ 17192:a1c153c70bb9
Use io_add_istream() wherever possible.
This shouldn't fix anything, but might make some functionality easier to
implement in future.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 03 Apr 2014 19:59:30 +0300 |
parents | 08f1c7af0ac0 |
children | e20a6192ddcf |
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 " | |
15783
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
83 "last_common_modseq last_common_pvt_modseq", |
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
84 .optional_keys = "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; |
362 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
363 line = i_stream_next_line(ibc->input); |
14584 | 364 if (line != NULL) { |
365 *line_r = line; | |
366 return 1; | |
367 } | |
368 /* try reading some */ | |
15592
0949ddc3a892
dsync: Minor fix for talking with remote dsync.
Timo Sirainen <tss@iki.fi>
parents:
15496
diff
changeset
|
369 if (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
|
370 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
|
371 return -1; |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
372 error = t_str_new(128); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
373 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
|
374 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
|
375 i_stream_get_error(ibc->input)); |
14584 | 376 } else { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
377 i_assert(ibc->input->eof); |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
378 str_printfa(error, "read(%s) failed: EOF", ibc->name); |
14584 | 379 } |
16673
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
380 if (!ibc->version_received) |
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
381 str_append(error, " (version not received)"); |
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
382 else if (!ibc->handshake_received) |
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
383 str_append(error, " (handshake not received)"); |
64464646c020
dsync: Stream disconnection error message improvement
Timo Sirainen <tss@iki.fi>
parents:
16669
diff
changeset
|
384 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
|
385 dsync_ibc_stream_stop(ibc); |
14584 | 386 return -1; |
387 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
388 *line_r = i_stream_next_line(ibc->input); |
14584 | 389 if (*line_r == NULL) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
390 ibc->has_pending_data = FALSE; |
14584 | 391 return 0; |
392 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
393 ibc->has_pending_data = TRUE; |
14584 | 394 return 1; |
395 } | |
396 | |
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
|
397 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
|
398 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
|
399 struct dsync_deserializer_decoder *decoder, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
400 const char *fmt, ...) |
14584 | 401 { |
402 va_list args; | |
403 const char *error; | |
404 | |
405 va_start(args, fmt); | |
406 error = t_strdup_vprintf(fmt, args); | |
407 if (decoder == NULL) | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
408 i_error("dsync(%s): %s", ibc->name, error); |
14584 | 409 else { |
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: %s", ibc->name, |
14584 | 411 dsync_deserializer_decoder_get_name(decoder), error); |
412 } | |
413 va_end(args); | |
414 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
415 dsync_ibc_stream_stop(ibc); |
14584 | 416 } |
417 | |
418 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
419 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
|
420 const string_t *str) |
14584 | 421 { |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
422 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
|
423 o_stream_nsend(ibc->output, str_data(str), str_len(str)); |
14584 | 424 } |
425 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
426 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
|
427 { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
428 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
|
429 string_t *path; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
430 int fd; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
431 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
432 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
|
433 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
|
434 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
|
435 if (fd == -1) { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
436 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
|
437 return -1; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
438 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
439 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
440 /* 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
|
441 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
|
442 /* shouldn't happen.. */ |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
443 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
|
444 i_close_fd(&fd); |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
445 return -1; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
446 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
447 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
448 *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
|
449 return fd; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
450 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
451 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
452 static struct istream * |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
453 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
|
454 { |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
455 struct istream *inputs[2]; |
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 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
|
458 inputs[1] = NULL; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
459 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
|
460 seekable_fd_callback, ibc); |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
461 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
|
462 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
463 return ibc->value_input; |
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 |
15036
5943cace4e05
dsync: Renamed "io" slave to "stream".
Timo Sirainen <tss@iki.fi>
parents:
15035
diff
changeset
|
466 static int |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
467 dsync_ibc_check_missing_deserializers(struct dsync_ibc_stream *ibc) |
14584 | 468 { |
469 unsigned int i; | |
470 int ret = 0; | |
471 | |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
472 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
|
473 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
|
474 ibc->minor_version >= items[i].min_minor_version && |
14584 | 475 (items[i].required_keys != NULL || |
476 items[i].optional_keys != NULL)) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
477 dsync_ibc_input_error(ibc, NULL, |
14584 | 478 "Remote didn't handshake deserializer for %s", |
479 items[i].name); | |
480 ret = -1; | |
481 } | |
482 } | |
483 return ret; | |
484 } | |
485 | |
486 static bool | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
487 dsync_ibc_stream_handshake(struct dsync_ibc_stream *ibc, const char *line) |
14584 | 488 { |
489 enum item_type item = ITEM_NONE; | |
490 const char *const *required_keys, *error; | |
491 unsigned int i; | |
492 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
493 if (ibc->handshake_received) |
14584 | 494 return TRUE; |
495 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
496 if (!ibc->version_received) { |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
497 if (!version_string_verify_full(line, "dsync", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
498 DSYNC_PROTOCOL_VERSION_MAJOR, |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
499 &ibc->minor_version)) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
500 dsync_ibc_input_error(ibc, NULL, |
14584 | 501 "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
|
502 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 503 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
504 ibc->version_received = TRUE; |
14584 | 505 return FALSE; |
506 } | |
507 | |
508 if (strcmp(line, END_OF_LIST_LINE) == 0) { | |
509 /* finished handshaking */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
510 if (dsync_ibc_check_missing_deserializers(ibc) < 0) |
14584 | 511 return FALSE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
512 ibc->handshake_received = TRUE; |
14584 | 513 return FALSE; |
514 } | |
515 | |
516 for (i = 1; i < ITEM_END_OF_LIST; i++) { | |
517 if (items[i].chr == line[0]) { | |
518 item = i; | |
519 break; | |
520 } | |
521 } | |
522 if (item == ITEM_NONE) { | |
523 /* unknown deserializer, ignore */ | |
524 return FALSE; | |
525 } | |
526 | |
527 required_keys = items[item].required_keys == NULL ? NULL : | |
528 t_strsplit(items[item].required_keys, " "); | |
529 if (dsync_deserializer_init(items[item].name, | |
530 required_keys, line + 1, | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
531 &ibc->deserializers[item], &error) < 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
532 dsync_ibc_input_error(ibc, NULL, |
14584 | 533 "Remote sent invalid handshake for %s: %s", |
534 items[item].name, error); | |
535 } | |
536 return FALSE; | |
537 } | |
538 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
539 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
540 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
|
541 struct dsync_deserializer_decoder **decoder_r) |
14584 | 542 { |
543 enum item_type line_item = ITEM_NONE; | |
544 const char *line, *error; | |
545 unsigned int i; | |
546 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
547 i_assert(ibc->value_input == NULL); |
14584 | 548 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
549 timeout_reset(ibc->to); |
14584 | 550 |
551 do { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
552 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
|
553 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
554 } while (!dsync_ibc_stream_handshake(ibc, line)); |
14584 | 555 |
556 if (strcmp(line, END_OF_LIST_LINE) == 0) { | |
557 /* end of this list */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
558 return DSYNC_IBC_RECV_RET_FINISHED; |
14584 | 559 } |
15767
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
560 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
|
561 /* 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
|
562 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
|
563 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
|
564 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
|
565 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
|
566 |
93a8a32adfd8
dsync: Don't log read() failed: EOF when remote intentionally fails early.
Timo Sirainen <tss@iki.fi>
parents:
15750
diff
changeset
|
567 } |
14584 | 568 for (i = 1; i < ITEM_END_OF_LIST; i++) { |
569 if (*line == items[i].chr) { | |
570 line_item = i; | |
571 break; | |
572 } | |
573 } | |
574 if (line_item != item) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
575 dsync_ibc_input_error(ibc, NULL, |
14584 | 576 "Received unexpected input %c != %c", |
577 *line, items[item].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
578 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 579 } |
580 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
581 if (ibc->cur_decoder != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
582 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
|
583 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
|
584 line+1, &ibc->cur_decoder, |
14584 | 585 &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
586 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
|
587 items[item].name, error); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
588 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 589 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
590 *decoder_r = ibc->cur_decoder; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
591 return DSYNC_IBC_RECV_RET_OK; |
14584 | 592 } |
593 | |
594 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
595 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
|
596 const struct dsync_ibc_settings *set) |
14584 | 597 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
598 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 599 struct dsync_serializer_encoder *encoder; |
600 string_t *str = t_str_new(128); | |
601 char sync_type[2]; | |
602 | |
603 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
|
604 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
|
605 dsync_serializer_encode_add(encoder, "hostname", set->hostname); |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
606 if (set->sync_ns_prefixes != NULL) { |
14584 | 607 dsync_serializer_encode_add(encoder, "sync_ns_prefix", |
17170
08f1c7af0ac0
dsync: Support multiple -n parameters.
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
608 set->sync_ns_prefixes); |
14584 | 609 } |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
610 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
|
611 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
|
612 if (set->exclude_mailboxes != NULL) { |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
613 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
|
614 unsigned int i; |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
615 |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
616 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
|
617 if (i != 0) |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
618 str_append_c(substr, '\t'); |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
619 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
|
620 } |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
621 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
|
622 str_c(substr)); |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
623 } |
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
|
624 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
|
625 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
|
626 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
|
627 } |
14584 | 628 |
629 sync_type[0] = sync_type[1] = '\0'; | |
630 switch (set->sync_type) { | |
631 case DSYNC_BRAIN_SYNC_TYPE_UNKNOWN: | |
632 break; | |
633 case DSYNC_BRAIN_SYNC_TYPE_FULL: | |
634 sync_type[0] = 'f'; | |
635 break; | |
636 case DSYNC_BRAIN_SYNC_TYPE_CHANGED: | |
637 sync_type[0] = 'c'; | |
638 break; | |
639 case DSYNC_BRAIN_SYNC_TYPE_STATE: | |
640 sync_type[0] = 's'; | |
641 break; | |
642 } | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
643 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
|
644 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
|
645 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
|
646 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
|
647 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
|
648 } |
15744
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 dsync_serializer_encode_add(encoder, "backup_send", ""); |
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_RECV) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
654 dsync_serializer_encode_add(encoder, "backup_recv", ""); |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
655 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
|
656 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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 dsync_serializer_encode_add(encoder, "purge_remote", ""); |
14584 | 665 |
666 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
|
667 dsync_ibc_stream_send_string(ibc, str); |
14584 | 668 } |
669 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
670 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
671 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
|
672 const struct dsync_ibc_settings **set_r) |
14584 | 673 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
674 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 675 struct dsync_deserializer_decoder *decoder; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
676 struct dsync_ibc_settings *set; |
14584 | 677 const char *value; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
678 pool_t pool = ibc->ret_pool; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
679 enum dsync_ibc_recv_ret ret; |
14584 | 680 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
681 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
|
682 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
|
683 if (ret != DSYNC_IBC_RECV_RET_TRYAGAIN) { |
14584 | 684 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
|
685 ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
686 dsync_ibc_stream_stop(ibc); |
14584 | 687 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
688 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 689 } |
690 | |
691 p_clear(pool); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
692 set = p_new(pool, struct dsync_ibc_settings, 1); |
14584 | 693 |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
694 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
|
695 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
|
696 /* 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
|
697 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
|
698 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
|
699 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
|
700 |
14584 | 701 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
|
702 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
|
703 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
|
704 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
|
705 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
|
706 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
|
707 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
|
708 "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
|
709 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
|
710 } |
16398
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
711 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
|
712 *value != '\0') { |
4883a8e1db13
dsync: Added -x parameter to exclude mailboxes from sync.
Timo Sirainen <tss@iki.fi>
parents:
16381
diff
changeset
|
713 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
|
714 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
|
715 } |
14584 | 716 if (dsync_deserializer_decode_try(decoder, "sync_type", &value)) { |
717 switch (value[0]) { | |
718 case 'f': | |
719 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL; | |
720 break; | |
721 case 'c': | |
722 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_CHANGED; | |
723 break; | |
724 case 's': | |
725 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_STATE; | |
726 break; | |
727 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
728 dsync_ibc_input_error(ibc, decoder, |
14584 | 729 "Unknown sync_type: %s", value); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
730 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 731 } |
732 } | |
15782
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
733 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
|
734 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
|
735 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
|
736 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
|
737 "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
|
738 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
|
739 } |
6f024e0289da
dsync: -l parameter locking is now done on the server with "lower" hostname.
Timo Sirainen <tss@iki.fi>
parents:
15767
diff
changeset
|
740 } |
15744
b4e2b3b54f0a
dsync: Renamed "guid_requests" to "mail_requests"
Timo Sirainen <tss@iki.fi>
parents:
15715
diff
changeset
|
741 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
|
742 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
|
743 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
|
744 set->brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_SEND; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
745 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
|
746 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
|
747 if (dsync_deserializer_decode_try(decoder, "debug", &value)) |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
748 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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 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
|
754 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
|
755 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
|
756 set->brain_flags |= DSYNC_BRAIN_FLAG_PURGE_REMOTE; |
14584 | 757 |
758 *set_r = set; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
759 return DSYNC_IBC_RECV_RET_OK; |
14584 | 760 } |
761 | |
762 static void | |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
763 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
|
764 enum dsync_ibc_eol_type type) |
14584 | 765 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
766 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 767 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
768 i_assert(ibc->value_output == NULL); |
14584 | 769 |
16222
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
770 switch (type) { |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
771 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
|
772 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
|
773 return; |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
774 break; |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
775 default: |
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 } |
d79cf48f1072
dsync: Fixed talking to earlier dsync without mailbox attribute support.
Timo Sirainen <tss@iki.fi>
parents:
16110
diff
changeset
|
778 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
779 o_stream_nsend_str(ibc->output, END_OF_LIST_LINE"\n"); |
14584 | 780 } |
781 | |
782 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
783 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
|
784 const struct dsync_mailbox_state *state) |
14584 | 785 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
786 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 787 struct dsync_serializer_encoder *encoder; |
788 string_t *str = t_str_new(128); | |
789 | |
790 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
|
791 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_STATE]); |
14584 | 792 dsync_serializer_encode_add(encoder, "mailbox_guid", |
793 guid_128_to_string(state->mailbox_guid)); | |
794 dsync_serializer_encode_add(encoder, "last_uidvalidity", | |
795 dec2str(state->last_uidvalidity)); | |
796 dsync_serializer_encode_add(encoder, "last_common_uid", | |
797 dec2str(state->last_common_uid)); | |
798 dsync_serializer_encode_add(encoder, "last_common_modseq", | |
799 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
|
800 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
|
801 dec2str(state->last_common_pvt_modseq)); |
15783
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
802 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
|
803 dsync_serializer_encode_add(encoder, "changes_during_sync", ""); |
14584 | 804 |
805 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
|
806 dsync_ibc_stream_send_string(ibc, str); |
14584 | 807 } |
808 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
809 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
810 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
|
811 struct dsync_mailbox_state *state_r) |
14584 | 812 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
813 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 814 struct dsync_deserializer_decoder *decoder; |
815 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
816 enum dsync_ibc_recv_ret ret; |
14584 | 817 |
818 memset(state_r, 0, sizeof(*state_r)); | |
819 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
820 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
|
821 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 822 return ret; |
823 | |
824 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
825 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
|
826 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
|
827 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 828 } |
829 value = dsync_deserializer_decode_get(decoder, "last_uidvalidity"); | |
830 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
|
831 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
|
832 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 833 } |
834 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
|
835 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
|
836 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
|
837 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 838 } |
839 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
|
840 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
|
841 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
|
842 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 843 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
844 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
|
845 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
|
846 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
|
847 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
|
848 } |
15783
502a50925641
dsync: Merge last-common-* values from both local and remote when they differ.
Timo Sirainen <tss@iki.fi>
parents:
15782
diff
changeset
|
849 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
|
850 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
|
851 return DSYNC_IBC_RECV_RET_OK; |
14584 | 852 } |
853 | |
854 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
855 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
|
856 const char *const *name, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
857 const struct dsync_mailbox_node *node) |
14584 | 858 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
859 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 860 struct dsync_serializer_encoder *encoder; |
861 string_t *str, *namestr; | |
862 | |
863 i_assert(*name != NULL); | |
864 | |
865 str = t_str_new(128); | |
866 str_append_c(str, items[ITEM_MAILBOX_TREE_NODE].chr); | |
867 | |
868 /* convert all hierarchy separators to tabs. mailbox names really | |
869 aren't supposed to have any tabs, but escape them anyway if there | |
870 are. */ | |
871 namestr = t_str_new(128); | |
872 for (; *name != NULL; name++) { | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
873 str_append_tabescaped(namestr, *name); |
14584 | 874 str_append_c(namestr, '\t'); |
875 } | |
876 str_truncate(namestr, str_len(namestr)-1); | |
877 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
878 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_TREE_NODE]); |
14584 | 879 dsync_serializer_encode_add(encoder, "name", str_c(namestr)); |
880 switch (node->existence) { | |
881 case DSYNC_MAILBOX_NODE_NONEXISTENT: | |
882 dsync_serializer_encode_add(encoder, "existence", "n"); | |
883 break; | |
884 case DSYNC_MAILBOX_NODE_EXISTS: | |
885 dsync_serializer_encode_add(encoder, "existence", "y"); | |
886 break; | |
887 case DSYNC_MAILBOX_NODE_DELETED: | |
888 dsync_serializer_encode_add(encoder, "existence", "d"); | |
889 break; | |
890 } | |
891 | |
892 if (!guid_128_is_empty(node->mailbox_guid)) { | |
893 dsync_serializer_encode_add(encoder, "mailbox_guid", | |
894 guid_128_to_string(node->mailbox_guid)); | |
895 } | |
896 if (node->uid_validity != 0) { | |
897 dsync_serializer_encode_add(encoder, "uid_validity", | |
898 dec2str(node->uid_validity)); | |
899 } | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
900 if (node->uid_next != 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
901 dsync_serializer_encode_add(encoder, "uid_next", |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
902 dec2str(node->uid_next)); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
903 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
904 if (node->last_renamed_or_created != 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
905 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
|
906 dec2str(node->last_renamed_or_created)); |
14584 | 907 } |
908 if (node->last_subscription_change != 0) { | |
909 dsync_serializer_encode_add(encoder, "last_subscription_change", | |
910 dec2str(node->last_subscription_change)); | |
911 } | |
912 if (node->subscribed) | |
913 dsync_serializer_encode_add(encoder, "subscribed", ""); | |
914 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
|
915 dsync_ibc_stream_send_string(ibc, str); |
14584 | 916 } |
917 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
918 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
919 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
|
920 const char *const **name_r, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
921 const struct dsync_mailbox_node **node_r) |
14584 | 922 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
923 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 924 struct dsync_deserializer_decoder *decoder; |
925 struct dsync_mailbox_node *node; | |
926 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
927 enum dsync_ibc_recv_ret ret; |
14584 | 928 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
929 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
|
930 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 931 return ret; |
932 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
933 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
934 node = p_new(ibc->ret_pool, struct dsync_mailbox_node, 1); |
14584 | 935 |
936 value = dsync_deserializer_decode_get(decoder, "name"); | |
937 if (*value == '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
938 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
|
939 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 940 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
941 *name_r = (void *)p_strsplit_tabescaped(ibc->ret_pool, value); |
14584 | 942 |
943 value = dsync_deserializer_decode_get(decoder, "existence"); | |
944 switch (*value) { | |
945 case 'n': | |
946 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT; | |
947 break; | |
948 case 'y': | |
949 node->existence = DSYNC_MAILBOX_NODE_EXISTS; | |
950 break; | |
951 case 'd': | |
952 node->existence = DSYNC_MAILBOX_NODE_DELETED; | |
953 break; | |
954 } | |
955 | |
956 if (dsync_deserializer_decode_try(decoder, "mailbox_guid", &value) && | |
957 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
|
958 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
|
959 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 960 } |
961 if (dsync_deserializer_decode_try(decoder, "uid_validity", &value) && | |
962 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
|
963 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
|
964 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 965 } |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
966 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
|
967 str_to_uint32(value, &node->uid_next) < 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
968 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
|
969 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
970 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
971 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
|
972 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
|
973 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
|
974 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 975 } |
976 if (dsync_deserializer_decode_try(decoder, "last_subscription_change", &value) && | |
977 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
|
978 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
|
979 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 980 } |
981 if (dsync_deserializer_decode_try(decoder, "subscribed", &value)) | |
982 node->subscribed = TRUE; | |
983 | |
984 *node_r = node; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
985 return DSYNC_IBC_RECV_RET_OK; |
14584 | 986 } |
987 | |
988 static void | |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
989 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
|
990 struct dsync_serializer_encoder *encoder, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
991 const struct dsync_mailbox_delete *deletes, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
992 unsigned int count, const char *key, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
993 enum dsync_mailbox_delete_type type) |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
994 { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
995 unsigned int i; |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
996 |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
997 str_truncate(str, 0); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
998 for (i = 0; i < count; i++) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
999 if (deletes[i].type == type) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1000 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
|
1001 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
|
1002 } |
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 if (str_len(str) > 0) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1005 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
|
1006 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
|
1007 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1008 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1009 |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1010 static void |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1011 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
|
1012 const struct dsync_mailbox_delete *deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1013 unsigned int count, char hierarchy_sep) |
14584 | 1014 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1015 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1016 struct dsync_serializer_encoder *encoder; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1017 string_t *str, *substr; |
14584 | 1018 char sep[2]; |
1019 | |
1020 str = t_str_new(128); | |
1021 str_append_c(str, items[ITEM_MAILBOX_DELETE].chr); | |
1022 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1023 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_DELETE]); |
14584 | 1024 sep[0] = hierarchy_sep; sep[1] = '\0'; |
1025 dsync_serializer_encode_add(encoder, "hierarchy_sep", sep); | |
1026 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1027 substr = t_str_new(128); |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1028 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
|
1029 "mailboxes", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1030 DSYNC_MAILBOX_DELETE_TYPE_MAILBOX); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1031 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
|
1032 "dirs", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1033 DSYNC_MAILBOX_DELETE_TYPE_DIR); |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1034 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
|
1035 "unsubscribes", |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1036 DSYNC_MAILBOX_DELETE_TYPE_UNSUBSCRIBE); |
14584 | 1037 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
|
1038 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1039 } |
1040 | |
1041 ARRAY_DEFINE_TYPE(dsync_mailbox_delete, struct dsync_mailbox_delete); | |
1042 static int | |
1043 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
|
1044 const char *value, enum dsync_mailbox_delete_type type) |
14584 | 1045 { |
1046 struct dsync_mailbox_delete *del; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1047 const char *const *tmp; |
14584 | 1048 unsigned int i; |
1049 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1050 tmp = t_strsplit(value, " "); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1051 for (i = 0; tmp[i] != NULL; i += 2) { |
14584 | 1052 del = array_append_space(deletes); |
16380
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1053 del->type = type; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1054 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
|
1055 return -1; |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1056 if (tmp[i+1] == NULL || |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
1057 str_to_time(tmp[i+1], &del->timestamp) < 0) |
14584 | 1058 return -1; |
1059 } | |
1060 return 0; | |
1061 } | |
1062 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1063 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1064 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
|
1065 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
|
1066 unsigned int *count_r, char *hierarchy_sep_r) |
14584 | 1067 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1068 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1069 struct dsync_deserializer_decoder *decoder; |
1070 ARRAY_TYPE(dsync_mailbox_delete) deletes; | |
1071 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1072 enum dsync_ibc_recv_ret ret; |
14584 | 1073 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1074 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
|
1075 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1076 return ret; |
1077 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1078 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1079 p_array_init(&deletes, ibc->ret_pool, 16); |
14584 | 1080 |
1081 value = dsync_deserializer_decode_get(decoder, "hierarchy_sep"); | |
1082 if (strlen(value) != 1) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1083 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
|
1084 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1085 } |
1086 *hierarchy_sep_r = value[0]; | |
1087 | |
1088 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
|
1089 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1090 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
|
1091 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
|
1092 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1093 } |
1094 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
|
1095 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1096 DSYNC_MAILBOX_DELETE_TYPE_DIR) < 0) { |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1097 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
|
1098 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1099 } |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1100 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
|
1101 decode_mailbox_deletes(&deletes, value, |
9878986a028d
dsync: Fixed unsubscribing from an already deleted mailbox.
Timo Sirainen <tss@iki.fi>
parents:
16376
diff
changeset
|
1102 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
|
1103 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
|
1104 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1105 } |
1106 *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
|
1107 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1108 } |
1109 | |
1110 static const char * | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1111 get_cache_fields(struct dsync_ibc_stream *ibc, |
14584 | 1112 const struct dsync_mailbox *dsync_box) |
1113 { | |
1114 struct dsync_serializer_encoder *encoder; | |
1115 string_t *str; | |
1116 const struct mailbox_cache_field *cache_fields; | |
1117 unsigned int i, count; | |
1118 char decision[3]; | |
1119 | |
1120 cache_fields = array_get(&dsync_box->cache_fields, &count); | |
1121 if (count == 0) | |
1122 return ""; | |
1123 | |
1124 str = t_str_new(128); | |
1125 for (i = 0; i < count; i++) { | |
1126 const struct mailbox_cache_field *field = &cache_fields[i]; | |
1127 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1128 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_CACHE_FIELD]); |
14584 | 1129 dsync_serializer_encode_add(encoder, "name", field->name); |
1130 | |
1131 memset(decision, 0, sizeof(decision)); | |
1132 switch (field->decision & ~MAIL_CACHE_DECISION_FORCED) { | |
1133 case MAIL_CACHE_DECISION_NO: | |
1134 decision[0] = 'n'; | |
1135 break; | |
1136 case MAIL_CACHE_DECISION_TEMP: | |
1137 decision[0] = 't'; | |
1138 break; | |
1139 case MAIL_CACHE_DECISION_YES: | |
1140 decision[0] = 'y'; | |
1141 break; | |
1142 } | |
1143 i_assert(decision[0] != '\0'); | |
1144 if ((field->decision & MAIL_CACHE_DECISION_FORCED) != 0) | |
1145 decision[1] = 'F'; | |
1146 dsync_serializer_encode_add(encoder, "decision", decision); | |
1147 if (field->last_used != 0) { | |
1148 dsync_serializer_encode_add(encoder, "last_used", | |
1149 dec2str(field->last_used)); | |
1150 } | |
1151 dsync_serializer_encode_finish(&encoder, str); | |
1152 } | |
1153 if (i > 0) { | |
1154 /* remove the trailing LF */ | |
1155 str_truncate(str, str_len(str)-1); | |
1156 } | |
1157 return str_c(str); | |
1158 } | |
1159 | |
1160 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1161 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
|
1162 const struct dsync_mailbox *dsync_box) |
14584 | 1163 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1164 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1165 struct dsync_serializer_encoder *encoder; |
1166 string_t *str = t_str_new(128); | |
1167 const char *value; | |
1168 | |
1169 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
|
1170 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX]); |
14584 | 1171 dsync_serializer_encode_add(encoder, "mailbox_guid", |
1172 guid_128_to_string(dsync_box->mailbox_guid)); | |
1173 | |
1174 if (dsync_box->mailbox_lost) | |
1175 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
|
1176 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
|
1177 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
|
1178 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
|
1179 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
|
1180 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
|
1181 dsync_serializer_encode_add(encoder, "have_only_guid128", ""); |
14584 | 1182 dsync_serializer_encode_add(encoder, "uid_validity", |
1183 dec2str(dsync_box->uid_validity)); | |
1184 dsync_serializer_encode_add(encoder, "uid_next", | |
1185 dec2str(dsync_box->uid_next)); | |
1186 dsync_serializer_encode_add(encoder, "messages_count", | |
1187 dec2str(dsync_box->messages_count)); | |
1188 dsync_serializer_encode_add(encoder, "first_recent_uid", | |
1189 dec2str(dsync_box->first_recent_uid)); | |
1190 dsync_serializer_encode_add(encoder, "highest_modseq", | |
1191 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
|
1192 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
|
1193 dec2str(dsync_box->highest_pvt_modseq)); |
14584 | 1194 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1195 value = get_cache_fields(ibc, dsync_box); |
14584 | 1196 if (value != NULL) |
1197 dsync_serializer_encode_add(encoder, "cache_fields", value); | |
1198 | |
1199 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
|
1200 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1201 } |
1202 | |
1203 static int | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1204 parse_cache_field(struct dsync_ibc_stream *ibc, struct dsync_mailbox *box, |
14584 | 1205 const char *value) |
1206 { | |
1207 struct dsync_deserializer_decoder *decoder; | |
1208 struct mailbox_cache_field field; | |
1209 const char *error; | |
1210 int ret = 0; | |
1211 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1212 if (dsync_deserializer_decode_begin(ibc->deserializers[ITEM_MAILBOX_CACHE_FIELD], |
14584 | 1213 value, &decoder, &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1214 dsync_ibc_input_error(ibc, NULL, |
14584 | 1215 "cache_field: Invalid input: %s", error); |
1216 return -1; | |
1217 } | |
1218 | |
1219 memset(&field, 0, sizeof(field)); | |
1220 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
|
1221 field.name = p_strdup(ibc->ret_pool, value); |
14584 | 1222 |
1223 value = dsync_deserializer_decode_get(decoder, "decision"); | |
1224 switch (*value) { | |
1225 case 'n': | |
1226 field.decision = MAIL_CACHE_DECISION_NO; | |
1227 break; | |
1228 case 't': | |
1229 field.decision = MAIL_CACHE_DECISION_TEMP; | |
1230 break; | |
1231 case 'y': | |
1232 field.decision = MAIL_CACHE_DECISION_YES; | |
1233 break; | |
1234 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1235 dsync_ibc_input_error(ibc, decoder, "Invalid decision: %s", |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1236 value); |
14584 | 1237 ret = -1; |
1238 break; | |
1239 } | |
1240 if (value[1] == 'F') | |
1241 field.decision |= MAIL_CACHE_DECISION_FORCED; | |
1242 | |
1243 if (dsync_deserializer_decode_try(decoder, "last_used", &value) && | |
1244 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
|
1245 dsync_ibc_input_error(ibc, decoder, "Invalid last_used"); |
14584 | 1246 ret = -1; |
1247 } | |
1248 array_append(&box->cache_fields, &field, 1); | |
1249 | |
1250 dsync_deserializer_decode_finish(&decoder); | |
1251 return ret; | |
1252 } | |
1253 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1254 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1255 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
|
1256 const struct dsync_mailbox **dsync_box_r) |
14584 | 1257 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1258 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
|
1259 pool_t pool = ibc->ret_pool; |
14584 | 1260 struct dsync_deserializer_decoder *decoder; |
1261 struct dsync_mailbox *box; | |
1262 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1263 enum dsync_ibc_recv_ret ret; |
14584 | 1264 |
1265 p_clear(pool); | |
1266 box = p_new(pool, struct dsync_mailbox, 1); | |
1267 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1268 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
|
1269 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1270 return ret; |
1271 | |
1272 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
1273 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
|
1274 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
|
1275 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1276 } |
1277 | |
1278 if (dsync_deserializer_decode_try(decoder, "mailbox_lost", &value)) | |
1279 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
|
1280 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
|
1281 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
|
1282 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
|
1283 (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
|
1284 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
|
1285 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
|
1286 box->have_only_guid128 = TRUE; |
14584 | 1287 value = dsync_deserializer_decode_get(decoder, "uid_validity"); |
1288 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
|
1289 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
|
1290 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1291 } |
1292 value = dsync_deserializer_decode_get(decoder, "uid_next"); | |
1293 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
|
1294 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
|
1295 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1296 } |
1297 value = dsync_deserializer_decode_get(decoder, "messages_count"); | |
1298 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
|
1299 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
|
1300 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1301 } |
1302 value = dsync_deserializer_decode_get(decoder, "first_recent_uid"); | |
1303 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
|
1304 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
|
1305 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1306 } |
1307 value = dsync_deserializer_decode_get(decoder, "highest_modseq"); | |
1308 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
|
1309 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
|
1310 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1311 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1312 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
|
1313 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
|
1314 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
|
1315 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
|
1316 } |
14584 | 1317 |
1318 p_array_init(&box->cache_fields, pool, 32); | |
1319 if (dsync_deserializer_decode_try(decoder, "cache_fields", &value)) { | |
1320 const char *const *fields = t_strsplit(value, "\n"); | |
1321 for (; *fields != NULL; fields++) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1322 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
|
1323 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1324 } |
1325 } | |
1326 | |
1327 *dsync_box_r = box; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1328 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1329 } |
1330 | |
1331 static void | |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1332 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
|
1333 const struct dsync_mailbox_attribute *attr) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1334 { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1335 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
|
1336 struct dsync_serializer_encoder *encoder; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1337 string_t *str = t_str_new(128); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1338 char type[2]; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1339 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1340 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
|
1341 return; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1342 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1343 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
|
1344 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
|
1345 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1346 type[0] = type[1] = '\0'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1347 switch (attr->type) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1348 case MAIL_ATTRIBUTE_TYPE_PRIVATE: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1349 type[0] = 'p'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1350 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1351 case MAIL_ATTRIBUTE_TYPE_SHARED: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1352 type[0] = 's'; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1353 break; |
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 i_assert(type[0] != '\0'); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1356 dsync_serializer_encode_add(encoder, "type", type); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1357 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
|
1358 if (attr->value != NULL) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1359 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
|
1360 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
|
1361 dsync_serializer_encode_add(encoder, "stream", ""); |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1362 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1363 if (attr->deleted) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1364 dsync_serializer_encode_add(encoder, "deleted", ""); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1365 if (attr->last_change != 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1366 dsync_serializer_encode_add(encoder, "last_change", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1367 dec2str(attr->last_change)); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1368 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1369 if (attr->modseq != 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1370 dsync_serializer_encode_add(encoder, "modseq", |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1371 dec2str(attr->modseq)); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1372 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1373 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1374 dsync_serializer_encode_finish(&encoder, str); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1375 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
|
1376 |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1377 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
|
1378 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
|
1379 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
|
1380 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
|
1381 (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
|
1382 } |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1383 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1384 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1385 static enum dsync_ibc_recv_ret |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1386 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
|
1387 const struct dsync_mailbox_attribute **attr_r) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1388 { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1389 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
|
1390 pool_t pool = ibc->ret_pool; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1391 struct dsync_deserializer_decoder *decoder; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1392 struct dsync_mailbox_attribute *attr; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1393 const char *value; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1394 enum dsync_ibc_recv_ret ret; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1395 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1396 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
|
1397 return DSYNC_IBC_RECV_RET_FINISHED; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1398 |
16109
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1399 if (ibc->value_input != NULL) { |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1400 /* wait until the mail's stream has been read */ |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1401 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1402 } |
acb88f199704
dsync: Fixed syncing attribute streams.
Timo Sirainen <tss@iki.fi>
parents:
16052
diff
changeset
|
1403 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1404 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
|
1405 /* 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
|
1406 *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
|
1407 ibc->cur_attr = NULL; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1408 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
|
1409 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1410 |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1411 p_clear(pool); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1412 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
|
1413 |
16051
46b223892373
dsync: Fixed sending mailbox attributes with stream ibc.
Timo Sirainen <tss@iki.fi>
parents:
16025
diff
changeset
|
1414 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
|
1415 if (ret != DSYNC_IBC_RECV_RET_OK) |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1416 return ret; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1417 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1418 value = dsync_deserializer_decode_get(decoder, "type"); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1419 switch (*value) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1420 case 'p': |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1421 attr->type = MAIL_ATTRIBUTE_TYPE_PRIVATE; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1422 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1423 case 's': |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1424 attr->type = MAIL_ATTRIBUTE_TYPE_SHARED; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1425 break; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1426 default: |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1427 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
|
1428 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1429 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1430 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1431 value = dsync_deserializer_decode_get(decoder, "key"); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1432 attr->key = p_strdup(pool, value); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1433 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1434 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
|
1435 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
|
1436 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
|
1437 ibc->cur_attr = attr; |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1438 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
|
1439 } |
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1440 /* 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
|
1441 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
|
1442 } 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
|
1443 attr->value = p_strdup(pool, value); |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1444 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
|
1445 attr->deleted = TRUE; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1446 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
|
1447 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
|
1448 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
|
1449 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1450 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1451 if (dsync_deserializer_decode_try(decoder, "modseq", &value) && |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1452 str_to_uint64(value, &attr->modseq) < 0) { |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1453 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
|
1454 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1455 } |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1456 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1457 *attr_r = attr; |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1458 return DSYNC_IBC_RECV_RET_OK; |
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 |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1461 static void |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1462 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
|
1463 const struct dsync_mail_change *change) |
14584 | 1464 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1465 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1466 struct dsync_serializer_encoder *encoder; |
1467 string_t *str = t_str_new(128); | |
1468 char type[2]; | |
1469 | |
1470 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
|
1471 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_CHANGE]); |
14584 | 1472 |
1473 type[0] = type[1] = '\0'; | |
1474 switch (change->type) { | |
1475 case DSYNC_MAIL_CHANGE_TYPE_SAVE: | |
1476 type[0] = 's'; | |
1477 break; | |
1478 case DSYNC_MAIL_CHANGE_TYPE_EXPUNGE: | |
1479 type[0] = 'e'; | |
1480 break; | |
1481 case DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE: | |
1482 type[0] = 'f'; | |
1483 break; | |
1484 } | |
1485 i_assert(type[0] != '\0'); | |
1486 dsync_serializer_encode_add(encoder, "type", type); | |
1487 dsync_serializer_encode_add(encoder, "uid", dec2str(change->uid)); | |
1488 if (change->guid != NULL) | |
1489 dsync_serializer_encode_add(encoder, "guid", change->guid); | |
1490 if (change->hdr_hash != NULL) { | |
1491 dsync_serializer_encode_add(encoder, "hdr_hash", | |
1492 change->hdr_hash); | |
1493 } | |
1494 if (change->modseq != 0) { | |
1495 dsync_serializer_encode_add(encoder, "modseq", | |
1496 dec2str(change->modseq)); | |
1497 } | |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1498 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
|
1499 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
|
1500 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
|
1501 } |
14584 | 1502 if (change->save_timestamp != 0) { |
1503 dsync_serializer_encode_add(encoder, "save_timestamp", | |
1504 dec2str(change->save_timestamp)); | |
1505 } | |
1506 if (change->add_flags != 0) { | |
1507 dsync_serializer_encode_add(encoder, "add_flags", | |
1508 t_strdup_printf("%x", change->add_flags)); | |
1509 } | |
1510 if (change->remove_flags != 0) { | |
1511 dsync_serializer_encode_add(encoder, "remove_flags", | |
1512 t_strdup_printf("%x", change->remove_flags)); | |
1513 } | |
1514 if (change->final_flags != 0) { | |
1515 dsync_serializer_encode_add(encoder, "final_flags", | |
1516 t_strdup_printf("%x", change->final_flags)); | |
1517 } | |
1518 if (change->keywords_reset) | |
1519 dsync_serializer_encode_add(encoder, "keywords_reset", ""); | |
1520 | |
1521 if (array_is_created(&change->keyword_changes) && | |
1522 array_count(&change->keyword_changes) > 0) { | |
1523 string_t *kw_str = t_str_new(128); | |
1524 const char *const *changes; | |
1525 unsigned int i, count; | |
1526 | |
1527 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
|
1528 str_append_tabescaped(kw_str, changes[0]); |
14584 | 1529 for (i = 1; i < count; i++) { |
1530 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
|
1531 str_append_tabescaped(kw_str, changes[i]); |
14584 | 1532 } |
1533 dsync_serializer_encode_add(encoder, "keyword_changes", | |
1534 str_c(kw_str)); | |
1535 } | |
1536 | |
1537 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
|
1538 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1539 } |
1540 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1541 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1542 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
|
1543 const struct dsync_mail_change **change_r) |
14584 | 1544 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1545 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
|
1546 pool_t pool = ibc->ret_pool; |
14584 | 1547 struct dsync_deserializer_decoder *decoder; |
1548 struct dsync_mail_change *change; | |
1549 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1550 enum dsync_ibc_recv_ret ret; |
14584 | 1551 |
1552 p_clear(pool); | |
1553 change = p_new(pool, struct dsync_mail_change, 1); | |
1554 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1555 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
|
1556 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1557 return ret; |
1558 | |
1559 value = dsync_deserializer_decode_get(decoder, "type"); | |
1560 switch (*value) { | |
1561 case 's': | |
1562 change->type = DSYNC_MAIL_CHANGE_TYPE_SAVE; | |
1563 break; | |
1564 case 'e': | |
1565 change->type = DSYNC_MAIL_CHANGE_TYPE_EXPUNGE; | |
1566 break; | |
1567 case 'f': | |
1568 change->type = DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE; | |
1569 break; | |
1570 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1571 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
|
1572 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1573 } |
1574 | |
1575 value = dsync_deserializer_decode_get(decoder, "uid"); | |
1576 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
|
1577 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
|
1578 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1579 } |
1580 | |
1581 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1582 change->guid = p_strdup(pool, value); | |
1583 if (dsync_deserializer_decode_try(decoder, "hdr_hash", &value)) | |
1584 change->hdr_hash = p_strdup(pool, value); | |
1585 if (dsync_deserializer_decode_try(decoder, "modseq", &value) && | |
1586 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
|
1587 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
|
1588 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1589 } |
15496
5d90e2aa1ba8
dsync: Use private modseqs to support syncing private flags in shared mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
15494
diff
changeset
|
1590 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
|
1591 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
|
1592 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
|
1593 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
|
1594 } |
14584 | 1595 if (dsync_deserializer_decode_try(decoder, "save_timestamp", &value) && |
1596 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
|
1597 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
|
1598 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1599 } |
1600 | |
1601 if (dsync_deserializer_decode_try(decoder, "add_flags", &value)) | |
1602 change->add_flags = strtoul(value, NULL, 16); | |
1603 if (dsync_deserializer_decode_try(decoder, "remove_flags", &value)) | |
1604 change->remove_flags = strtoul(value, NULL, 16); | |
1605 if (dsync_deserializer_decode_try(decoder, "final_flags", &value)) | |
1606 change->final_flags = strtoul(value, NULL, 16); | |
1607 if (dsync_deserializer_decode_try(decoder, "keywords_reset", &value)) | |
1608 change->keywords_reset = TRUE; | |
1609 | |
1610 if (dsync_deserializer_decode_try(decoder, "keyword_changes", &value) && | |
1611 *value != '\0') { | |
1612 const char *const *changes = t_strsplit_tab(value); | |
1613 unsigned int i, count = str_array_length(changes); | |
1614 | |
1615 p_array_init(&change->keyword_changes, pool, count); | |
1616 for (i = 0; i < count; i++) { | |
1617 value = p_strdup(pool, changes[i]); | |
1618 array_append(&change->keyword_changes, &value, 1); | |
1619 } | |
1620 } | |
1621 | |
1622 *change_r = change; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1623 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1624 } |
1625 | |
1626 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1627 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
|
1628 const struct dsync_mail_request *request) |
14584 | 1629 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1630 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1631 struct dsync_serializer_encoder *encoder; |
1632 string_t *str = t_str_new(128); | |
1633 | |
1634 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
|
1635 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_REQUEST]); |
14584 | 1636 if (request->guid != NULL) |
1637 dsync_serializer_encode_add(encoder, "guid", request->guid); | |
1638 if (request->uid != 0) { | |
1639 dsync_serializer_encode_add(encoder, "uid", | |
1640 dec2str(request->uid)); | |
1641 } | |
1642 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
|
1643 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1644 } |
1645 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1646 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1647 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
|
1648 const struct dsync_mail_request **request_r) |
14584 | 1649 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1650 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1651 struct dsync_deserializer_decoder *decoder; |
1652 struct dsync_mail_request *request; | |
1653 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1654 enum dsync_ibc_recv_ret ret; |
14584 | 1655 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1656 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1657 request = p_new(ibc->ret_pool, struct dsync_mail_request, 1); |
14584 | 1658 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1659 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
|
1660 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1661 return ret; |
1662 | |
1663 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
|
1664 request->guid = p_strdup(ibc->ret_pool, value); |
14584 | 1665 if (dsync_deserializer_decode_try(decoder, "uid", &value) && |
1666 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
|
1667 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
|
1668 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1669 } |
1670 | |
1671 *request_r = request; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1672 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1673 } |
1674 | |
1675 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1676 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
|
1677 const struct dsync_mail *mail) |
14584 | 1678 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1679 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1680 struct dsync_serializer_encoder *encoder; |
1681 string_t *str = t_str_new(128); | |
1682 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1683 i_assert(ibc->value_output == NULL); |
14584 | 1684 |
1685 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
|
1686 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL]); |
14584 | 1687 if (mail->guid != NULL) |
1688 dsync_serializer_encode_add(encoder, "guid", mail->guid); | |
1689 if (mail->uid != 0) | |
1690 dsync_serializer_encode_add(encoder, "uid", dec2str(mail->uid)); | |
1691 if (mail->pop3_uidl != NULL) { | |
1692 dsync_serializer_encode_add(encoder, "pop3_uidl", | |
1693 mail->pop3_uidl); | |
1694 } | |
1695 if (mail->pop3_order > 0) { | |
1696 dsync_serializer_encode_add(encoder, "pop3_order", | |
1697 dec2str(mail->pop3_order)); | |
1698 } | |
1699 if (mail->received_date > 0) { | |
1700 dsync_serializer_encode_add(encoder, "received_date", | |
1701 dec2str(mail->received_date)); | |
1702 } | |
1703 if (mail->input != NULL) | |
1704 dsync_serializer_encode_add(encoder, "stream", ""); | |
1705 | |
1706 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
|
1707 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1708 |
1709 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
|
1710 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
|
1711 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
|
1712 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
|
1713 (void)dsync_ibc_stream_send_value_stream(ibc); |
14584 | 1714 } |
1715 } | |
1716 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1717 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1718 dsync_ibc_stream_recv_mail(struct dsync_ibc *_ibc, struct dsync_mail **mail_r) |
14584 | 1719 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1720 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
|
1721 pool_t pool = ibc->ret_pool; |
14584 | 1722 struct dsync_deserializer_decoder *decoder; |
1723 struct dsync_mail *mail; | |
1724 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1725 enum dsync_ibc_recv_ret ret; |
14584 | 1726 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1727 if (ibc->value_input != NULL) { |
14584 | 1728 /* 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
|
1729 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1730 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1731 if (ibc->cur_mail != NULL) { |
14584 | 1732 /* 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
|
1733 *mail_r = ibc->cur_mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1734 ibc->cur_mail = NULL; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1735 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1736 } |
1737 | |
1738 p_clear(pool); | |
1739 mail = p_new(pool, struct dsync_mail, 1); | |
1740 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1741 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
|
1742 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1743 return ret; |
1744 | |
1745 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1746 mail->guid = p_strdup(pool, value); | |
1747 if (dsync_deserializer_decode_try(decoder, "uid", &value) && | |
1748 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
|
1749 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
|
1750 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1751 } |
1752 if (dsync_deserializer_decode_try(decoder, "pop3_uidl", &value)) | |
1753 mail->pop3_uidl = p_strdup(pool, value); | |
1754 if (dsync_deserializer_decode_try(decoder, "pop3_order", &value) && | |
1755 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
|
1756 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
|
1757 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1758 } |
1759 if (dsync_deserializer_decode_try(decoder, "received_date", &value) && | |
1760 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
|
1761 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
|
1762 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1763 } |
1764 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
|
1765 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
|
1766 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
|
1767 ibc->cur_mail = mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1768 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1769 } |
1770 /* 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
|
1771 i_assert(ibc->value_input == NULL); |
14584 | 1772 } |
1773 | |
1774 *mail_r = mail; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1775 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1776 } |
1777 | |
15632
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
1778 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
|
1779 { |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
1780 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
|
1781 |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1782 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
|
1783 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
|
1784 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
|
1785 } |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
1786 } |
40dd9a080b6e
dsync: Close mail streams earlier on failures to avoid assert-crashing
Timo Sirainen <tss@iki.fi>
parents:
15594
diff
changeset
|
1787 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1788 static bool dsync_ibc_stream_is_send_queue_full(struct dsync_ibc *_ibc) |
14584 | 1789 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1790 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1791 size_t bytes; |
1792 | |
16052
0e5a359b7b7f
lib-storage: Mailbox attributes can now be accessed via istreams.
Timo Sirainen <tss@iki.fi>
parents:
16051
diff
changeset
|
1793 if (ibc->value_output != NULL) |
14584 | 1794 return TRUE; |
1795 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1796 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
|
1797 if (bytes < DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE) |
14584 | 1798 return FALSE; |
1799 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1800 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 1801 return TRUE; |
1802 } | |
1803 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1804 static bool dsync_ibc_stream_has_pending_data(struct dsync_ibc *_ibc) |
14584 | 1805 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1806 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1807 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1808 return ibc->has_pending_data; |
14584 | 1809 } |
1810 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1811 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
|
1812 dsync_ibc_stream_deinit, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1813 dsync_ibc_stream_send_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1814 dsync_ibc_stream_recv_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1815 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
|
1816 dsync_ibc_stream_send_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1817 dsync_ibc_stream_recv_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1818 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
|
1819 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
|
1820 dsync_ibc_stream_send_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1821 dsync_ibc_stream_recv_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1822 dsync_ibc_stream_send_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1823 dsync_ibc_stream_recv_mailbox, |
16025
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1824 dsync_ibc_stream_send_mailbox_attribute, |
c6082de4bf5b
dsync: Added support for syncing mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15986
diff
changeset
|
1825 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
|
1826 dsync_ibc_stream_send_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1827 dsync_ibc_stream_recv_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1828 dsync_ibc_stream_send_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1829 dsync_ibc_stream_recv_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1830 dsync_ibc_stream_send_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1831 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
|
1832 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
|
1833 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
|
1834 dsync_ibc_stream_has_pending_data |
14584 | 1835 }; |
1836 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1837 struct dsync_ibc * |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1838 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
|
1839 const char *name, const char *temp_path_prefix) |
14584 | 1840 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1841 struct dsync_ibc_stream *ibc; |
14584 | 1842 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1843 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
|
1844 ibc->ibc.v = dsync_ibc_stream_vfuncs; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1845 ibc->input = input; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1846 ibc->output = output; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1847 ibc->name = i_strdup(name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1848 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
|
1849 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
|
1850 dsync_ibc_stream_init(ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1851 return &ibc->ibc; |
14584 | 1852 } |