]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: smtp-server-command - Allow overriding commands.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 27 Jan 2021 01:21:50 +0000 (02:21 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 5 Nov 2021 06:49:45 +0000 (06:49 +0000)
src/lib-smtp/smtp-server-command.c
src/lib-smtp/smtp-server.h

index 3972fc4639b675e528d10265f6df8dedfe8bbc91..ed4b0258bed076903cfbddfafad1f60246c9e282 100644 (file)
@@ -26,8 +26,9 @@ void smtp_server_command_register(struct smtp_server *server, const char *name,
        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;
@@ -36,13 +37,29 @@ void smtp_server_command_unregister(struct smtp_server *server,
        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)
index 5c8bb5ff56603b751c0a55e787493eac37942065..e6291f9a037d74dae832a8b7ff2d37521e091426 100644 (file)
@@ -589,13 +589,17 @@ void smtp_server_command_remove_hook(struct smtp_server_command *cmd,
 
 /* 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);