]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Move common recipient handling code to separate file.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 13 Jan 2018 12:25:01 +0000 (13:25 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 6 Mar 2018 04:44:46 +0000 (06:44 +0200)
src/lmtp/Makefile.am
src/lmtp/client.h
src/lmtp/lmtp-common.c [new file with mode: 0644]
src/lmtp/lmtp-common.h [new file with mode: 0644]
src/lmtp/lmtp-local.c
src/lmtp/lmtp-proxy.c

index 7bab76413d1716c423d17fb4bec869af4f19274f..08c674da53ca9da192f1381a51884e72a865518e 100644 (file)
@@ -34,6 +34,7 @@ lmtp_SOURCES = \
        main.c \
        client.c \
        commands.c \
+       lmtp-common.c \
        lmtp-local.c \
        lmtp-proxy.c \
        lmtp-settings.c
@@ -42,6 +43,7 @@ noinst_HEADERS = \
        main.h \
        client.h \
        commands.h \
+       lmtp-common.h \
        lmtp-local.h \
        lmtp-proxy.h \
        lmtp-settings.h
index 396d81ddc44acb0fedc96ac7e0fb661482941bd9..ff5bf6ec4bcced97b7c0f6462a240c1933e8839b 100644 (file)
@@ -6,15 +6,6 @@
 
 #define CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE (1024*128)
 
-struct lmtp_recipient {
-       struct client *client;
-
-       struct smtp_address *path;
-       struct smtp_server_cmd_ctx *rcpt_cmd;
-       struct smtp_server_recipient *rcpt;
-       unsigned int index;
-};
-
 struct client_state {
        const char *name;
        unsigned int session_id_seq;
diff --git a/src/lmtp/lmtp-common.c b/src/lmtp/lmtp-common.c
new file mode 100644 (file)
index 0000000..e3e34bf
--- /dev/null
@@ -0,0 +1,26 @@
+/* Copyright (c) 2018 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "smtp-server.h"
+#include "lmtp-common.h"
+
+void lmtp_recipient_init(struct lmtp_recipient *rcpt,
+                        struct client *client,
+                        struct smtp_server_cmd_ctx *cmd,
+                        struct smtp_server_cmd_rcpt *data)
+{
+       rcpt->client = client;
+       rcpt->rcpt_cmd = cmd;
+       rcpt->path = data->path;
+}
+
+void lmtp_recipient_finish(struct lmtp_recipient *rcpt,
+                          struct smtp_server_recipient *trcpt,
+                          unsigned int index)
+{
+       trcpt->context = rcpt;
+
+       rcpt->rcpt = trcpt;
+       rcpt->index = index;
+       rcpt->rcpt_cmd = NULL;
+}
diff --git a/src/lmtp/lmtp-common.h b/src/lmtp/lmtp-common.h
new file mode 100644 (file)
index 0000000..11db05b
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef LMTP_COMMON_H
+#define LMTP_COMMON_H
+
+struct smtp_address;
+struct smtp_server_cmd_ctx;
+struct smtp_server_cmd_rcpt;
+struct smtp_server_recipient;
+struct client;
+
+struct lmtp_recipient {
+       struct client *client;
+
+       struct smtp_address *path;
+       struct smtp_server_cmd_ctx *rcpt_cmd;
+       struct smtp_server_recipient *rcpt;
+       unsigned int index;
+};
+
+void lmtp_recipient_init(struct lmtp_recipient *rcpt,
+                        struct client *client,
+                        struct smtp_server_cmd_ctx *cmd,
+                        struct smtp_server_cmd_rcpt *data);
+
+void lmtp_recipient_finish(struct lmtp_recipient *rcpt,
+                          struct smtp_server_recipient *trcpt,
+                          unsigned int index);
+
+#endif
index 0c051cff500444da8e5a9cb2dd3d42028036f627..f4c7de03aac2a76e35af7c26b649362da7f42b2a 100644 (file)
@@ -28,6 +28,7 @@
 #include "lmtp-settings.h"
 #include "client.h"
 #include "main.h"
+#include "lmtp-common.h"
 #include "lmtp-settings.h"
 #include "lmtp-local.h"
 
@@ -271,14 +272,10 @@ static void lmtp_local_rcpt_finished(
                return;
        }
 
-       trcpt->context = (void *)rcpt;
+       lmtp_recipient_finish(&rcpt->rcpt, trcpt, index);
 
        /* add to local recipients */
        array_append(&client->local->rcpt_to, &rcpt, 1);
-
-       rcpt->rcpt.rcpt = trcpt;
-       rcpt->rcpt.index = index;
-       rcpt->rcpt.rcpt_cmd = NULL;
 }
 
 static bool
@@ -388,9 +385,8 @@ int lmtp_local_rcpt(struct client *client,
                client->local = lmtp_local_init(client);
 
        rcpt = i_new(struct lmtp_local_recipient, 1);
-       rcpt->rcpt.client = client;
-       rcpt->rcpt.path = data->path;
-       rcpt->rcpt.rcpt_cmd = cmd;
+       lmtp_recipient_init(&rcpt->rcpt, client, cmd, data);
+
        rcpt->detail = i_strdup(detail);
        rcpt->service_user = service_user;
        rcpt->session_id = i_strdup(session_id);
index 662b24569f92456a76710d2b966f9338c29cfb8b..46256a3f223981257e9d8e814a44c8ca61c8d008 100644 (file)
@@ -22,6 +22,7 @@
 #include "lda-settings.h"
 #include "client.h"
 #include "main.h"
+#include "lmtp-common.h"
 #include "lmtp-settings.h"
 #include "lmtp-proxy.h"
 
@@ -384,15 +385,10 @@ lmtp_proxy_rcpt_finished(struct smtp_server_cmd_ctx *cmd,
 
        cmd->hook_destroy = NULL;
 
-       /* copy to transaction */
-       trcpt->context = (void *)rcpt;
+       lmtp_recipient_finish(&rcpt->rcpt, trcpt, index);
 
        /* add to local recipients */
        array_append(&client->proxy->rcpt_to, &rcpt, 1);
-
-       rcpt->rcpt.rcpt = trcpt;
-       rcpt->rcpt.index = index;
-       rcpt->rcpt.rcpt_cmd = NULL;
 }
 
 static void
@@ -526,9 +522,8 @@ int lmtp_proxy_rcpt(struct client *client,
        pool_unref(&auth_pool);
 
        rcpt = i_new(struct lmtp_proxy_recipient, 1);
-       rcpt->rcpt.client = client;
-       rcpt->rcpt.rcpt_cmd = cmd;
-       rcpt->rcpt.path = data->path;
+       lmtp_recipient_init(&rcpt->rcpt, client, cmd, data);
+
        rcpt->conn = conn;
 
        cmd->context = (void*)rcpt;