imap-commands.c revision c9b76ca218d93dc97e27d6ec04a645e8dc6f228b
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen/* Copyright (c) 2002-2015 Dovecot authors, see the included COPYING file */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstatic const struct command imap4rev1_commands[] = {
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen { "LOGOUT", cmd_logout, COMMAND_FLAG_BREAKS_MAILBOX },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "NOOP", cmd_noop, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "APPEND", cmd_append, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "EXAMINE", cmd_examine, COMMAND_FLAG_BREAKS_MAILBOX },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "DELETE", cmd_delete, COMMAND_FLAG_BREAKS_MAILBOX |
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "RENAME", cmd_rename, COMMAND_FLAG_USE_NONEXISTENT },
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen { "SELECT", cmd_select, COMMAND_FLAG_BREAKS_MAILBOX },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UNSUBSCRIBE", cmd_unsubscribe, COMMAND_FLAG_USE_NONEXISTENT },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "CHECK", cmd_check, COMMAND_FLAG_BREAKS_SEQS },
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen { "CLOSE", cmd_close, COMMAND_FLAG_BREAKS_MAILBOX },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "EXPUNGE", cmd_expunge, COMMAND_FLAG_BREAKS_SEQS },
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen { "FETCH", cmd_fetch, COMMAND_FLAG_USES_SEQS },
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen { "SEARCH", cmd_search, COMMAND_FLAG_USES_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "STORE", cmd_store, COMMAND_FLAG_USES_SEQS },
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen { "UID COPY", cmd_copy, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID FETCH", cmd_fetch, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID SEARCH", cmd_search, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID STORE", cmd_store, COMMAND_FLAG_BREAKS_SEQS }
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#define IMAP4REV1_COMMANDS_COUNT N_ELEMENTS(imap4rev1_commands)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstatic const struct command imap_ext_commands[] = {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* IMAP extensions: */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "IDLE", cmd_idle, COMMAND_FLAG_BREAKS_SEQS |
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen { "NOTIFY", cmd_notify, COMMAND_FLAG_BREAKS_SEQS },
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen { "THREAD", cmd_thread, COMMAND_FLAG_USES_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID EXPUNGE", cmd_uid_expunge, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID MOVE", cmd_move, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID SORT", cmd_sort, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UID THREAD", cmd_thread, COMMAND_FLAG_BREAKS_SEQS },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "UNSELECT", cmd_unselect, COMMAND_FLAG_BREAKS_MAILBOX },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen { "X-STATE", cmd_x_state, COMMAND_FLAG_REQUIRES_SYNC },
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* IMAP URLAUTH (RFC4467): */
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen#define IMAP_EXT_COMMANDS_COUNT N_ELEMENTS(imap_ext_commands)
6389aeec8c26b585e583c364b48ad12adf741898Timo Sirainenstatic ARRAY(struct command_hook) command_hooks;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid command_register(const char *name, command_func_t *func,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen unsigned int i, count;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen for (i = 0; i < count; i++) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen i_error("Trying to unregister unknown command '%s'", name);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenvoid command_register_array(const struct command *cmdarr, unsigned int count)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid command_unregister_array(const struct command *cmdarr, unsigned int count)
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen while (count > 0) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid command_hook_register(command_hook_callback_t *pre,
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenvoid command_hook_unregister(command_hook_callback_t *pre,
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen unsigned int i, count;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen for (i = 0; i < count; i++) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen if (hooks[i].pre == pre && hooks[i].post == post) {
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen i_panic("command_hook_unregister(): hook not registered");
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainenbool command_exec(struct client_command_context *cmd)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen uint64_t cmd_start_bytes_in, cmd_start_bytes_out;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen cmd_start_bytes_in = i_stream_get_absolute_offset(cmd->client->input);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen cmd_start_bytes_out = cmd->client->output->offset;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen timeval_diff_usecs(&ioloop_timeval, &cmd_start_timeval);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen cmd->bytes_in += i_stream_get_absolute_offset(cmd->client->input) -
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen cmd->bytes_out += cmd->client->output->offset - cmd_start_bytes_out;
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstatic int command_cmp(const struct command *c1, const struct command *c2)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstatic int command_bsearch(const char *name, const struct command *cmd)
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen return array_bsearch(&imap_commands, name, command_bsearch);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen command_register_array(imap4rev1_commands, IMAP4REV1_COMMANDS_COUNT);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen command_register_array(imap_ext_commands, IMAP_EXT_COMMANDS_COUNT);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen command_unregister_array(imap4rev1_commands, IMAP4REV1_COMMANDS_COUNT);