imap-commands.c revision 5735ada0f82788ee1b5228978d5bd8dad5a04219
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenstatic const struct command imap4rev1_commands[] = {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen { "LOGOUT", cmd_logout, COMMAND_FLAG_BREAKS_MAILBOX },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "NOOP", cmd_noop, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "APPEND", cmd_append, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "EXAMINE", cmd_examine, COMMAND_FLAG_BREAKS_MAILBOX },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "SELECT", cmd_select, COMMAND_FLAG_BREAKS_MAILBOX },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "CHECK", cmd_check, COMMAND_FLAG_BREAKS_SEQS },
714e2da5096fb52b8845d3c79f9bb26225a606c9Timo Sirainen { "CLOSE", cmd_close, COMMAND_FLAG_BREAKS_MAILBOX },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "EXPUNGE", cmd_expunge, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "FETCH", cmd_fetch, COMMAND_FLAG_USES_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "SEARCH", cmd_search, COMMAND_FLAG_USES_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "STORE", cmd_store, COMMAND_FLAG_USES_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UID COPY", cmd_copy, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UID FETCH", cmd_fetch, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UID SEARCH", cmd_search, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UID STORE", cmd_store, COMMAND_FLAG_BREAKS_SEQS }
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define IMAP4REV1_COMMANDS_COUNT N_ELEMENTS(imap4rev1_commands)
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenstatic const struct command imap_ext_commands[] = {
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "IDLE", cmd_idle, COMMAND_FLAG_BREAKS_SEQS |
15a07b47846c47a81d69a14d649564e222d6f742Timo Sirainen { "THREAD", cmd_thread, COMMAND_FLAG_USES_SEQS },
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen { "UID EXPUNGE", cmd_uid_expunge, COMMAND_FLAG_BREAKS_SEQS },
6882df5fbca4a09cdaa95f54d70bb31b5920528cTimo Sirainen { "UID SORT", cmd_sort, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UID THREAD", cmd_thread, COMMAND_FLAG_BREAKS_SEQS },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen { "UNSELECT", cmd_unselect, COMMAND_FLAG_BREAKS_MAILBOX },
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen#define IMAP_EXT_COMMANDS_COUNT N_ELEMENTS(imap_ext_commands)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenvoid command_register(const char *name, command_func_t *func,
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen unsigned int i, count;
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen for (i = 0; i < count; i++) {
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen i_error("Trying to unregister unknown command '%s'", name);
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenvoid command_register_array(const struct command *cmdarr, unsigned int count)
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenvoid command_unregister_array(const struct command *cmdarr, unsigned int count)
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen while (count > 0) {
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenstatic int command_cmp(const void *p1, const void *p2)
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainenstatic int command_bsearch(const void *name, const void *cmd_p)
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen unsigned int count;
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen base = array_get_modifiable(&imap_commands, &count);
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen qsort(base, count, sizeof(struct command), command_cmp);
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen return bsearch(name, base, count, sizeof(struct command),
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen command_register_array(imap4rev1_commands, IMAP4REV1_COMMANDS_COUNT);
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen command_register_array(imap_ext_commands, IMAP_EXT_COMMANDS_COUNT);
02a54da28f376dd66d7939d8546a196a0045b486Timo Sirainen command_unregister_array(imap4rev1_commands, IMAP4REV1_COMMANDS_COUNT);