Skip to content

Commit 658c3e2

Browse files
committed
Initial commit for splitting struct client into a generic client and imap_client.
Allowing other protocols to be implemented later on. Most of the code is still very IMAP-specific, but this give a starting point.
1 parent dee21c1 commit 658c3e2

20 files changed

+1394
-1215
lines changed

src/checkpoint.c

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "mail-types.h"
77
#include "settings.h"
88
#include "mailbox.h"
9-
#include "client.h"
9+
#include "imap-client.h"
1010
#include "checkpoint.h"
1111

1212
#include <stdlib.h>
@@ -32,7 +32,7 @@ struct checkpoint_context {
3232
};
3333

3434
static void
35-
keyword_map_update(struct checkpoint_context *ctx, struct client *client)
35+
keyword_map_update(struct checkpoint_context *ctx, struct imap_client *client)
3636
{
3737
const struct mailbox_keyword *kw_my;
3838
const char *const *kw_all, *name;
@@ -53,7 +53,7 @@ keyword_map_update(struct checkpoint_context *ctx, struct client *client)
5353
if (!ctx->first) {
5454
i_error("Checkpoint: client %u: "
5555
"Missing keyword %s",
56-
client->idx, name);
56+
client->client.idx, name);
5757
}
5858
array_append(&ctx->all_keywords, &name, 1);
5959
kw_all = array_get(&ctx->all_keywords, &all_count);
@@ -99,8 +99,9 @@ checkpoint_keywords_to_str(struct checkpoint_context *ctx,
9999
}
100100
return str_c(str);
101101
}
102+
102103
static void
103-
checkpoint_update(struct checkpoint_context *ctx, struct client *client)
104+
checkpoint_update(struct checkpoint_context *ctx, struct imap_client *client)
104105
{
105106
struct mailbox_view *view = client->view;
106107
const struct message_metadata_dynamic *msgs;
@@ -116,22 +117,22 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
116117
ctx->errors = TRUE;
117118
i_error("Checkpoint: client %u: "
118119
"Mailbox has only %u of %u messages",
119-
client->global_id, count, ctx->count);
120+
client->client.global_id, count, ctx->count);
120121
}
121122

122123
if (!view->storage->checkpoint->thread_sent) {
123124
/* no THREAD checking */
124125
} else if (client->view->last_thread_reply == NULL) {
125126
ctx->errors = TRUE;
126127
i_error("Checkpoint: client %u: Missing THREAD reply",
127-
client->global_id);
128+
client->client.global_id);
128129
} else if (ctx->thread_reply == NULL)
129130
ctx->thread_reply = client->view->last_thread_reply;
130131
else if (strcmp(client->view->last_thread_reply,
131132
ctx->thread_reply) != 0) {
132133
ctx->errors = TRUE;
133134
i_error("Checkpoint: client %u: THREAD reply differs: %s != %s",
134-
client->global_id, client->view->last_thread_reply,
135+
client->client.global_id, client->view->last_thread_reply,
135136
ctx->thread_reply);
136137
}
137138

@@ -150,7 +151,7 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
150151
ctx->errors = TRUE;
151152
i_error("Checkpoint: client %u: "
152153
"Message seq=%u UID %u != %u",
153-
client->global_id, i + 1,
154+
client->client.global_id, i + 1,
154155
uids[i], ctx->uids[i]);
155156
break;
156157
}
@@ -164,7 +165,7 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
164165
i_error("Checkpoint: client %u: "
165166
"Message seq=%u UID=%u "
166167
"modseqs differ: %s vs %s",
167-
client->global_id, i + 1, uids[i],
168+
client->client.global_id, i + 1, uids[i],
168169
dec2str(msgs[i].modseq),
169170
dec2str(ctx->messages[i].modseq));
170171
}
@@ -195,7 +196,7 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
195196
i_error("Checkpoint: client %u: "
196197
"Message seq=%u UID=%u "
197198
"has \\Recent flag in multiple sessions",
198-
client->global_id, i + 1, uids[i]);
199+
client->client.global_id, i + 1, uids[i]);
199200
view->storage->dont_track_recent = TRUE;
200201
}
201202
}
@@ -206,7 +207,7 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
206207
ctx->errors = TRUE;
207208
i_error("Checkpoint: client %u: Message seq=%u UID=%u "
208209
"flags differ: (%s) vs (%s)",
209-
client->global_id, i + 1, uids[i],
210+
client->client.global_id, i + 1, uids[i],
210211
mail_flags_to_str(this_flags),
211212
mail_flags_to_str(other_flags));
212213
}
@@ -215,7 +216,7 @@ checkpoint_update(struct checkpoint_context *ctx, struct client *client)
215216
ctx->errors = TRUE;
216217
i_error("Checkpoint: client %u: Message seq=%u UID=%u "
217218
"keywords differ: (%s) vs (%s)",
218-
client->global_id, i + 1, uids[i],
219+
client->client.global_id, i + 1, uids[i],
219220
checkpoint_keywords_to_str(ctx, keywords_remapped),
220221
checkpoint_keywords_to_str(ctx, ctx->messages[i].keyword_bitmask));
221222
}
@@ -253,13 +254,15 @@ static void checkpoint_send_state_cmd(struct mailbox_storage *storage,
253254

254255
c = array_get(&clients, &count);
255256
for (i = 0; i < count; i++) {
256-
if (c[i] == NULL || c[i]->checkpointing != storage)
257+
struct imap_client *client = imap_client(c[i]);
258+
259+
if (client == NULL || client->checkpointing != storage)
257260
continue;
258261

259262
/* send the checkpoint command */
260-
c[i]->plan[0] = state;
261-
c[i]->plan_size = 1;
262-
(void)client_plan_send_next_cmd(c[i]);
263+
client->plan[0] = state;
264+
client->plan_size = 1;
265+
(void)imap_client_plan_send_next_cmd(client);
263266
storage->checkpoint->clients_left++;
264267
}
265268
}
@@ -304,17 +307,18 @@ void checkpoint_neg(struct mailbox_storage *storage)
304307
/* get maximum number of messages in mailbox */
305308
recent_total = 0;
306309
for (i = 0; i < count; i++) {
307-
if (c[i] == NULL || c[i]->checkpointing != storage)
310+
struct imap_client *client = imap_client(c[i]);
311+
if (client == NULL || client->checkpointing != storage)
308312
continue;
309313

310-
i_assert(array_count(&c[i]->commands) == 0);
311-
if (c[i]->view->select_uidnext != 0) {
314+
i_assert(array_count(&client->commands) == 0);
315+
if (client->view->select_uidnext != 0) {
312316
min_uidnext = I_MIN(min_uidnext,
313-
c[i]->view->select_uidnext);
317+
client->view->select_uidnext);
314318
}
315-
recent_total += c[i]->view->recent_count;
319+
recent_total += client->view->recent_count;
316320
max_msgs_count = I_MAX(max_msgs_count,
317-
array_count(&c[i]->view->uidmap));
321+
array_count(&client->view->uidmap));
318322
}
319323

320324
/* make sure everyone has the same idea of what the mailbox
@@ -330,11 +334,12 @@ void checkpoint_neg(struct mailbox_storage *storage)
330334
i_array_init(&ctx.all_keywords, 32);
331335
i_array_init(&ctx.cur_keywords_map, 32);
332336
for (i = 0; i < count; i++) {
333-
if (c[i] == NULL || c[i]->checkpointing != storage)
337+
struct imap_client *client = imap_client(c[i]);
338+
if (client == NULL || client->checkpointing != storage)
334339
continue;
335340

336341
check_count++;
337-
checkpoint_update(&ctx, c[i]);
342+
checkpoint_update(&ctx, client);
338343
ctx.first = FALSE;
339344
}
340345
for (i = 0; i < ctx.count; i++)
@@ -372,15 +377,16 @@ void checkpoint_neg(struct mailbox_storage *storage)
372377

373378
/* checkpointing is done - continue normal commands */
374379
for (i = 0; i < count; i++) {
375-
if (c[i] == NULL)
380+
struct imap_client *client = imap_client(c[i]);
381+
if (client == NULL)
376382
continue;
377-
if (c[i]->checkpointing == storage)
378-
c[i]->checkpointing = NULL;
383+
if (client->checkpointing == storage)
384+
client->checkpointing = NULL;
379385

380-
if (array_count(&c[i]->commands) == 0 &&
381-
c[i]->state != STATE_BANNER) {
382-
(void)client_send_more_commands(c[i]);
383-
i_assert(array_count(&c[i]->commands) > 0);
386+
if (array_count(&client->commands) == 0 &&
387+
client->client.state != STATE_BANNER) {
388+
(void)client_send_more_commands(&client->client);
389+
i_assert(array_count(&client->commands) > 0);
384390
}
385391
}
386392

@@ -402,12 +408,14 @@ void clients_checkpoint(struct mailbox_storage *storage)
402408

403409
c = array_get(&clients, &count);
404410
for (i = 0; i < count; i++) {
405-
if (c[i] == NULL || c[i]->login_state != LSTATE_SELECTED)
411+
struct imap_client *client = imap_client(c[i]);
412+
if (client == NULL ||
413+
client->client.login_state != LSTATE_SELECTED)
406414
continue;
407415

408-
if (c[i]->storage == storage) {
409-
c[i]->checkpointing = storage;
410-
if (array_count(&c[i]->commands) > 0)
416+
if (client->storage == storage) {
417+
client->checkpointing = storage;
418+
if (array_count(&client->commands) > 0)
411419
storage->checkpoint->clients_left++;
412420
}
413421
}

0 commit comments

Comments
 (0)