]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: Implement client vfuncs for all normal SMTP commands.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 15 Sep 2018 19:47:42 +0000 (21:47 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:40:54 +0000 (15:40 +0200)
src/submission/submission-client.c
src/submission/submission-client.h
src/submission/submission-commands.c
src/submission/submission-commands.h

index e01a86134558ec4a4c6708d45b772adb8d30b4b7..474f74223d97ed8894954c58751dda41d1e2f77a 100644 (file)
@@ -520,4 +520,16 @@ static const struct smtp_server_callbacks smtp_callbacks = {
 
 static const struct submission_client_vfuncs submission_client_vfuncs = {
        client_default_destroy,
+
+       .cmd_helo = client_default_cmd_helo,
+
+       .cmd_mail = client_default_cmd_mail,
+       .cmd_rcpt = client_default_cmd_rcpt,
+       .cmd_rset = client_default_cmd_rset,
+       .cmd_data = client_default_cmd_data,
+
+       .cmd_vrfy = client_default_cmd_vrfy,
+
+       .cmd_noop = client_default_cmd_noop,
+       .cmd_quit = client_default_cmd_quit,
 };
index 98fb9d1242be9d8642d1867552f7426903627d26..8329d4700b73d70ff813f9e20385f740f9fced52 100644 (file)
@@ -20,6 +20,27 @@ struct client_state {
 struct submission_client_vfuncs {
        void (*destroy)(struct client *client, const char *prefix,
                        const char *reason);
+
+       int (*cmd_helo)(struct client *client, struct smtp_server_cmd_ctx *cmd,
+                       struct smtp_server_cmd_helo *data);
+
+       int (*cmd_mail)(struct client *client, struct smtp_server_cmd_ctx *cmd,
+                       struct smtp_server_cmd_mail *data);
+       int (*cmd_rcpt)(struct client *client,
+                       struct submission_recipient *rcpt,
+                       struct smtp_server_cmd_ctx *cmd,
+                       struct smtp_server_cmd_rcpt *data);
+       int (*cmd_rset)(struct client *client, struct smtp_server_cmd_ctx *cmd);
+       int (*cmd_data)(struct client *client,
+                       struct smtp_server_cmd_ctx *cmd,
+                       struct smtp_server_transaction *trans,
+                       struct istream *data_input, uoff_t data_size);
+
+       int (*cmd_vrfy)(struct client *client, struct smtp_server_cmd_ctx *cmd,
+                       const char *param);
+
+       int (*cmd_noop)(struct client *client, struct smtp_server_cmd_ctx *cmd);
+       int (*cmd_quit)(struct client *client, struct smtp_server_cmd_ctx *cmd);
 };
 
 struct client {
index 865c5251ed06f98b34a5f363907e1e76abd34f55..cbf3bab980779bebe8eab12867175e028c55f94d 100644 (file)
@@ -82,16 +82,22 @@ int cmd_helo(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
 
        if (!data->first ||
            smtp_server_connection_get_state(client->conn)
-               >= SMTP_SERVER_STATE_READY) {
-               return submission_backend_cmd_helo(client->backend_default,
-                                                  cmd, data);
-       }
+               >= SMTP_SERVER_STATE_READY)
+               return client->v.cmd_helo(client, cmd, data);
 
        /* respond right away */
        submission_helo_reply_submit(cmd, data);
        return 1;
 }
 
+int client_default_cmd_helo(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_helo *data)
+{
+       return submission_backend_cmd_helo(client->backend_default, cmd, data);
+}
+
+
 /*
  * MAIL command
  */
@@ -103,6 +109,13 @@ int cmd_mail(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
 
        client->state.backend = client->backend_default;
 
+       return client->v.cmd_mail(client, cmd, data);
+}
+
+int client_default_cmd_mail(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_mail *data)
+{
        return submission_backend_cmd_mail(client->state.backend, cmd, data);
 }
 
@@ -136,7 +149,6 @@ int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             struct smtp_server_cmd_rcpt *data)
 {
        struct client *client = conn_ctx;
-       struct smtp_server_transaction *trans;
        struct submission_recipient *rcpt;
 
        rcpt = submission_recipient_create(client, data->path);
@@ -147,6 +159,16 @@ int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
        data->trans_context = rcpt;
        data->hook_finished = submission_rcpt_finished;
 
+       return client->v.cmd_rcpt(client, rcpt, cmd, data);
+}
+
+int client_default_cmd_rcpt(struct client *client ATTR_UNUSED,
+                           struct submission_recipient *rcpt,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_rcpt *data)
+{
+       struct smtp_server_transaction *trans;
+
        trans = smtp_server_connection_get_transaction(cmd->conn);
        if (trans != NULL)
                submission_backend_trans_start(rcpt->backend, trans);
@@ -161,6 +183,13 @@ int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
 int cmd_rset(void *conn_ctx, struct smtp_server_cmd_ctx *cmd)
 {
        struct client *client = conn_ctx;
+
+       return client->v.cmd_rset(client, cmd);
+}
+
+int client_default_cmd_rset(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd)
+{
        struct submission_backend *backend = client->state.backend;
 
        if (backend == NULL)
@@ -221,8 +250,7 @@ int cmd_data_continue(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
        i_stream_unref(&inputs[0]);
        i_stream_unref(&inputs[1]);
 
-       ret = submission_backends_cmd_data(client, cmd, trans,
-                                          data_input, data_size);
+       ret = client->v.cmd_data(client, cmd, trans, data_input, data_size);
 
        i_stream_unref(&data_input);
        return ret;
@@ -247,6 +275,15 @@ int cmd_data_begin(void *conn_ctx,
        return 0;
 }
 
+int client_default_cmd_data(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_transaction *trans,
+                           struct istream *data_input, uoff_t data_size)
+{
+       return submission_backends_cmd_data(client, cmd, trans,
+                                           data_input, data_size);
+}
+
 /*
  * BURL command
  */
@@ -472,6 +509,12 @@ int cmd_vrfy(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
 {
        struct client *client = conn_ctx;
 
+       return client->v.cmd_vrfy(client, cmd, param);
+}
+
+int client_default_cmd_vrfy(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd, const char *param)
+{
        return submission_backend_cmd_vrfy(client->backend_default, cmd, param);
 }
 
@@ -483,6 +526,12 @@ int cmd_noop(void *conn_ctx, struct smtp_server_cmd_ctx *cmd)
 {
        struct client *client = conn_ctx;
 
+       return client->v.cmd_noop(client, cmd);
+}
+
+int client_default_cmd_noop(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd)
+{
        return submission_backend_cmd_noop(client->backend_default, cmd);
 }
 
@@ -528,6 +577,13 @@ int cmd_quit(void *conn_ctx, struct smtp_server_cmd_ctx *cmd)
        smtp_server_command_add_hook(cmd->cmd, SMTP_SERVER_COMMAND_HOOK_NEXT,
                                     cmd_quit_next, quit_cmd);
 
+       return client->v.cmd_quit(client, cmd);
+}
+
+int client_default_cmd_quit(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd)
+{
        return submission_backend_cmd_quit(client->backend_default, cmd);
 }
 
+
index 6bb1af5b30896f3e58a9445bf65ba8f94d7b5983..c54e689beac34ec10a17449f54e39bf7e40706f4 100644 (file)
@@ -1,28 +1,99 @@
 #ifndef SUBMISSION_COMMANDS_H
 #define SUBMISSION_COMMANDS_H
 
+/*
+ * HELO command
+ */
+
 void submission_helo_reply_submit(struct smtp_server_cmd_ctx *cmd,
                                  struct smtp_server_cmd_helo *data);
+
 int cmd_helo(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             struct smtp_server_cmd_helo *data);
 
+int client_default_cmd_helo(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_helo *data);
+
+/*
+ * MAIL command
+ */
+
 int cmd_mail(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             struct smtp_server_cmd_mail *data);
+
+int client_default_cmd_mail(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_mail *data);
+
+/*
+ * RCPT command
+ */
+
 int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             struct smtp_server_cmd_rcpt *data);
+
+int client_default_cmd_rcpt(struct client *client ATTR_UNUSED,
+                           struct submission_recipient *rcpt,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_cmd_rcpt *data);
+
+/*
+ * RSET command
+ */
+
 int cmd_rset(void *conn_ctx, struct smtp_server_cmd_ctx *cmd);
 
+int client_default_cmd_rset(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd);
+
+/*
+ * DATA/BDAT commands
+ */
+
 int cmd_data_begin(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
                   struct smtp_server_transaction *trans,
                   struct istream *data_input);
 int cmd_data_continue(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
                      struct smtp_server_transaction *trans);
+
+int client_default_cmd_data(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd,
+                           struct smtp_server_transaction *trans,
+                           struct istream *data_input, uoff_t data_size);
+
+/*
+ * BURL command
+ */
+
 void cmd_burl(struct smtp_server_cmd_ctx *cmd, const char *params);
 
+/*
+ * VRFY command
+ */
+
 int cmd_vrfy(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             const char *param);
 
+int client_default_cmd_vrfy(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd, const char *param);
+
+/*
+ * NOOP command
+ */
+
 int cmd_noop(void *conn_ctx, struct smtp_server_cmd_ctx *cmd);
+
+int client_default_cmd_noop(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd);
+
+/*
+ * QUIT command
+ */
+
 int cmd_quit(void *conn_ctx, struct smtp_server_cmd_ctx *cmd);
 
+int client_default_cmd_quit(struct client *client,
+                           struct smtp_server_cmd_ctx *cmd);
+
 #endif