From: Stephan Bosch Date: Sat, 13 Jan 2018 12:25:01 +0000 (+0100) Subject: lmtp: Move common recipient handling code to separate file. X-Git-Tag: 2.3.1~211 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e365ad475aac50e991ddfb4b5e1e7835702c253d;p=thirdparty%2Fdovecot%2Fcore.git lmtp: Move common recipient handling code to separate file. --- diff --git a/src/lmtp/Makefile.am b/src/lmtp/Makefile.am index 7bab76413d..08c674da53 100644 --- a/src/lmtp/Makefile.am +++ b/src/lmtp/Makefile.am @@ -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 diff --git a/src/lmtp/client.h b/src/lmtp/client.h index 396d81ddc4..ff5bf6ec4b 100644 --- a/src/lmtp/client.h +++ b/src/lmtp/client.h @@ -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 index 0000000000..e3e34bf5b5 --- /dev/null +++ b/src/lmtp/lmtp-common.c @@ -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 index 0000000000..11db05b5e6 --- /dev/null +++ b/src/lmtp/lmtp-common.h @@ -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 diff --git a/src/lmtp/lmtp-local.c b/src/lmtp/lmtp-local.c index 0c051cff50..f4c7de03aa 100644 --- a/src/lmtp/lmtp-local.c +++ b/src/lmtp/lmtp-local.c @@ -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); diff --git a/src/lmtp/lmtp-proxy.c b/src/lmtp/lmtp-proxy.c index 662b24569f..46256a3f22 100644 --- a/src/lmtp/lmtp-proxy.c +++ b/src/lmtp/lmtp-proxy.c @@ -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;