server->commands_unsorted = TRUE;
}
-void smtp_server_command_unregister(struct smtp_server *server,
- const char *name)
+static bool ATTR_NOWARN_UNUSED_RESULT
+smtp_server_command_do_unregister(struct smtp_server *server,
+ const char *name)
{
const struct smtp_server_command_reg *cmd;
unsigned int i, count;
for (i = 0; i < count; i++) {
if (strcasecmp(cmd[i].name, name) == 0) {
array_delete(&server->commands_reg, i, 1);
- return;
+ return TRUE;
}
}
+ return FALSE;
+}
+
+void smtp_server_command_unregister(struct smtp_server *server,
+ const char *name)
+{
+ if (smtp_server_command_do_unregister(server, name))
+ return;
i_panic("smtp-server: Trying to unregister unknown command '%s'", name);
}
+void smtp_server_command_override(struct smtp_server *server, const char *name,
+ smtp_server_cmd_start_func_t *func,
+ enum smtp_server_command_flags flags)
+{
+ smtp_server_command_do_unregister(server, name);
+ smtp_server_command_register(server, name, func, flags);
+}
+
static int
smtp_server_command_cmp(const struct smtp_server_command_reg *c1,
const struct smtp_server_command_reg *c2)
/* The core SMTP commands are pre-registered. Special connection callbacks are
provided for the core SMTP commands. Only use this command registration API
- when custom/extension SMTP commands are required.
+ when custom/extension SMTP commands are required. It is also possible to
+ completely override the default implementations.
*/
void smtp_server_command_register(struct smtp_server *server, const char *name,
smtp_server_cmd_start_func_t *func,
enum smtp_server_command_flags);
void smtp_server_command_unregister(struct smtp_server *server,
const char *name);
+void smtp_server_command_override(struct smtp_server *server, const char *name,
+ smtp_server_cmd_start_func_t *func,
+ enum smtp_server_command_flags flags);
void smtp_server_command_set_reply_count(struct smtp_server_command *cmd,
unsigned int count);