Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3141:61abed5f7864 HEAD
Moved command-specific variables from struct client to struct
client_command_context and changed code to use it.
line wrap: on
line diff
--- a/src/imap/client.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/client.c Sat Feb 05 20:07:26 2005 +0200 @@ -36,7 +36,9 @@ imap_max_line_length); client->last_input = ioloop_time; - client->cmd_pool = pool_alloconly_create("command pool", 8192); + client->cmd.pool = pool_alloconly_create("command pool", 8192); + client->cmd.client = client; + client->keywords.pool = pool_alloconly_create("mailbox_keywords", 512); client->namespaces = namespaces; @@ -62,7 +64,7 @@ /* try to deinitialize the command */ i_stream_close(client->input); o_stream_close(client->output); - ret = client->cmd_func(client); + ret = client->cmd.func(&client->cmd); i_assert(ret); } @@ -78,7 +80,7 @@ o_stream_unref(client->output); pool_unref(client->keywords.pool); - pool_unref(client->cmd_pool); + pool_unref(client->cmd.pool); i_free(client); /* quit the program */ @@ -119,9 +121,10 @@ CLIENT_OUTPUT_OPTIMAL_SIZE; } -void client_send_tagline(struct client *client, const char *data) +void client_send_tagline(struct client_command_context *cmd, const char *data) { - const char *tag = client->cmd_tag; + struct client *client = cmd->client; + const char *tag = cmd->tag; if (client->output->closed) return; @@ -135,9 +138,11 @@ (void)o_stream_send(client->output, "\r\n", 2); } -void client_send_command_error(struct client *client, const char *msg) +void client_send_command_error(struct client_command_context *cmd, + const char *msg) { - const char *error, *cmd; + struct client *client = cmd->client; + const char *error, *cmd_name; int fatal; if (msg == NULL) { @@ -148,17 +153,17 @@ } } - if (client->cmd_tag == NULL) + if (cmd->tag == NULL) error = t_strconcat("BAD Error in IMAP tag: ", msg, NULL); - else if (client->cmd_name == NULL) + else if (cmd->name == NULL) error = t_strconcat("BAD Error in IMAP command: ", msg, NULL); else { - cmd = t_str_ucase(client->cmd_name); + cmd_name = t_str_ucase(cmd->name); error = t_strconcat("BAD Error in IMAP command ", - cmd, ": ", msg, NULL); + cmd_name, ": ", msg, NULL); } - client_send_tagline(client, error); + client_send_tagline(cmd, error); if (++client->bad_counter >= CLIENT_MAX_BAD_COMMANDS) { client_disconnect_with_error(client, @@ -168,17 +173,17 @@ /* client_read_args() failures rely on this being set, so that the command processing is stopped even while command function returns FALSE. */ - client->cmd_param_error = TRUE; + cmd->param_error = TRUE; } -int client_read_args(struct client *client, unsigned int count, +int client_read_args(struct client_command_context *cmd, unsigned int count, unsigned int flags, struct imap_arg **args) { int ret; i_assert(count <= INT_MAX); - ret = imap_parser_read_args(client->parser, count, flags, args); + ret = imap_parser_read_args(cmd->client->parser, count, flags, args); if (ret >= (int)count) { /* all parameters read successfully */ return TRUE; @@ -187,20 +192,21 @@ return FALSE; } else { /* error, or missing arguments */ - client_send_command_error(client, ret < 0 ? NULL : + client_send_command_error(cmd, ret < 0 ? NULL : "Missing arguments"); return FALSE; } } -int client_read_string_args(struct client *client, unsigned int count, ...) +int client_read_string_args(struct client_command_context *cmd, + unsigned int count, ...) { struct imap_arg *imap_args; va_list va; const char *str; unsigned int i; - if (!client_read_args(client, count, 0, &imap_args)) + if (!client_read_args(cmd, count, 0, &imap_args)) return FALSE; va_start(va, count); @@ -208,13 +214,13 @@ const char **ret = va_arg(va, const char **); if (imap_args[i].type == IMAP_ARG_EOL) { - client_send_command_error(client, "Missing arguments."); + client_send_command_error(cmd, "Missing arguments."); break; } str = imap_arg_string(&imap_args[i]); if (str == NULL) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); break; } @@ -228,6 +234,8 @@ void _client_reset_command(struct client *client) { + pool_t pool; + /* reset input idle time because command output might have taken a long time and we don't want to disconnect client immediately then */ client->last_input = ioloop_time; @@ -238,13 +246,13 @@ IO_READ, _client_input, client); } - client->cmd_tag = NULL; - client->cmd_name = NULL; - client->cmd_func = NULL; - client->cmd_uid = FALSE; - client->cmd_param_error = FALSE; + pool = client->cmd.pool; + memset(&client->cmd, 0, sizeof(client->cmd)); - p_clear(client->cmd_pool); + p_clear(pool); + client->cmd.pool = pool; + client->cmd.client = client; + imap_parser_reset(client->parser); } @@ -269,11 +277,13 @@ return !client->input_skip_line; } -static int client_handle_input(struct client *client) +static int client_handle_input(struct client_command_context *cmd) { - if (client->cmd_func != NULL) { + struct client *client = cmd->client; + + if (cmd->func != NULL) { /* command is being executed - continue it */ - if (client->cmd_func(client) || client->cmd_param_error) { + if (cmd->func(cmd) || cmd->param_error) { /* command execution was finished */ client->bad_counter = 0; _client_reset_command(client); @@ -293,35 +303,35 @@ /* pass through to parse next command */ } - if (client->cmd_tag == NULL) { - client->cmd_tag = imap_parser_read_word(client->parser); - if (client->cmd_tag == NULL) + if (cmd->tag == NULL) { + cmd->tag = imap_parser_read_word(client->parser); + if (cmd->tag == NULL) return FALSE; /* need more data */ - client->cmd_tag = p_strdup(client->cmd_pool, client->cmd_tag); + cmd->tag = p_strdup(cmd->pool, cmd->tag); } - if (client->cmd_name == NULL) { - client->cmd_name = imap_parser_read_word(client->parser); - if (client->cmd_name == NULL) + if (cmd->name == NULL) { + cmd->name = imap_parser_read_word(client->parser); + if (cmd->name == NULL) return FALSE; /* need more data */ - client->cmd_name = p_strdup(client->cmd_pool, client->cmd_name); + cmd->name = p_strdup(cmd->pool, cmd->name); } - if (client->cmd_name == '\0') { + if (cmd->name == '\0') { /* command not given - cmd_func is already NULL. */ } else { /* find the command function */ - client->cmd_func = command_find(client->cmd_name); + cmd->func = command_find(cmd->name); } - if (client->cmd_func == NULL) { + if (cmd->func == NULL) { /* unknown command */ - client_send_command_error(client, "Unknown command."); + client_send_command_error(cmd, "Unknown command."); client->input_skip_line = TRUE; _client_reset_command(client); } else { client->input_skip_line = TRUE; - if (client->cmd_func(client) || client->cmd_param_error) { + if (cmd->func(cmd) || cmd->param_error) { /* command execution was finished. */ client->bad_counter = 0; _client_reset_command(client); @@ -337,6 +347,7 @@ void _client_input(void *context) { struct client *client = context; + struct client_command_context *cmd = &client->cmd; if (client->command_pending) { /* already processing one command. wait. */ @@ -359,13 +370,13 @@ until newline is found. */ client->input_skip_line = TRUE; - client_send_command_error(client, "Too long argument."); + client_send_command_error(cmd, "Too long argument."); _client_reset_command(client); break; } o_stream_cork(client->output); - while (client_handle_input(client)) + while (client_handle_input(cmd)) ; o_stream_uncork(client->output); @@ -379,6 +390,7 @@ int _client_output(void *context) { struct client *client = context; + struct client_command_context *cmd = &client->cmd; int ret, finished; client->last_output = ioloop_time; @@ -394,7 +406,7 @@ /* continue processing command */ o_stream_cork(client->output); client->output_pending = TRUE; - finished = client->cmd_func(client) || client->cmd_param_error; + finished = cmd->func(cmd) || cmd->param_error; o_stream_uncork(client->output); /* a bit kludgy. normally we would want to get back here, but IDLE
--- a/src/imap/client.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/client.h Sat Feb 05 20:07:26 2005 +0200 @@ -15,6 +15,20 @@ unsigned int keywords_count; }; +struct client_command_context { + struct client *client; + + pool_t pool; + const char *tag; + const char *name; + + command_func_t *func; + void *context; + + unsigned int uid:1; /* used UID command */ + unsigned int param_error:1; +}; + struct client { int socket; struct io *io; @@ -31,17 +45,11 @@ unsigned int bad_counter; struct imap_parser *parser; - pool_t cmd_pool; - const char *cmd_tag; - const char *cmd_name; - command_func_t *cmd_func; - void *cmd_context; + struct client_command_context cmd; unsigned int command_pending:1; unsigned int input_pending:1; unsigned int output_pending:1; - unsigned int cmd_uid:1; /* used UID command */ - unsigned int cmd_param_error:1; unsigned int rawlog:1; unsigned int input_skip_line:1; /* skip all the data until we've found a new line */ @@ -60,18 +68,20 @@ -1 if error */ int client_send_line(struct client *client, const char *data); /* Send line of data to client, prefixed with client->tag */ -void client_send_tagline(struct client *client, const char *data); +void client_send_tagline(struct client_command_context *cmd, const char *data); /* Send BAD command error to client. msg can be NULL. */ -void client_send_command_error(struct client *client, const char *msg); +void client_send_command_error(struct client_command_context *cmd, + const char *msg); /* Read a number of arguments. Returns TRUE if everything was read or FALSE if either needs more data or error occured. */ -int client_read_args(struct client *client, unsigned int count, +int client_read_args(struct client_command_context *cmd, unsigned int count, unsigned int flags, struct imap_arg **args); /* Reads a number of string arguments. ... is a list of pointers where to store the arguments. */ -int client_read_string_args(struct client *client, unsigned int count, ...); +int client_read_string_args(struct client_command_context *cmd, + unsigned int count, ...); void clients_init(void); void clients_deinit(void);
--- a/src/imap/cmd-append.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-append.c Sat Feb 05 20:07:26 2005 +0200 @@ -14,6 +14,7 @@ struct cmd_append_context { struct client *client; + struct client_command_context *cmd; struct mail_storage *storage; struct mailbox *box; struct mailbox_transaction_context *t; @@ -25,11 +26,12 @@ struct mail_save_context *save_ctx; }; -static int cmd_append_continue_message(struct client *client); +static int cmd_append_continue_message(struct client_command_context *cmd); static void client_input(void *context) { struct client *client = context; + struct client_command_context *cmd = &client->cmd; client->last_input = ioloop_time; @@ -50,12 +52,12 @@ until newline is found. */ client->input_skip_line = TRUE; - client_send_command_error(client, "Too long argument."); + client_send_command_error(cmd, "Too long argument."); _client_reset_command(client); break; } - if (client->cmd_func(client)) { + if (cmd->func(cmd)) { /* command execution was finished */ client->bad_counter = 0; _client_reset_command(client); @@ -119,16 +121,16 @@ if (ctx->t != NULL) mailbox_transaction_rollback(ctx->t); - if (ctx->box != ctx->client->mailbox && ctx->box != NULL) + if (ctx->box != ctx->cmd->client->mailbox && ctx->box != NULL) mailbox_close(ctx->box); (void)i_stream_get_data(ctx->client->input, &size); ctx->client->input_pending = size != 0; } -static int cmd_append_continue_cancel(struct client *client) +static int cmd_append_continue_cancel(struct client_command_context *cmd) { - struct cmd_append_context *ctx = client->cmd_context; + struct cmd_append_context *ctx = cmd->context; size_t size; (void)i_stream_read(ctx->input); @@ -156,14 +158,15 @@ ctx->msg_size); ctx->client->command_pending = TRUE; - ctx->client->cmd_func = cmd_append_continue_cancel; - ctx->client->cmd_context = ctx; - return cmd_append_continue_cancel(ctx->client); + ctx->cmd->func = cmd_append_continue_cancel; + ctx->cmd->context = ctx; + return cmd_append_continue_cancel(ctx->cmd); } -static int cmd_append_continue_parsing(struct client *client) +static int cmd_append_continue_parsing(struct client_command_context *cmd) { - struct cmd_append_context *ctx = client->cmd_context; + struct client *client = cmd->client; + struct cmd_append_context *ctx = cmd->context; struct imap_arg *args; struct imap_arg_list *flags_list; enum mail_flags flags; @@ -181,7 +184,7 @@ IMAP_PARSE_FLAG_LITERAL_SIZE, &args); if (ret == -1) { if (ctx->box != NULL) - client_send_command_error(client, NULL); + client_send_command_error(cmd, NULL); cmd_append_finish(ctx); return TRUE; } @@ -203,22 +206,22 @@ ret = mailbox_transaction_commit(ctx->t, 0); ctx->t = NULL; if (ret < 0) { - client_send_storage_error(client, ctx->storage); + client_send_storage_error(cmd, ctx->storage); cmd_append_finish(ctx); return TRUE; } - sync_flags = ctx->box == client->mailbox ? + sync_flags = ctx->box == cmd->client->mailbox ? 0 : MAILBOX_SYNC_FLAG_FAST; client->input_skip_line = TRUE; cmd_append_finish(ctx); - return cmd_sync(client, sync_flags, "OK Append completed."); + return cmd_sync(cmd, sync_flags, "OK Append completed."); } if (!validate_args(args, &flags_list, &internal_date_str, &ctx->msg_size, &nonsync)) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); return cmd_append_cancel(ctx, nonsync); } @@ -229,7 +232,7 @@ } if (flags_list != NULL) { - if (!client_parse_mail_flags(client, flags_list->args, + if (!client_parse_mail_flags(cmd, flags_list->args, &flags, &keywords_list)) return cmd_append_cancel(ctx, nonsync); keywords = keywords_list == NULL ? NULL : @@ -245,13 +248,13 @@ timezone_offset = 0; } else if (!imap_parse_datetime(internal_date_str, &internal_date, &timezone_offset)) { - client_send_tagline(client, "BAD Invalid internal date."); + client_send_tagline(cmd, "BAD Invalid internal date."); return cmd_append_cancel(ctx, nonsync); } if (ctx->msg_size == 0) { /* no message data, abort */ - client_send_tagline(client, "NO Append aborted."); + client_send_tagline(cmd, "NO Append aborted."); cmd_append_finish(ctx); return TRUE; } @@ -276,13 +279,14 @@ mailbox_keywords_free(ctx->t, keywords); client->command_pending = TRUE; - client->cmd_func = cmd_append_continue_message; - return cmd_append_continue_message(client); + cmd->func = cmd_append_continue_message; + return cmd_append_continue_message(cmd); } -static int cmd_append_continue_message(struct client *client) +static int cmd_append_continue_message(struct client_command_context *cmd) { - struct cmd_append_context *ctx = client->cmd_context; + struct client *client = cmd->client; + struct cmd_append_context *ctx = cmd->context; size_t size; int failed; @@ -310,7 +314,7 @@ if (ctx->save_ctx == NULL) { /* failed above */ - client_send_storage_error(client, ctx->storage); + client_send_storage_error(cmd, ctx->storage); failed = TRUE; } else if (client->input->eof) { /* client disconnected */ @@ -318,7 +322,7 @@ mailbox_save_cancel(ctx->save_ctx); } else if (mailbox_save_finish(ctx->save_ctx, NULL) < 0) { failed = TRUE; - client_send_storage_error(client, ctx->storage); + client_send_storage_error(cmd, ctx->storage); } ctx->save_ctx = NULL; @@ -330,57 +334,60 @@ /* prepare for next message */ client->command_pending = FALSE; imap_parser_reset(ctx->save_parser); - client->cmd_func = cmd_append_continue_parsing; - return cmd_append_continue_parsing(client); + cmd->func = cmd_append_continue_parsing; + return cmd_append_continue_parsing(cmd); } return FALSE; } -static struct mailbox *get_mailbox(struct client *client, const char *name) +static struct mailbox * +get_mailbox(struct client_command_context *cmd, const char *name) { struct mail_storage *storage; struct mailbox *box; - if (!client_verify_mailbox_name(client, name, TRUE, FALSE)) + if (!client_verify_mailbox_name(cmd, name, TRUE, FALSE)) return NULL; - storage = client_find_storage(client, &name); + storage = client_find_storage(cmd, &name); if (storage == NULL) return NULL; - if (client->mailbox != NULL && - mailbox_name_equals(mailbox_get_name(client->mailbox), name)) - return client->mailbox; + if (cmd->client->mailbox != NULL && + mailbox_name_equals(mailbox_get_name(cmd->client->mailbox), name)) + return cmd->client->mailbox; box = mailbox_open(storage, name, MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT); if (box == NULL) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return NULL; } return box; } -int cmd_append(struct client *client) +int cmd_append(struct client_command_context *cmd) { + struct client *client = cmd->client; struct cmd_append_context *ctx; struct mailbox_status status; const char *mailbox; /* <mailbox> */ - if (!client_read_string_args(client, 1, &mailbox)) + if (!client_read_string_args(cmd, 1, &mailbox)) return FALSE; - ctx = p_new(client->cmd_pool, struct cmd_append_context, 1); + ctx = p_new(cmd->pool, struct cmd_append_context, 1); + ctx->cmd = cmd; ctx->client = client; - ctx->box = get_mailbox(client, mailbox); + ctx->box = get_mailbox(cmd, mailbox); if (ctx->box != NULL) { ctx->storage = mailbox_get_storage(ctx->box); if (mailbox_get_status(ctx->box, STATUS_KEYWORDS, &status) < 0) { - client_send_storage_error(client, ctx->storage); + client_send_storage_error(cmd, ctx->storage); mailbox_close(ctx->box); ctx->box = NULL; } else { @@ -402,7 +409,7 @@ ctx->save_parser = imap_parser_create(client->input, client->output, imap_max_line_length); - client->cmd_func = cmd_append_continue_parsing; - client->cmd_context = ctx; - return cmd_append_continue_parsing(client); + cmd->func = cmd_append_continue_parsing; + cmd->context = ctx; + return cmd_append_continue_parsing(cmd); }
--- a/src/imap/cmd-authenticate.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-authenticate.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,8 +3,8 @@ #include "common.h" #include "commands.h" -int cmd_authenticate(struct client *client) +int cmd_authenticate(struct client_command_context *cmd) { - client_send_tagline(client, "OK Already authenticated."); + client_send_tagline(cmd, "OK Already authenticated."); return TRUE; }
--- a/src/imap/cmd-capability.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-capability.c Sat Feb 05 20:07:26 2005 +0200 @@ -4,11 +4,12 @@ #include "commands.h" #include "str.h" -int cmd_capability(struct client *client) +int cmd_capability(struct client_command_context *cmd) { - client_send_line(client, t_strconcat("* CAPABILITY ", - str_c(capability_string), NULL)); + client_send_line(cmd->client, + t_strconcat("* CAPABILITY ", + str_c(capability_string), NULL)); - client_send_tagline(client, "OK Capability completed."); + client_send_tagline(cmd, "OK Capability completed."); return TRUE; }
--- a/src/imap/cmd-check.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-check.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,11 +3,11 @@ #include "common.h" #include "commands.h" -int cmd_check(struct client *client) +int cmd_check(struct client_command_context *cmd) { - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; - return cmd_sync(client, MAILBOX_SYNC_FLAG_FULL_READ | + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FULL_READ | MAILBOX_SYNC_FLAG_FULL_WRITE, "OK Check completed."); }
--- a/src/imap/cmd-close.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-close.c Sat Feb 05 20:07:26 2005 +0200 @@ -4,12 +4,13 @@ #include "commands.h" #include "imap-expunge.h" -int cmd_close(struct client *client) +int cmd_close(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mailbox *mailbox = client->mailbox; struct mail_storage *storage; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; storage = mailbox_get_storage(mailbox); @@ -23,6 +24,6 @@ if (mailbox_close(mailbox) < 0) client_send_untagged_storage_error(client, storage); - client_send_tagline(client, "OK Close completed."); + client_send_tagline(cmd, "OK Close completed."); return TRUE; }
--- a/src/imap/cmd-copy.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-copy.c Sat Feb 05 20:07:26 2005 +0200 @@ -48,8 +48,9 @@ return ret; } -int cmd_copy(struct client *client) +int cmd_copy(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mail_storage *storage; struct mailbox *destbox; struct mailbox_transaction_context *t; @@ -59,21 +60,21 @@ int ret; /* <message set> <mailbox> */ - if (!client_read_string_args(client, 2, &messageset, &mailbox)) + if (!client_read_string_args(cmd, 2, &messageset, &mailbox)) return FALSE; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; /* open the destination mailbox */ - if (!client_verify_mailbox_name(client, mailbox, TRUE, FALSE)) + if (!client_verify_mailbox_name(cmd, mailbox, TRUE, FALSE)) return TRUE; - search_arg = imap_search_get_arg(client, messageset, client->cmd_uid); + search_arg = imap_search_get_arg(cmd, messageset, cmd->uid); if (search_arg == NULL) return TRUE; - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return TRUE; @@ -83,7 +84,7 @@ destbox = mailbox_open(storage, mailbox, MAILBOX_OPEN_FAST | MAILBOX_OPEN_KEEP_RECENT); if (destbox == NULL) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return TRUE; } } @@ -104,13 +105,13 @@ } if (ret > 0) - return cmd_sync(client, sync_flags, "OK Copy completed."); + return cmd_sync(cmd, sync_flags, "OK Copy completed."); else if (ret == 0) { /* some messages were expunged, sync them */ - return cmd_sync(client, 0, + return cmd_sync(cmd, 0, "NO Some of the requested messages no longer exist."); } else { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return TRUE; } }
--- a/src/imap/cmd-create.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-create.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ #include "common.h" #include "commands.h" -int cmd_create(struct client *client) +int cmd_create(struct client_command_context *cmd) { struct mail_storage *storage; const char *mailbox, *full_mailbox; @@ -11,11 +11,11 @@ size_t len; /* <mailbox> */ - if (!client_read_string_args(client, 1, &mailbox)) + if (!client_read_string_args(cmd, 1, &mailbox)) return FALSE; full_mailbox = mailbox; - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return TRUE; @@ -31,12 +31,12 @@ full_mailbox = t_strndup(full_mailbox, strlen(full_mailbox)-1); } - if (!client_verify_mailbox_name(client, full_mailbox, FALSE, TRUE)) + if (!client_verify_mailbox_name(cmd, full_mailbox, FALSE, TRUE)) return TRUE; if (mail_storage_mailbox_create(storage, mailbox, directory) < 0) - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); else - client_send_tagline(client, "OK Create completed."); + client_send_tagline(cmd, "OK Create completed."); return TRUE; }
--- a/src/imap/cmd-delete.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-delete.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,19 +3,20 @@ #include "common.h" #include "commands.h" -int cmd_delete(struct client *client) +int cmd_delete(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mail_storage *storage; struct mailbox *mailbox; const char *name; /* <mailbox> */ - if (!client_read_string_args(client, 1, &name)) + if (!client_read_string_args(cmd, 1, &name)) return FALSE; if (strcasecmp(name, "INBOX") == 0) { /* INBOX can't be deleted */ - client_send_tagline(client, "NO INBOX can't be deleted."); + client_send_tagline(cmd, "NO INBOX can't be deleted."); return TRUE; } @@ -28,14 +29,14 @@ if (mailbox_close(mailbox) < 0) client_send_untagged_storage_error(client, storage); } else { - storage = client_find_storage(client, &name); + storage = client_find_storage(cmd, &name); if (storage == NULL) return TRUE; } if (mail_storage_mailbox_delete(storage, name) < 0) - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); else - client_send_tagline(client, "OK Delete completed."); + client_send_tagline(cmd, "OK Delete completed."); return TRUE; }
--- a/src/imap/cmd-examine.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-examine.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ #include "common.h" #include "commands.h" -int cmd_examine(struct client *client) +int cmd_examine(struct client_command_context *cmd) { - return _cmd_select_full(client, TRUE); + return _cmd_select_full(cmd, TRUE); }
--- a/src/imap/cmd-expunge.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-expunge.c Sat Feb 05 20:07:26 2005 +0200 @@ -5,48 +5,51 @@ #include "imap-search.h" #include "imap-expunge.h" -int cmd_uid_expunge(struct client *client) +int cmd_uid_expunge(struct client_command_context *cmd) { + struct client *client = cmd->client; struct imap_arg *args; struct mail_search_arg *search_arg; const char *uidset; - if (!client_read_args(client, 1, 0, &args)) + if (!client_read_args(cmd, 1, 0, &args)) return FALSE; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; uidset = imap_arg_string(&args[0]); if (uidset == NULL) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); return TRUE; } - search_arg = imap_search_get_arg(client, uidset, TRUE); + search_arg = imap_search_get_arg(cmd, uidset, TRUE); if (search_arg == NULL) return TRUE; if (imap_expunge(client->mailbox, search_arg)) { - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST, + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST, "OK Expunge completed."); } else { - client_send_storage_error(client, + client_send_storage_error(cmd, mailbox_get_storage(client->mailbox)); return TRUE; } } -int cmd_expunge(struct client *client) +int cmd_expunge(struct client_command_context *cmd) { - if (!client_verify_open_mailbox(client)) + struct client *client = cmd->client; + + if (!client_verify_open_mailbox(cmd)) return TRUE; if (imap_expunge(client->mailbox, NULL)) { - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST, + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST, "OK Expunge completed."); } else { - client_send_storage_error(client, + client_send_storage_error(cmd, mailbox_get_storage(client->mailbox)); return TRUE; }
--- a/src/imap/cmd-fetch.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-fetch.c Sat Feb 05 20:07:26 2005 +0200 @@ -18,8 +18,7 @@ }; static int -fetch_parse_args(struct client *client, struct imap_fetch_context *ctx, - struct imap_arg *arg) +fetch_parse_args(struct imap_fetch_context *ctx, struct imap_arg *arg) { const char *str, *const *macro; @@ -55,13 +54,13 @@ return FALSE; } if (arg->type != IMAP_ARG_EOL) { - client_send_command_error(client, + client_send_command_error(ctx->cmd, "FETCH list contains non-atoms."); return FALSE; } } - if (client->cmd_uid) { + if (ctx->cmd->uid) { if (!imap_fetch_init_handler(ctx, "UID", &arg)) return FALSE; } @@ -69,8 +68,9 @@ return TRUE; } -static int cmd_fetch_finish(struct client *client, int failed) +static int cmd_fetch_finish(struct client_command_context *cmd, int failed) { + struct client *client = cmd->client; static const char *ok_message = "OK Fetch completed."; if (failed) { @@ -90,27 +90,27 @@ client_disconnect_with_error(client, error); } else { /* user error, we'll reply with BAD */ - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); } return TRUE; } if ((client_workarounds & WORKAROUND_OE6_FETCH_NO_NEWMAIL) != 0) { - client_send_tagline(client, ok_message); + client_send_tagline(cmd, ok_message); return TRUE; } else { - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST | - (client->cmd_uid ? 0 : - MAILBOX_SYNC_FLAG_NO_EXPUNGES), ok_message); + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST | + (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), + ok_message); } } -static int cmd_fetch_continue(struct client *client) +static int cmd_fetch_continue(struct client_command_context *cmd) { - struct imap_fetch_context *ctx = client->cmd_context; + struct imap_fetch_context *ctx = cmd->context; int ret; - if (client->output->closed) + if (cmd->client->output->closed) ret = -1; else { if ((ret = imap_fetch(ctx)) == 0) { @@ -123,39 +123,40 @@ if (imap_fetch_deinit(ctx) < 0) ret = -1; - return cmd_fetch_finish(client, ret < 0); + return cmd_fetch_finish(cmd, ret < 0); } -int cmd_fetch(struct client *client) +int cmd_fetch(struct client_command_context *cmd) { - struct imap_fetch_context *ctx; + struct client *client = cmd->client; + struct imap_fetch_context *ctx; struct imap_arg *args; struct mail_search_arg *search_arg; const char *messageset; int ret; - if (!client_read_args(client, 0, 0, &args)) + if (!client_read_args(cmd, 0, 0, &args)) return FALSE; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; messageset = imap_arg_string(&args[0]); if (messageset == NULL || (args[1].type != IMAP_ARG_LIST && args[1].type != IMAP_ARG_ATOM)) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); return TRUE; } - search_arg = imap_search_get_arg(client, messageset, client->cmd_uid); + search_arg = imap_search_get_arg(cmd, messageset, cmd->uid); if (search_arg == NULL) return TRUE; - ctx = imap_fetch_init(client); + ctx = imap_fetch_init(cmd); if (ctx == NULL) return TRUE; - if (!fetch_parse_args(client, ctx, &args[1])) { + if (!fetch_parse_args(ctx, &args[1])) { imap_fetch_deinit(ctx); return TRUE; } @@ -164,13 +165,13 @@ if ((ret = imap_fetch(ctx)) == 0) { /* unfinished */ client->command_pending = TRUE; - client->cmd_func = cmd_fetch_continue; - client->cmd_context = ctx; + cmd->func = cmd_fetch_continue; + cmd->context = ctx; return FALSE; } if (ret < 0) ctx->failed = TRUE; if (imap_fetch_deinit(ctx) < 0) ret = -1; - return cmd_fetch_finish(client, ret < 0); + return cmd_fetch_finish(cmd, ret < 0); }
--- a/src/imap/cmd-idle.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-idle.c Sat Feb 05 20:07:26 2005 +0200 @@ -13,6 +13,7 @@ struct cmd_idle_context { struct client *client; + struct client_command_context *cmd; struct imap_sync_context *sync_ctx; struct timeout *to; @@ -22,7 +23,7 @@ unsigned int sync_pending:1; }; -static int cmd_idle_continue(struct client *client); +static int cmd_idle_continue(struct client_command_context *cmd); static void idle_finish(struct cmd_idle_context *ctx, int done_ok) { @@ -48,9 +49,9 @@ mailbox_notify_changes(client->mailbox, 0, NULL, NULL); if (done_ok) - client_send_tagline(client, "OK Idle completed."); + client_send_tagline(ctx->cmd, "OK Idle completed."); else - client_send_tagline(client, "BAD Expected DONE."); + client_send_tagline(ctx->cmd, "BAD Expected DONE."); o_stream_uncork(client->output); @@ -126,13 +127,14 @@ else { ctx->sync_pending = FALSE; ctx->sync_ctx = imap_sync_init(ctx->client, box, 0); - cmd_idle_continue(ctx->client); + cmd_idle_continue(ctx->cmd); } } -static int cmd_idle_continue(struct client *client) +static int cmd_idle_continue(struct client_command_context *cmd) { - struct cmd_idle_context *ctx = client->cmd_context; + struct client *client = cmd->client; + struct cmd_idle_context *ctx = cmd->context; if (client->output->closed) { idle_finish(ctx, FALSE); @@ -166,13 +168,15 @@ return FALSE; } -int cmd_idle(struct client *client) +int cmd_idle(struct client_command_context *cmd) { + struct client *client = cmd->client; struct cmd_idle_context *ctx; const char *str; unsigned int interval; - ctx = p_new(client->cmd_pool, struct cmd_idle_context, 1); + ctx = p_new(cmd->pool, struct cmd_idle_context, 1); + ctx->cmd = cmd; ctx->client = client; if ((client_workarounds & WORKAROUND_OUTLOOK_IDLE) != 0 && @@ -197,7 +201,7 @@ IO_READ, idle_client_input, ctx); client->command_pending = TRUE; - client->cmd_func = cmd_idle_continue; - client->cmd_context = ctx; + cmd->func = cmd_idle_continue; + cmd->context = ctx; return FALSE; }
--- a/src/imap/cmd-list.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-list.c Sat Feb 05 20:07:26 2005 +0200 @@ -63,14 +63,15 @@ return *str == '\0' ? "" : str+1; } -static int parse_list_flags(struct client *client, struct imap_arg *args, - enum mailbox_list_flags *list_flags) +static int +parse_list_flags(struct client_command_context *cmd, struct imap_arg *args, + enum mailbox_list_flags *list_flags) { const char *atom; while (args->type != IMAP_ARG_EOL) { if (args->type != IMAP_ARG_ATOM) { - client_send_command_error(client, + client_send_command_error(cmd, "List options contains non-atoms."); return FALSE; } @@ -82,7 +83,7 @@ else if (strcasecmp(atom, "CHILDREN") == 0) *list_flags |= MAILBOX_LIST_CHILDREN; else { - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "BAD Invalid list option ", atom, NULL)); return FALSE; } @@ -178,8 +179,10 @@ } static void -list_namespace_init(struct client *client, struct cmd_list_context *ctx) +list_namespace_init(struct client_command_context *cmd, + struct cmd_list_context *ctx) { + struct client *client = cmd->client; struct namespace *ns = ctx->ns; const char *cur_prefix, *cur_ref, *cur_mask; enum imap_match_result match; @@ -206,7 +209,7 @@ ctx->inbox && cur_ref == ctx->ref); } - ctx->glob = imap_match_init(client->cmd_pool, ctx->mask, + ctx->glob = imap_match_init(cmd->pool, ctx->mask, ctx->inbox && cur_ref == ctx->ref, ns->sep); if (*cur_ref != '\0' || *cur_prefix == '\0') @@ -216,7 +219,7 @@ if (cur_prefix[len-1] == ns->sep) cur_prefix = t_strndup(cur_prefix, len-1); match = ns->hidden ? IMAP_MATCH_NO : - imap_match(ctx->glob, cur_prefix); + imap_match(ctx->glob, cur_prefix); if (match == IMAP_MATCH_YES) { /* The prefix itself matches */ @@ -298,31 +301,33 @@ list_flags); } -static int cmd_list_continue(struct client *client) +static int cmd_list_continue(struct client_command_context *cmd) { - struct cmd_list_context *ctx = client->cmd_context; + struct client *client = cmd->client; + struct cmd_list_context *ctx = cmd->context; int ret; for (; ctx->ns != NULL; ctx->ns = ctx->ns->next) { if (ctx->list_ctx == NULL) - list_namespace_init(client, ctx); + list_namespace_init(cmd, ctx); if ((ret = list_namespace_mailboxes(client, ctx)) < 0) { - client_send_storage_error(client, ctx->ns->storage); + client_send_storage_error(cmd, ctx->ns->storage); return TRUE; } if (ret == 0) return FALSE; } - client_send_tagline(client, !ctx->lsub ? + client_send_tagline(cmd, !ctx->lsub ? "OK List completed." : "OK Lsub completed."); return TRUE; } -int _cmd_list_full(struct client *client, int lsub) +int _cmd_list_full(struct client_command_context *cmd, int lsub) { + struct client *client = cmd->client; struct namespace *ns; struct imap_arg *args; enum mailbox_list_flags list_flags; @@ -330,7 +335,7 @@ const char *ref, *mask; /* [(<options>)] <reference> <mailbox wildcards> */ - if (!client_read_args(client, 0, 0, &args)) + if (!client_read_args(cmd, 0, 0, &args)) return FALSE; if (lsub) { @@ -342,7 +347,7 @@ list_flags = 0; } else { list_flags = _MAILBOX_LIST_LISTEXT; - if (!parse_list_flags(client, IMAP_ARG_LIST(&args[0])->args, + if (!parse_list_flags(cmd, IMAP_ARG_LIST(&args[0])->args, &list_flags)) return TRUE; args++; @@ -356,7 +361,7 @@ mask = imap_arg_string(&args[1]); if (ref == NULL || mask == NULL) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); return TRUE; } @@ -373,9 +378,9 @@ "* LIST (\\Noselect) \"", ns->sep_str, "\" \"\"", NULL)); } - client_send_tagline(client, "OK List completed."); + client_send_tagline(cmd, "OK List completed."); } else { - ctx = p_new(client->cmd_pool, struct cmd_list_context, 1); + ctx = p_new(cmd->pool, struct cmd_list_context, 1); ctx->ref = ref; ctx->mask = mask; ctx->list_flags = list_flags; @@ -384,21 +389,21 @@ (*ref == '\0' && strncasecmp(mask, "INBOX", 5) == 0); ctx->ns = client->namespaces; - client->cmd_context = ctx; - if (!cmd_list_continue(client)) { + cmd->context = ctx; + if (!cmd_list_continue(cmd)) { /* unfinished */ client->command_pending = TRUE; - client->cmd_func = cmd_list_continue; + cmd->func = cmd_list_continue; return FALSE; } - client->cmd_context = NULL; + cmd->context = NULL; return TRUE; } return TRUE; } -int cmd_list(struct client *client) +int cmd_list(struct client_command_context *cmd) { - return _cmd_list_full(client, FALSE); + return _cmd_list_full(cmd, FALSE); }
--- a/src/imap/cmd-login.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-login.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,8 +3,8 @@ #include "common.h" #include "commands.h" -int cmd_login(struct client *client) +int cmd_login(struct client_command_context *cmd) { - client_send_tagline(client, "OK Already logged in."); + client_send_tagline(cmd, "OK Already logged in."); return TRUE; }
--- a/src/imap/cmd-logout.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-logout.c Sat Feb 05 20:07:26 2005 +0200 @@ -4,8 +4,10 @@ #include "ostream.h" #include "commands.h" -int cmd_logout(struct client *client) +int cmd_logout(struct client_command_context *cmd) { + struct client *client = cmd->client; + client_send_line(client, "* BYE Logging out"); o_stream_uncork(client->output); @@ -17,7 +19,7 @@ client->mailbox = NULL; } - client_send_tagline(client, "OK Logout completed."); + client_send_tagline(cmd, "OK Logout completed."); client_disconnect(client); return TRUE; }
--- a/src/imap/cmd-lsub.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-lsub.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ #include "common.h" #include "commands.h" -int cmd_lsub(struct client *client) +int cmd_lsub(struct client_command_context *cmd) { - return _cmd_list_full(client, TRUE); + return _cmd_list_full(cmd, TRUE); }
--- a/src/imap/cmd-namespace.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-namespace.c Sat Feb 05 20:07:26 2005 +0200 @@ -33,8 +33,9 @@ str_append(str, "NIL"); } -int cmd_namespace(struct client *client) +int cmd_namespace(struct client_command_context *cmd) { + struct client *client = cmd->client; string_t *str; str = t_str_new(256); @@ -47,6 +48,6 @@ list_namespaces(client->namespaces, NAMESPACE_PUBLIC, str); client_send_line(client, str_c(str)); - client_send_tagline(client, "OK Namespace completed."); + client_send_tagline(cmd, "OK Namespace completed."); return TRUE; }
--- a/src/imap/cmd-noop.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-noop.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ #include "common.h" #include "commands.h" -int cmd_noop(struct client *client) +int cmd_noop(struct client_command_context *cmd) { - return cmd_sync(client, 0, "OK NOOP completed."); + return cmd_sync(cmd, 0, "OK NOOP completed."); }
--- a/src/imap/cmd-rename.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-rename.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,36 +3,36 @@ #include "common.h" #include "commands.h" -int cmd_rename(struct client *client) +int cmd_rename(struct client_command_context *cmd) { struct mail_storage *old_storage, *new_storage; const char *oldname, *newname; /* <old name> <new name> */ - if (!client_read_string_args(client, 2, &oldname, &newname)) + if (!client_read_string_args(cmd, 2, &oldname, &newname)) return FALSE; - if (!client_verify_mailbox_name(client, newname, FALSE, TRUE)) + if (!client_verify_mailbox_name(cmd, newname, FALSE, TRUE)) return TRUE; - old_storage = client_find_storage(client, &oldname); + old_storage = client_find_storage(cmd, &oldname); if (old_storage == NULL) return TRUE; - new_storage = client_find_storage(client, &newname); + new_storage = client_find_storage(cmd, &newname); if (new_storage == NULL) return TRUE; if (old_storage != new_storage) { - client_send_tagline(client, + client_send_tagline(cmd, "NO Can't rename mailbox to another storage type."); return TRUE; } if (mail_storage_mailbox_rename(old_storage, oldname, newname) < 0) - client_send_storage_error(client, old_storage); + client_send_storage_error(cmd, old_storage); else - client_send_tagline(client, "OK Rename completed."); + client_send_tagline(cmd, "OK Rename completed."); return TRUE; }
--- a/src/imap/cmd-search.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-search.c Sat Feb 05 20:07:26 2005 +0200 @@ -8,9 +8,10 @@ #define STRBUF_SIZE 1024 -static int imap_search(struct client *client, const char *charset, +static int imap_search(struct client_command_context *cmd, const char *charset, struct mail_search_arg *sargs) { + struct client *client = cmd->client; struct mail_search_context *ctx; struct mailbox_transaction_context *trans; const struct mail *mail; @@ -18,7 +19,7 @@ int ret, uid, first = TRUE; str = t_str_new(STRBUF_SIZE); - uid = client->cmd_uid; + uid = cmd->uid; trans = mailbox_transaction_begin(client->mailbox, FALSE); ctx = mailbox_search_init(trans, charset, sargs, @@ -53,8 +54,9 @@ return ret == 0; } -int cmd_search(struct client *client) +int cmd_search(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mail_search_arg *sargs; struct imap_arg *args; int args_count; @@ -65,12 +67,12 @@ if (args_count == -2) return FALSE; - client_send_command_error(client, args_count < 0 ? NULL : + client_send_command_error(cmd, args_count < 0 ? NULL : "Missing SEARCH arguments."); return TRUE; } - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; if (args->type == IMAP_ARG_ATOM && @@ -79,7 +81,7 @@ args++; if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) { - client_send_command_error(client, + client_send_command_error(cmd, "Invalid charset argument."); return TRUE; } @@ -90,17 +92,17 @@ charset = NULL; } - sargs = imap_search_args_build(client->cmd_pool, client->mailbox, args, &error); + sargs = imap_search_args_build(cmd->pool, client->mailbox, + args, &error); if (sargs == NULL) { /* error in search arguments */ - client_send_tagline(client, t_strconcat("NO ", error, NULL)); - } else if (imap_search(client, charset, sargs)) { - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST | - (client->cmd_uid ? - 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), + client_send_tagline(cmd, t_strconcat("NO ", error, NULL)); + } else if (imap_search(cmd, charset, sargs)) { + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST | + (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), "OK Search completed."); } else { - client_send_storage_error(client, + client_send_storage_error(cmd, mailbox_get_storage(client->mailbox)); }
--- a/src/imap/cmd-select.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-select.c Sat Feb 05 20:07:26 2005 +0200 @@ -4,15 +4,16 @@ #include "commands.h" #include "imap-sync.h" -int _cmd_select_full(struct client *client, int readonly) +int _cmd_select_full(struct client_command_context *cmd, int readonly) { + struct client *client = cmd->client; struct mail_storage *storage; struct mailbox *box; struct mailbox_status status; const char *mailbox; /* <mailbox> */ - if (!client_read_string_args(client, 1, &mailbox)) + if (!client_read_string_args(cmd, 1, &mailbox)) return FALSE; if (client->mailbox != NULL) { @@ -24,19 +25,19 @@ } } - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return TRUE; box = mailbox_open(storage, mailbox, !readonly ? 0 : (MAILBOX_OPEN_READONLY | MAILBOX_OPEN_KEEP_RECENT)); if (box == NULL) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return TRUE; } if (imap_sync_nonselected(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); mailbox_close(box); return TRUE; } @@ -45,7 +46,7 @@ STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY | STATUS_UIDNEXT | STATUS_KEYWORDS, &status) < 0) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); mailbox_close(box); return TRUE; } @@ -87,13 +88,13 @@ "Disk space is full, delete some messages."); } - client_send_tagline(client, mailbox_is_readonly(box) ? + client_send_tagline(cmd, mailbox_is_readonly(box) ? "OK [READ-ONLY] Select completed." : "OK [READ-WRITE] Select completed."); return TRUE; } -int cmd_select(struct client *client) +int cmd_select(struct client_command_context *cmd) { - return _cmd_select_full(client, FALSE); + return _cmd_select_full(cmd, FALSE); }
--- a/src/imap/cmd-sort.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-sort.c Sat Feb 05 20:07:26 2005 +0200 @@ -25,7 +25,7 @@ }; static enum mail_sort_type * -get_sort_program(struct client *client, struct imap_arg *args) +get_sort_program(struct client_command_context *cmd, struct imap_arg *args) { enum mail_sort_type type; buffer_t *buf; @@ -33,7 +33,7 @@ if (args->type == IMAP_ARG_EOL) { /* empyty list */ - client_send_command_error(client, "Empty sort program."); + client_send_command_error(cmd, "Empty sort program."); return NULL; } @@ -49,7 +49,7 @@ } if (sort_names[i].type == MAIL_SORT_END) { - client_send_command_error(client, t_strconcat( + client_send_command_error(cmd, t_strconcat( "Unknown sort argument: ", arg, NULL)); return NULL; } @@ -63,7 +63,7 @@ buffer_append(buf, &type, sizeof(type)); if (args->type != IMAP_ARG_EOL) { - client_send_command_error(client, + client_send_command_error(cmd, "Invalid sort list argument."); return NULL; } @@ -71,8 +71,9 @@ return buffer_free_without_data(buf); } -int cmd_sort(struct client *client) +int cmd_sort(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mail_search_arg *sargs; enum mail_sort_type *sorting; struct imap_arg *args; @@ -85,28 +86,28 @@ return FALSE; if (args_count < 3) { - client_send_command_error(client, args_count < 0 ? NULL : + client_send_command_error(cmd, args_count < 0 ? NULL : "Missing or invalid arguments."); return TRUE; } - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; /* sort program */ if (args->type != IMAP_ARG_LIST) { - client_send_command_error(client, "Invalid sort argument."); + client_send_command_error(cmd, "Invalid sort argument."); return TRUE; } - sorting = get_sort_program(client, IMAP_ARG_LIST(args)->args); + sorting = get_sort_program(cmd, IMAP_ARG_LIST(args)->args); if (sorting == NULL) return TRUE; args++; /* charset */ if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) { - client_send_command_error(client, + client_send_command_error(cmd, "Invalid charset argument."); return TRUE; } @@ -118,15 +119,14 @@ sargs = imap_search_args_build(pool, client->mailbox, args, &error); if (sargs == NULL) { /* error in search arguments */ - client_send_tagline(client, t_strconcat("NO ", error, NULL)); - } else if (imap_sort(client, charset, sargs, sorting) == 0) { + client_send_tagline(cmd, t_strconcat("NO ", error, NULL)); + } else if (imap_sort(cmd, charset, sargs, sorting) == 0) { pool_unref(pool); - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST | - (client->cmd_uid ? - 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST | + (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), "OK Sort completed."); } else { - client_send_storage_error(client, + client_send_storage_error(cmd, mailbox_get_storage(client->mailbox)); }
--- a/src/imap/cmd-status.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-status.c Sat Feb 05 20:07:26 2005 +0200 @@ -8,7 +8,7 @@ /* Returns status items, or -1 if error */ static enum mailbox_status_items -get_status_items(struct client *client, struct imap_arg *args) +get_status_items(struct client_command_context *cmd, struct imap_arg *args) { const char *item; enum mailbox_status_items items; @@ -17,7 +17,7 @@ for (; args->type != IMAP_ARG_EOL; args++) { if (args->type != IMAP_ARG_ATOM) { /* list may contain only atoms */ - client_send_command_error(client, + client_send_command_error(cmd, "Status list contains non-atoms."); return -1; } @@ -35,7 +35,7 @@ else if (strcmp(item, "UNSEEN") == 0) items |= STATUS_UNSEEN; else { - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "BAD Invalid status item ", item, NULL)); return -1; } @@ -76,8 +76,9 @@ return !failed; } -int cmd_status(struct client *client) +int cmd_status(struct client_command_context *cmd) { + struct client *client = cmd->client; struct imap_arg *args; struct mailbox_status status; enum mailbox_status_items items; @@ -86,29 +87,29 @@ string_t *str; /* <mailbox> <status items> */ - if (!client_read_args(client, 2, 0, &args)) + if (!client_read_args(cmd, 2, 0, &args)) return FALSE; mailbox = imap_arg_string(&args[0]); if (mailbox == NULL || args[1].type != IMAP_ARG_LIST) { - client_send_command_error(client, "Status items must be list."); + client_send_command_error(cmd, "Status items must be list."); return TRUE; } /* get the items client wants */ - items = get_status_items(client, IMAP_ARG_LIST(&args[1])->args); + items = get_status_items(cmd, IMAP_ARG_LIST(&args[1])->args); if (items == (enum mailbox_status_items)-1) { /* error */ return TRUE; } - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return FALSE; /* get status */ if (!get_mailbox_status(client, storage, mailbox, items, &status)) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return TRUE; } @@ -133,7 +134,7 @@ str_append_c(str, ')'); client_send_line(client, str_c(str)); - client_send_tagline(client, "OK Status completed."); + client_send_tagline(cmd, "OK Status completed."); return TRUE; }
--- a/src/imap/cmd-store.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-store.c Sat Feb 05 20:07:26 2005 +0200 @@ -6,7 +6,7 @@ #include "imap-search.h" #include "imap-util.h" -static int get_modify_type(struct client *client, const char *item, +static int get_modify_type(struct client_command_context *cmd, const char *item, enum modify_type *modify_type, int *silent) { if (*item == '+') { @@ -20,14 +20,14 @@ } if (strncasecmp(item, "FLAGS", 5) != 0) { - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "NO Invalid item ", item, NULL)); return FALSE; } *silent = strcasecmp(item+5, ".SILENT") == 0; if (!*silent && item[5] != '\0') { - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "NO Invalid item ", item, NULL)); return FALSE; } @@ -35,8 +35,9 @@ return TRUE; } -int cmd_store(struct client *client) +int cmd_store(struct client_command_context *cmd) { + struct client *client = cmd->client; struct imap_arg *args; enum mail_flags flags; const char *const *keywords_list; @@ -50,10 +51,10 @@ const char *messageset, *item; int silent, failed; - if (!client_read_args(client, 0, 0, &args)) + if (!client_read_args(cmd, 0, 0, &args)) return FALSE; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; /* validate arguments */ @@ -61,26 +62,26 @@ item = imap_arg_string(&args[1]); if (messageset == NULL || item == NULL) { - client_send_command_error(client, "Invalid arguments."); + client_send_command_error(cmd, "Invalid arguments."); return TRUE; } - if (!get_modify_type(client, item, &modify_type, &silent)) + if (!get_modify_type(cmd, item, &modify_type, &silent)) return TRUE; if (args[2].type == IMAP_ARG_LIST) { - if (!client_parse_mail_flags(client, + if (!client_parse_mail_flags(cmd, IMAP_ARG_LIST(&args[2])->args, &flags, &keywords_list)) return TRUE; } else { - if (!client_parse_mail_flags(client, args+2, + if (!client_parse_mail_flags(cmd, args+2, &flags, &keywords_list)) return TRUE; } box = client->mailbox; - search_arg = imap_search_get_arg(client, messageset, client->cmd_uid); + search_arg = imap_search_get_arg(cmd, messageset, cmd->uid); if (search_arg == NULL) return TRUE; @@ -121,12 +122,11 @@ } if (!failed) { - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST | - (client->cmd_uid ? - 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST | + (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), "OK Store completed."); } else { - client_send_storage_error(client, mailbox_get_storage(box)); + client_send_storage_error(cmd, mailbox_get_storage(box)); return TRUE; } }
--- a/src/imap/cmd-subscribe.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-subscribe.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,33 +3,33 @@ #include "common.h" #include "commands.h" -int _cmd_subscribe_full(struct client *client, int subscribe) +int _cmd_subscribe_full(struct client_command_context *cmd, int subscribe) { struct mail_storage *storage; const char *mailbox; /* <mailbox> */ - if (!client_read_string_args(client, 1, &mailbox)) + if (!client_read_string_args(cmd, 1, &mailbox)) return FALSE; - if (!client_verify_mailbox_name(client, mailbox, subscribe, FALSE)) + if (!client_verify_mailbox_name(cmd, mailbox, subscribe, FALSE)) return TRUE; - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return TRUE; if (mail_storage_set_subscribed(storage, mailbox, subscribe) < 0) - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); else { - client_send_tagline(client, subscribe ? + client_send_tagline(cmd, subscribe ? "OK Subscribe completed." : "OK Unsubscribe completed."); } return TRUE; } -int cmd_subscribe(struct client *client) +int cmd_subscribe(struct client_command_context *cmd) { - return _cmd_subscribe_full(client, TRUE); + return _cmd_subscribe_full(cmd, TRUE); }
--- a/src/imap/cmd-thread.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-thread.c Sat Feb 05 20:07:26 2005 +0200 @@ -6,8 +6,9 @@ #include "imap-search.h" #include "imap-thread.h" -int cmd_thread(struct client *client) +int cmd_thread(struct client_command_context *cmd) { + struct client *client = cmd->client; enum mail_thread_type threading; struct mail_search_arg *sargs; struct imap_arg *args; @@ -20,16 +21,16 @@ return FALSE; if (args_count < 3) { - client_send_command_error(client, args_count < 0 ? NULL : + client_send_command_error(cmd, args_count < 0 ? NULL : "Missing or invalid arguments."); return TRUE; } - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) { - client_send_command_error(client, + client_send_command_error(cmd, "Invalid thread algorithm argument."); return TRUE; } @@ -38,18 +39,18 @@ if (strcasecmp(str, "REFERENCES") == 0) threading = MAIL_THREAD_REFERENCES; else if (strcasecmp(str, "ORDEREDSUBJECT") == 0) { - client_send_command_error(client, + client_send_command_error(cmd, "ORDEREDSUBJECT threading is currently not supported."); return TRUE; } else { - client_send_command_error(client, "Unknown thread algorithm."); + client_send_command_error(cmd, "Unknown thread algorithm."); return TRUE; } args++; /* charset */ if (args->type != IMAP_ARG_ATOM && args->type != IMAP_ARG_STRING) { - client_send_command_error(client, + client_send_command_error(cmd, "Invalid charset argument."); return TRUE; } @@ -61,15 +62,14 @@ sargs = imap_search_args_build(pool, client->mailbox, args, &error); if (sargs == NULL) { /* error in search arguments */ - client_send_tagline(client, t_strconcat("NO ", error, NULL)); - } else if (imap_thread(client, charset, sargs, threading) == 0) { + client_send_tagline(cmd, t_strconcat("NO ", error, NULL)); + } else if (imap_thread(cmd, charset, sargs, threading) == 0) { pool_unref(pool); - return cmd_sync(client, MAILBOX_SYNC_FLAG_FAST | - (client->cmd_uid ? - 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), + return cmd_sync(cmd, MAILBOX_SYNC_FLAG_FAST | + (cmd->uid ? 0 : MAILBOX_SYNC_FLAG_NO_EXPUNGES), "OK Thread completed."); } else { - client_send_storage_error(client, + client_send_storage_error(cmd, mailbox_get_storage(client->mailbox)); }
--- a/src/imap/cmd-uid.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-uid.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,23 +3,23 @@ #include "common.h" #include "commands.h" -int cmd_uid(struct client *client) +int cmd_uid(struct client_command_context *cmd) { - const char *cmd; + const char *cmd_name; /* UID <command> <args> */ - cmd = imap_parser_read_word(client->parser); - if (cmd == NULL) + cmd_name = imap_parser_read_word(cmd->client->parser); + if (cmd_name == NULL) return FALSE; - client->cmd_func = command_find(t_strconcat("UID ", cmd, NULL)); + cmd->func = command_find(t_strconcat("UID ", cmd_name, NULL)); - if (client->cmd_func != NULL) { - client->cmd_uid = TRUE; - return client->cmd_func(client); + if (cmd->func != NULL) { + cmd->uid = TRUE; + return cmd->func(cmd); } else { - client_send_tagline(client, t_strconcat( - "BAD Unknown UID command ", cmd, NULL)); + client_send_tagline(cmd, t_strconcat( + "BAD Unknown UID command ", cmd_name, NULL)); return TRUE; } }
--- a/src/imap/cmd-unselect.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-unselect.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,11 +3,12 @@ #include "common.h" #include "commands.h" -int cmd_unselect(struct client *client) +int cmd_unselect(struct client_command_context *cmd) { + struct client *client = cmd->client; struct mailbox *mailbox = client->mailbox; - if (!client_verify_open_mailbox(client)) + if (!client_verify_open_mailbox(cmd)) return TRUE; client->mailbox = NULL; @@ -17,6 +18,6 @@ mailbox_get_storage(mailbox)); } - client_send_tagline(client, "OK Unselect completed."); + client_send_tagline(cmd, "OK Unselect completed."); return TRUE; }
--- a/src/imap/cmd-unsubscribe.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/cmd-unsubscribe.c Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ #include "common.h" #include "commands.h" -int cmd_unsubscribe(struct client *client) +int cmd_unsubscribe(struct client_command_context *cmd) { - return _cmd_subscribe_full(client, FALSE); + return _cmd_subscribe_full(cmd, FALSE); }
--- a/src/imap/commands-util.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/commands-util.c Sat Feb 05 20:07:26 2005 +0200 @@ -17,19 +17,20 @@ #define MAILBOX_MAX_NAME_LEN 512 struct mail_storage * -client_find_storage(struct client *client, const char **mailbox) +client_find_storage(struct client_command_context *cmd, const char **mailbox) { struct namespace *ns; - ns = namespace_find(client->namespaces, mailbox); + ns = namespace_find(cmd->client->namespaces, mailbox); if (ns != NULL) return ns->storage; - client_send_tagline(client, "NO Unknown namespace."); + client_send_tagline(cmd, "NO Unknown namespace."); return NULL; } -int client_verify_mailbox_name(struct client *client, const char *mailbox, +int client_verify_mailbox_name(struct client_command_context *cmd, + const char *mailbox, int should_exist, int should_not_exist) { struct mail_storage *storage; @@ -37,34 +38,34 @@ const char *p; char sep; - storage = client_find_storage(client, &mailbox); + storage = client_find_storage(cmd, &mailbox); if (storage == NULL) return FALSE; /* make sure it even looks valid */ sep = mail_storage_get_hierarchy_sep(storage); if (*mailbox == '\0' || strspn(mailbox, "\r\n*%?") != 0) { - client_send_tagline(client, "NO Invalid mailbox name."); + client_send_tagline(cmd, "NO Invalid mailbox name."); return FALSE; } /* make sure two hierarchy separators aren't next to each others */ for (p = mailbox+1; *p != '\0'; p++) { if (p[0] == sep && p[1] == sep) { - client_send_tagline(client, "NO Invalid mailbox name."); + client_send_tagline(cmd, "NO Invalid mailbox name."); return FALSE; } } if (strlen(mailbox) > MAILBOX_MAX_NAME_LEN) { - client_send_tagline(client, "NO Mailbox name too long."); + client_send_tagline(cmd, "NO Mailbox name too long."); return FALSE; } /* check what our storage thinks of it */ if (mail_storage_get_mailbox_name_status(storage, mailbox, &mailbox_status) < 0) { - client_send_storage_error(client, storage); + client_send_storage_error(cmd, storage); return FALSE; } @@ -73,25 +74,25 @@ if (should_exist || !should_not_exist) return TRUE; - client_send_tagline(client, "NO Mailbox exists."); + client_send_tagline(cmd, "NO Mailbox exists."); break; case MAILBOX_NAME_VALID: if (!should_exist) return TRUE; - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "NO [TRYCREATE] Mailbox doesn't exist: ", mailbox, NULL)); break; case MAILBOX_NAME_INVALID: - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "NO Invalid mailbox name: ", mailbox, NULL)); break; case MAILBOX_NAME_NOINFERIORS: - client_send_tagline(client, + client_send_tagline(cmd, "NO Mailbox parent doesn't allow inferior mailboxes."); break; @@ -102,33 +103,33 @@ return FALSE; } -int client_verify_open_mailbox(struct client *client) +int client_verify_open_mailbox(struct client_command_context *cmd) { - if (client->mailbox != NULL) + if (cmd->client->mailbox != NULL) return TRUE; else { - client_send_tagline(client, "BAD No mailbox selected."); + client_send_tagline(cmd, "BAD No mailbox selected."); return FALSE; } } -void client_send_storage_error(struct client *client, +void client_send_storage_error(struct client_command_context *cmd, struct mail_storage *storage) { const char *error; int syntax; - if (client->mailbox != NULL && - mailbox_is_inconsistent(client->mailbox)) { + if (cmd->client->mailbox != NULL && + mailbox_is_inconsistent(cmd->client->mailbox)) { /* we can't do forced CLOSE, so have to disconnect */ - client_disconnect_with_error(client, + client_disconnect_with_error(cmd->client, "Mailbox is in inconsistent state, please relogin."); return; } error = mail_storage_get_last_error(storage, &syntax); - client_send_tagline(client, t_strconcat(syntax ? "BAD " : "NO ", - error, NULL)); + client_send_tagline(cmd, + t_strconcat(syntax ? "BAD " : "NO ", error, NULL)); } void client_send_untagged_storage_error(struct client *client, @@ -150,19 +151,21 @@ t_strconcat(syntax ? "* BAD " : "* NO ", error, NULL)); } -static int is_valid_keyword(struct client *client, const char *keyword) +static int is_valid_keyword(struct client_command_context *cmd, + const char *keyword) { + struct mailbox_keywords *keywords = &cmd->client->keywords; size_t i; /* if it already exists, skip validity checks */ - for (i = 0; i < client->keywords.keywords_count; i++) { - if (client->keywords.keywords[i] != NULL && - strcasecmp(client->keywords.keywords[i], keyword) == 0) + for (i = 0; i < keywords->keywords_count; i++) { + if (keywords->keywords[i] != NULL && + strcasecmp(keywords->keywords[i], keyword) == 0) return TRUE; } if (strlen(keyword) > max_keyword_length) { - client_send_tagline(client, + client_send_tagline(cmd, t_strdup_printf("BAD Invalid keyword name '%s': " "Maximum length is %u characters", keyword, max_keyword_length)); @@ -172,8 +175,8 @@ return TRUE; } -int client_parse_mail_flags(struct client *client, struct imap_arg *args, - enum mail_flags *flags_r, +int client_parse_mail_flags(struct client_command_context *cmd, + struct imap_arg *args, enum mail_flags *flags_r, const char *const **keywords_r) { const char *const *keywords; @@ -183,11 +186,11 @@ *flags_r = 0; *keywords_r = NULL; - buffer = buffer_create_dynamic(client->cmd_pool, 256); + buffer = buffer_create_dynamic(cmd->pool, 256); while (args->type != IMAP_ARG_EOL) { if (args->type != IMAP_ARG_ATOM) { - client_send_command_error(client, + client_send_command_error(cmd, "Flags list contains non-atoms."); return FALSE; } @@ -207,7 +210,7 @@ else if (strcmp(atom, "\\DRAFT") == 0) *flags_r |= MAIL_DRAFT; else { - client_send_tagline(client, t_strconcat( + client_send_tagline(cmd, t_strconcat( "BAD Invalid system flag ", atom, NULL)); return FALSE; @@ -222,7 +225,7 @@ } if (i == size) { - if (!is_valid_keyword(client, atom)) + if (!is_valid_keyword(cmd, atom)) return FALSE; buffer_append(buffer, &atom, sizeof(atom)); }
--- a/src/imap/commands-util.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/commands-util.h Sat Feb 05 20:07:26 2005 +0200 @@ -12,7 +12,7 @@ /* Finds mail storage for given mailbox from namespaces. If not found, sends "Unknown namespace" error message to client. */ struct mail_storage * -client_find_storage(struct client *client, const char **mailbox); +client_find_storage(struct client_command_context *cmd, const char **mailbox); /* If should_exist is TRUE, this function returns TRUE if the mailbox exists. If it doesn't exist but would be a valid mailbox name, the @@ -20,15 +20,16 @@ If should_exist is FALSE, the should_not_exist specifies if we should return TRUE or FALSE if mailbox doesn't exist. */ -int client_verify_mailbox_name(struct client *client, const char *mailbox, +int client_verify_mailbox_name(struct client_command_context *cmd, + const char *mailbox, int should_exist, int should_not_exist); /* Returns TRUE if mailbox is selected. If not, sends "No mailbox selected" error message to client. */ -int client_verify_open_mailbox(struct client *client); +int client_verify_open_mailbox(struct client_command_context *cmd); /* Send last mail storage error message to client. */ -void client_send_storage_error(struct client *client, +void client_send_storage_error(struct client_command_context *cmd, struct mail_storage *storage); /* Send untagged error message to client. */ @@ -37,8 +38,8 @@ /* Parse flags. Returns TRUE if successful, if not sends an error message to client. */ -int client_parse_mail_flags(struct client *client, struct imap_arg *args, - enum mail_flags *flags_r, +int client_parse_mail_flags(struct client_command_context *cmd, + struct imap_arg *args, enum mail_flags *flags_r, const char *const **keywords_r); /* Send FLAGS + PERMANENTFLAGS to client. */
--- a/src/imap/commands.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/commands.h Sat Feb 05 20:07:26 2005 +0200 @@ -1,14 +1,14 @@ #ifndef __COMMANDS_H #define __COMMANDS_H -struct client; +struct client_command_context; #include "mail-storage.h" #include "imap-parser.h" #include "imap-sync.h" #include "commands-util.h" -typedef int command_func_t(struct client *client); +typedef int command_func_t(struct client_command_context *cmd); struct command { const char *name; @@ -32,51 +32,51 @@ /* IMAP4rev1 commands: */ /* Non-Authenticated State */ -int cmd_authenticate(struct client *client); -int cmd_login(struct client *client); -int cmd_logout(struct client *client); +int cmd_authenticate(struct client_command_context *cmd); +int cmd_login(struct client_command_context *cmd); +int cmd_logout(struct client_command_context *cmd); -int cmd_capability(struct client *client); -int cmd_noop(struct client *client); +int cmd_capability(struct client_command_context *cmd); +int cmd_noop(struct client_command_context *cmd); /* Authenticated State */ -int cmd_select(struct client *client); -int cmd_examine(struct client *client); +int cmd_select(struct client_command_context *cmd); +int cmd_examine(struct client_command_context *cmd); -int cmd_create(struct client *client); -int cmd_delete(struct client *client); -int cmd_rename(struct client *client); +int cmd_create(struct client_command_context *cmd); +int cmd_delete(struct client_command_context *cmd); +int cmd_rename(struct client_command_context *cmd); -int cmd_subscribe(struct client *client); -int cmd_unsubscribe(struct client *client); +int cmd_subscribe(struct client_command_context *cmd); +int cmd_unsubscribe(struct client_command_context *cmd); -int cmd_list(struct client *client); -int cmd_lsub(struct client *client); +int cmd_list(struct client_command_context *cmd); +int cmd_lsub(struct client_command_context *cmd); -int cmd_status(struct client *client); -int cmd_append(struct client *client); +int cmd_status(struct client_command_context *cmd); +int cmd_append(struct client_command_context *cmd); /* Selected state */ -int cmd_check(struct client *client); -int cmd_close(struct client *client); -int cmd_expunge(struct client *client); -int cmd_search(struct client *client); -int cmd_fetch(struct client *client); -int cmd_store(struct client *client); -int cmd_copy(struct client *client); -int cmd_uid(struct client *client); +int cmd_check(struct client_command_context *cmd); +int cmd_close(struct client_command_context *cmd); +int cmd_expunge(struct client_command_context *cmd); +int cmd_search(struct client_command_context *cmd); +int cmd_fetch(struct client_command_context *cmd); +int cmd_store(struct client_command_context *cmd); +int cmd_copy(struct client_command_context *cmd); +int cmd_uid(struct client_command_context *cmd); /* IMAP extensions: */ -int cmd_idle(struct client *client); -int cmd_namespace(struct client *client); -int cmd_sort(struct client *client); -int cmd_thread(struct client *client); -int cmd_uid_expunge(struct client *client); -int cmd_unselect(struct client *client); +int cmd_idle(struct client_command_context *cmd); +int cmd_namespace(struct client_command_context *cmd); +int cmd_sort(struct client_command_context *cmd); +int cmd_thread(struct client_command_context *cmd); +int cmd_uid_expunge(struct client_command_context *cmd); +int cmd_unselect(struct client_command_context *cmd); /* private: */ -int _cmd_list_full(struct client *client, int lsub); -int _cmd_select_full(struct client *client, int readonly); -int _cmd_subscribe_full(struct client *client, int subscribe); +int _cmd_list_full(struct client_command_context *cmd, int lsub); +int _cmd_select_full(struct client_command_context *cmd, int readonly); +int _cmd_subscribe_full(struct client_command_context *cmd, int subscribe); #endif
--- a/src/imap/imap-fetch-body.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-fetch-body.c Sat Feb 05 20:07:26 2005 +0200 @@ -594,7 +594,7 @@ t_push(); for (arr = body->fields; *arr != NULL; arr++) { - char *hdr = p_strdup(ctx->client->cmd_pool, *arr); + char *hdr = p_strdup(ctx->cmd->pool, *arr); buffer_append(ctx->all_headers_buf, &hdr, sizeof(hdr)); } @@ -660,7 +660,7 @@ } } - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: Unknown or broken section"); return FALSE; } @@ -694,17 +694,17 @@ const char **arr; size_t i; - str = str_new(ctx->client->cmd_pool, 128); + str = str_new(ctx->cmd->pool, 128); str_append(str, prefix); str_append(str, " ("); /* @UNSAFE: NULL-terminated list of headers */ - arr = p_new(ctx->client->cmd_pool, const char *, list->size + 1); + arr = p_new(ctx->cmd->pool, const char *, list->size + 1); for (i = 0; i < list->size; i++) { if (list->args[i].type != IMAP_ARG_ATOM && list->args[i].type != IMAP_ARG_STRING) { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: " "Header list contains non-strings"); return FALSE; @@ -738,7 +738,7 @@ const char *partial; const char *p = name + 4; - body = p_new(ctx->client->cmd_pool, struct imap_fetch_body_data, 1); + body = p_new(ctx->cmd->pool, struct imap_fetch_body_data, 1); body->max_size = (uoff_t)-1; if (strncmp(p, ".PEEK", 5) == 0) { @@ -749,7 +749,7 @@ } if (*p != '[') { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: Missing '['"); return FALSE; } @@ -758,7 +758,7 @@ /* BODY[HEADER.FIELDS.. (headers list)] */ if ((*args)[1].type != IMAP_ARG_ATOM || IMAP_ARG_STR(&(*args)[1])[0] != ']') { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: Missing ']'"); return FALSE; } @@ -772,11 +772,11 @@ body->section = p+1; p = strchr(body->section, ']'); if (p == NULL) { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: Missing ']'"); return FALSE; } - body->section = p_strdup_until(ctx->client->cmd_pool, + body->section = p_strdup_until(ctx->cmd->pool, body->section, p); } @@ -788,7 +788,7 @@ if (!read_uoff_t(&p, &body->skip) || body->skip > OFF_T_MAX) { /* wrapped */ - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: " "Too big partial start"); return FALSE; @@ -807,7 +807,7 @@ if (!read_uoff_t(&p, &body->max_size) || body->max_size > OFF_T_MAX) { /* wrapped */ - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, "Invalid BODY[..] parameter: " "Too big partial end"); return FALSE; @@ -815,7 +815,7 @@ } if (*p != '>') { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, t_strdup_printf("Invalid BODY[..] parameter: " "Missing '>' in '%s'", partial)); @@ -947,7 +947,7 @@ return TRUE; } - client_send_command_error(ctx->client, t_strconcat( + client_send_command_error(ctx->cmd, t_strconcat( "Unknown parameter ", name, NULL)); return FALSE; }
--- a/src/imap/imap-fetch.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-fetch.c Sat Feb 05 20:07:26 2005 +0200 @@ -67,7 +67,7 @@ sizeof(struct imap_fetch_handler), imap_fetch_handler_bsearch); if (handler == NULL) { - client_send_command_error(ctx->client, + client_send_command_error(ctx->cmd, t_strconcat("Unknown command ", name, NULL)); return FALSE; } @@ -75,8 +75,9 @@ return handler->init(ctx, name, args); } -struct imap_fetch_context *imap_fetch_init(struct client *client) +struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd) { + struct client *client = cmd->client; struct imap_fetch_context *ctx; if (fetch_handlers == NULL) { @@ -85,13 +86,14 @@ sizeof(default_handlers[0])); } - ctx = p_new(client->cmd_pool, struct imap_fetch_context, 1); + ctx = p_new(cmd->pool, struct imap_fetch_context, 1); ctx->client = client; + ctx->cmd = cmd; ctx->box = client->mailbox; ctx->cur_str = str_new(default_pool, 8192); - ctx->all_headers_buf = buffer_create_dynamic(client->cmd_pool, 128); - ctx->handlers = buffer_create_dynamic(client->cmd_pool, 128); + ctx->all_headers_buf = buffer_create_dynamic(cmd->pool, 128); + ctx->handlers = buffer_create_dynamic(cmd->pool, 128); ctx->line_finished = TRUE; return ctx; }
--- a/src/imap/imap-fetch.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-fetch.h Sat Feb 05 20:07:26 2005 +0200 @@ -23,6 +23,7 @@ struct imap_fetch_context { struct client *client; + struct client_command_context *cmd; struct mailbox *box; struct mailbox_transaction_context *trans; @@ -61,7 +62,7 @@ void imap_fetch_add_handler(struct imap_fetch_context *ctx, imap_fetch_handler_t *handler, void *context); -struct imap_fetch_context *imap_fetch_init(struct client *client); +struct imap_fetch_context *imap_fetch_init(struct client_command_context *cmd); int imap_fetch_deinit(struct imap_fetch_context *ctx); int imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name, struct imap_arg **args);
--- a/src/imap/imap-search.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-search.c Sat Feb 05 20:07:26 2005 +0200 @@ -444,22 +444,23 @@ } struct mail_search_arg * -imap_search_get_arg(struct client *client, const char *set, int uid) +imap_search_get_arg(struct client_command_context *cmd, + const char *set, int uid) { struct mail_search_arg *search_arg; const char *error; int ret; if (!uid) { - ret = imap_search_get_msgset_arg(client->cmd_pool, set, + ret = imap_search_get_msgset_arg(cmd->pool, set, &search_arg, &error); } else { - ret = imap_search_get_uidset_arg(client->cmd_pool, - client->mailbox, set, + ret = imap_search_get_uidset_arg(cmd->pool, + cmd->client->mailbox, set, &search_arg, &error); } if (ret < 0) { - client_send_command_error(client, error); + client_send_command_error(cmd, error); return NULL; }
--- a/src/imap/imap-search.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-search.h Sat Feb 05 20:07:26 2005 +0200 @@ -3,7 +3,7 @@ struct imap_arg; struct mailbox; -struct client; +struct client_command_context; /* Builds search arguments based on IMAP arguments. */ struct mail_search_arg * @@ -11,6 +11,7 @@ const char **error_r); struct mail_search_arg * -imap_search_get_arg(struct client *client, const char *set, int uid); +imap_search_get_arg(struct client_command_context *cmd, + const char *set, int uid); #endif
--- a/src/imap/imap-sort.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-sort.c Sat Feb 05 20:07:26 2005 +0200 @@ -187,10 +187,11 @@ i_free(ctx->last_to); } -int imap_sort(struct client *client, const char *charset, +int imap_sort(struct client_command_context *cmd, const char *charset, struct mail_search_arg *args, const enum mail_sort_type *sort_program) { + struct client *client = cmd->client; enum mail_sort_type norm_prog[MAX_SORT_PROGRAM_SIZE]; enum mail_fetch_field wanted_fields; const char *wanted_headers[MAX_WANTED_HEADERS]; @@ -245,7 +246,7 @@ ctx->str = t_str_new(STRBUF_SIZE); str_append(ctx->str, "* SORT"); - ctx->id_is_uid = client->cmd_uid; + ctx->id_is_uid = cmd->uid; while ((mail = mailbox_search_next(ctx->search_ctx)) != NULL) mail_sort_input(ctx, mail);
--- a/src/imap/imap-sort.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-sort.h Sat Feb 05 20:07:26 2005 +0200 @@ -1,7 +1,7 @@ #ifndef __IMAP_SORT_H #define __IMAP_SORT_H -int imap_sort(struct client *client, const char *charset, +int imap_sort(struct client_command_context *cmd, const char *charset, struct mail_search_arg *args, const enum mail_sort_type *sort_program);
--- a/src/imap/imap-sync.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-sync.c Sat Feb 05 20:07:26 2005 +0200 @@ -164,38 +164,39 @@ return mailbox_sync_deinit(ctx, &status); } -static int cmd_sync_continue(struct client *client) +static int cmd_sync_continue(struct client_command_context *cmd) { - struct cmd_sync_context *ctx = client->cmd_context; + struct cmd_sync_context *ctx = cmd->context; if (imap_sync_more(ctx->sync_ctx) == 0) return FALSE; if (imap_sync_deinit(ctx->sync_ctx) < 0) { - client_send_untagged_storage_error(client, - mailbox_get_storage(client->mailbox)); + client_send_untagged_storage_error(cmd->client, + mailbox_get_storage(cmd->client->mailbox)); } - client_send_tagline(client, ctx->tagline); + client_send_tagline(cmd, ctx->tagline); return TRUE; } -int cmd_sync(struct client *client, enum mailbox_sync_flags flags, +int cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags, const char *tagline) { struct cmd_sync_context *ctx; - if (client->mailbox == NULL) { - client_send_tagline(client, tagline); + if (cmd->client->mailbox == NULL) { + client_send_tagline(cmd, tagline); return TRUE; } - ctx = p_new(client->cmd_pool, struct cmd_sync_context, 1); - ctx->tagline = p_strdup(client->cmd_pool, tagline); - ctx->sync_ctx = imap_sync_init(client, client->mailbox, flags); + ctx = p_new(cmd->pool, struct cmd_sync_context, 1); + ctx->tagline = p_strdup(cmd->pool, tagline); + ctx->sync_ctx = imap_sync_init(cmd->client, cmd->client->mailbox, + flags); - client->cmd_func = cmd_sync_continue; - client->cmd_context = ctx; - client->command_pending = TRUE; - return cmd_sync_continue(client); + cmd->func = cmd_sync_continue; + cmd->context = ctx; + cmd->client->command_pending = TRUE; + return cmd_sync_continue(cmd); }
--- a/src/imap/imap-sync.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-sync.h Sat Feb 05 20:07:26 2005 +0200 @@ -1,6 +1,8 @@ #ifndef __IMAP_SYNC_H #define __IMAP_SYNC_H +struct client; + struct imap_sync_context * imap_sync_init(struct client *client, struct mailbox *box, enum mailbox_sync_flags flags); @@ -9,7 +11,7 @@ int imap_sync_nonselected(struct mailbox *box, enum mailbox_sync_flags flags); -int cmd_sync(struct client *client, enum mailbox_sync_flags flags, +int cmd_sync(struct client_command_context *cmd, enum mailbox_sync_flags flags, const char *tagline); #endif
--- a/src/imap/imap-thread.c Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-thread.c Sat Feb 05 20:07:26 2005 +0200 @@ -100,13 +100,14 @@ pool_unref(ctx->pool); } -int imap_thread(struct client *client, const char *charset, +int imap_thread(struct client_command_context *cmd, const char *charset, struct mail_search_arg *args, enum mail_thread_type type) { static const char *wanted_headers[] = { "message-id", "in-reply-to", "references", "subject", NULL }; + struct client *client = cmd->client; struct mailbox_header_lookup_ctx *headers_ctx; struct thread_context *ctx; struct mail *mail; @@ -142,7 +143,7 @@ APPROX_MSG_COUNT*2, str_hash, (hash_cmp_callback_t *)strcmp); - ctx->id_is_uid = client->cmd_uid; + ctx->id_is_uid = cmd->uid; while ((mail = mailbox_search_next(ctx->search_ctx)) != NULL) mail_thread_input(ctx, mail);
--- a/src/imap/imap-thread.h Sat Feb 05 20:05:24 2005 +0200 +++ b/src/imap/imap-thread.h Sat Feb 05 20:07:26 2005 +0200 @@ -7,7 +7,7 @@ MAIL_THREAD_REFERENCES }; -int imap_thread(struct client *client, const char *charset, +int imap_thread(struct client_command_context *cmd, const char *charset, struct mail_search_arg *args, enum mail_thread_type type); #endif