Lines Matching refs:ctx

23 static void idle_add_keepalive_timeout(struct cmd_idle_context *ctx);
27 idle_finish(struct cmd_idle_context *ctx, bool done_ok, bool free_cmd)
29 struct client *client = ctx->client;
31 timeout_remove(&ctx->keepalive_to);
32 timeout_remove(&ctx->to_hibernate);
34 if (ctx->sync_ctx != NULL) {
36 (void)imap_sync_deinit(ctx->sync_ctx, ctx->cmd);
46 client_send_tagline(ctx->cmd, "OK Idle completed.");
48 client_send_tagline(ctx->cmd, "BAD Expected DONE.");
52 client_command_free(&ctx->cmd);
56 idle_client_handle_input(struct cmd_idle_context *ctx, bool free_cmd)
60 while ((line = i_stream_next_line(ctx->client->input)) != NULL) {
61 if (ctx->client->input_skip_line)
62 ctx->client->input_skip_line = FALSE;
64 idle_finish(ctx, strcasecmp(line, "DONE") == 0,
72 static bool idle_client_input_more(struct cmd_idle_context *ctx)
74 struct client *client = ctx->client;
86 idle_finish(ctx, FALSE, TRUE);
90 if (ctx->sync_ctx != NULL) {
97 return idle_client_handle_input(ctx, TRUE);
100 static void idle_client_input(struct cmd_idle_context *ctx)
102 struct client *client = ctx->client;
104 if (idle_client_input_more(ctx)) {
112 static void keepalive_timeout(struct cmd_idle_context *ctx)
114 if (ctx->client->output_cmd_lock != NULL) {
119 if (o_stream_get_buffer_used_size(ctx->client->output) == 0) {
124 o_stream_cork(ctx->client->output);
125 client_send_line(ctx->client, "* OK Still here");
126 o_stream_uncork(ctx->client->output);
131 timeout_reset(ctx->client->to_idle);
133 idle_add_keepalive_timeout(ctx);
136 static bool idle_sync_now(struct mailbox *box, struct cmd_idle_context *ctx)
138 i_assert(ctx->sync_ctx == NULL);
142 timeout_remove(&ctx->to_hibernate);
144 ctx->sync_pending = FALSE;
145 ctx->sync_ctx = imap_sync_init(ctx->client, box, 0, 0);
146 return cmd_idle_continue(ctx->cmd);
149 static void idle_callback(struct mailbox *box, struct cmd_idle_context *ctx)
151 struct client *client = ctx->client;
153 if (ctx->sync_ctx != NULL)
154 ctx->sync_pending = TRUE;
156 ctx->manual_cork = TRUE;
157 (void)idle_sync_now(box, ctx);
163 static void idle_add_keepalive_timeout(struct cmd_idle_context *ctx)
165 struct client *client = ctx->client;
175 timeout_remove(&ctx->keepalive_to);
176 ctx->keepalive_to = timeout_add(interval, keepalive_timeout, ctx);
179 static void idle_hibernate_timeout(struct cmd_idle_context *ctx)
181 struct client *client = ctx->client;
183 i_assert(ctx->sync_ctx == NULL);
184 i_assert(!ctx->sync_pending);
190 timeout_remove(&ctx->to_hibernate);
194 static void idle_add_hibernate_timeout(struct cmd_idle_context *ctx)
196 unsigned int secs = ctx->client->set->imap_hibernate_timeout;
198 i_assert(ctx->to_hibernate == NULL);
203 ctx->to_hibernate =
204 timeout_add(secs * 1000, idle_hibernate_timeout, ctx);
210 struct cmd_idle_context *ctx = cmd->context;
214 idle_finish(ctx, FALSE, FALSE);
218 if (ctx->to_hibernate != NULL)
219 timeout_reset(ctx->to_hibernate);
221 if (ctx->manual_cork) {
227 if (ctx->sync_ctx != NULL) {
228 if (imap_sync_more(ctx->sync_ctx) == 0) {
230 if (ctx->manual_cork) {
231 ctx->manual_cork = FALSE;
238 if (imap_sync_deinit(ctx->sync_ctx, ctx->cmd) < 0) {
243 ctx->sync_ctx = NULL;
246 ctx->keepalive_to != NULL)
247 idle_add_keepalive_timeout(ctx);
249 if (ctx->sync_pending) {
255 return idle_sync_now(client->mailbox, ctx);
257 if (ctx->to_hibernate == NULL)
258 idle_add_hibernate_timeout(ctx);
261 if (ctx->manual_cork) {
262 ctx->manual_cork = FALSE;
267 idle_finish(ctx, FALSE, FALSE);
274 idle_client_input, ctx);
283 struct cmd_idle_context *ctx;
285 ctx = p_new(cmd->pool, struct cmd_idle_context, 1);
286 ctx->cmd = cmd;
287 ctx->client = client;
288 idle_add_keepalive_timeout(ctx);
289 idle_add_hibernate_timeout(ctx);
292 mailbox_notify_changes(client->mailbox, idle_callback, ctx);
301 client->io = io_add_istream(client->input, idle_client_input, ctx);
304 cmd->context = ctx;
309 idle_sync_now(client->mailbox, ctx);
310 return idle_client_handle_input(ctx, FALSE);