smtp-server-private.h revision 1d4c4128808d04cf4b8396ce04ce524da9194782
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#ifndef SMTP_SERVER_PRIVATE_H
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_PRIVATE_H
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#include "connection.h"
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen#include "smtp-server.h"
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_COMMAND_POOL_MAX (8 * 1024)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen#define SMTP_SERVER_DEFAULT_MAX_COMMAND_LINE (4 * 1024)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_DEFAULT_MAX_BAD_COMMANDS 10
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_DEFAULT_CAPABILITIES \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen (SMTP_CAPABILITY_SIZE | SMTP_CAPABILITY_ENHANCEDSTATUSCODES | \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_CAPABILITY_8BITMIME | SMTP_CAPABILITY_CHUNKING)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_reply;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_command;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_connection;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo SirainenARRAY_DEFINE_TYPE(smtp_server_reply, struct smtp_server_reply);
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainen
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainenenum smtp_server_command_state {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* New command; callback to command start handler executing. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_NEW = 0,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* This command is being processed; command data is fully read, but no
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen reply is yet submitted */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_PROCESSING,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* A reply is submitted for this command. If not all command data was
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainen read by the handler, it is first skipped on the input. If this is a
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainen multi-reply command (LMTP->DATA), not all replies may be submitted
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen yet. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_SUBMITTED_REPLY,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* Request is ready for sending reply; a reply is submitted and the
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen command payload is fully read. If this is a multi-reply command
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen (LMTP->DATA), not all replies may be submitted yet. In that case the
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen command state goes back to PROCESSING once the all submitted replies
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen are sent. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_READY_TO_REPLY,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* The reply for the command is sent */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_FINISHED,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* Request is aborted; still lingering due to references */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_SERVER_COMMAND_STATE_ABORTED
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen};
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_reply_content {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int status;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *status_prefix;
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen string_t *text;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen size_t last_line;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen};
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainenstruct smtp_server_reply {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_command *command;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int index;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* replies may share content */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_reply_content *content;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool submitted:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool sent:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen};
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_command_reg {
c69a255a68103a50fa3f04a527281a169075403fTimo Sirainen const char *name;
c69a255a68103a50fa3f04a527281a169075403fTimo Sirainen enum smtp_server_command_flags flags;
c69a255a68103a50fa3f04a527281a169075403fTimo Sirainen smtp_server_cmd_start_func_t *func;
0f66f12eb4cdbf47670975044c88d8f388bf92dfTimo Sirainen};
0f66f12eb4cdbf47670975044c88d8f388bf92dfTimo Sirainen
c69a255a68103a50fa3f04a527281a169075403fTimo Sirainenstruct smtp_server_command {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_cmd_ctx context;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_server_command_reg *reg;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int refcount;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen enum smtp_server_command_state state;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct smtp_server_command *prev, *next;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen ARRAY_TYPE(smtp_server_reply) replies;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int replies_expected;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int replies_submitted;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* private hooks */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* next: command is next to reply but has not submittted all replies yet */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen smtp_server_cmd_func_t *hook_next;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* replied: command has submitted all replies */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen smtp_server_cmd_func_t *hook_replied;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* completed: server is about to send last replies for this command */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen smtp_server_cmd_func_t *hook_completed;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* destroy: command is about to be destroyed */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen smtp_server_cmd_func_t *hook_destroy;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* private context data */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen void *data;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen bool input_locked:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool input_captured:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool reply_early:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen};
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_state_data {
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen enum smtp_server_state state;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen time_t timestamp;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int pending_mail_cmds, pending_rcpt_cmds;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_transaction *trans;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct istream *data_input, *data_chain_input;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct istream_chain *data_chain;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int data_chunks;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen bool data_failed:1;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen};
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainenstruct smtp_server_connection {
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct connection conn;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct smtp_server *server;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen pool_t pool;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int refcount;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct smtp_server_settings set;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen const struct smtp_server_callbacks *callbacks;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen void *context;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int socket_family;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct ip_addr remote_ip;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen in_port_t remote_port;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen pid_t remote_pid;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen uid_t remote_uid;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen enum smtp_proxy_protocol proxy_proto;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen unsigned int proxy_ttl_plus_1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int proxy_timeout_secs;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_helo_data helo, *pending_helo;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen char *helo_domain, *helo_login, *username;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int id;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct timeout *to_idle;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct istream *raw_input;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen struct ostream *raw_output;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen struct ssl_iostream *ssl_iostream;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_command_parser *smtp_parser;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_command *command_queue_head, *command_queue_tail;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int command_queue_count;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int bad_counter;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen char *disconnect_reason;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_state_data state;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct smtp_server_stats stats;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool started:1;
72388282bf6718c39af34cfcf51438910f9d62daTimo Sirainen bool halted:1;
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen bool ssl_start:1;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen bool ssl_secured:1;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen bool authenticated:1;
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen bool created_from_streams:1;
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen bool corked:1;
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen bool disconnected:1;
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen bool closing:1;
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen bool closed:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool input_broken:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool input_locked:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool handling_input:1;
0ce8f754204c7eeb33805993807393f74faf2cd3Timo Sirainen bool rawlog_checked:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool rawlog_enabled:1;
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen};
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenstruct smtp_server {
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen pool_t pool;
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_settings set;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct ioloop *ioloop;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen ARRAY(struct smtp_server_command_reg) commands_reg;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct connection_list *conn_list;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen bool commands_unsorted:1;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen};
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstatic inline const char *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_label(struct smtp_server_command *cmd)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen{
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen if (cmd->context.name == NULL)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return "[INVALID]";
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return cmd->context.name;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen}
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
055f4599bba1874fa1148a8fa488517fa077619cTimo Sirainenstatic inline const char *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_connection_label(struct smtp_server_connection *conn)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen{
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return conn->conn.name;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen}
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenbool smtp_server_connection_pending_command_data(
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen/*
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen * Reply
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_reply_free(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint smtp_server_reply_send(struct smtp_server_reply *resp,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char **error_r);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint smtp_server_reply_send_more(struct smtp_server_reply *resp,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char **error_r);
e619ecbbc00cba9e6e1e8322caa59776507fac02Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenconst char *smtp_server_reply_get_one_line(struct smtp_server_reply *reply);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
cdeab2b97792dfa0691e39cd46462b28cfcb9a66Timo Sirainen/*
cdeab2b97792dfa0691e39cd46462b28cfcb9a66Timo Sirainen * Command
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainen */
cdeab2b97792dfa0691e39cd46462b28cfcb9a66Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_commands_init(struct smtp_server *server);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_debug(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *format, ...) ATTR_FORMAT(2, 3);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_command *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_alloc(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_command *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_new(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *name, const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_ref(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenbool smtp_server_command_unref(struct smtp_server_command **_cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_abort(struct smtp_server_command **_cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_submit_reply(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint smtp_server_connection_flush(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_ready_to_reply(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_next_to_reply(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_completed(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_finished(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstatic inline bool
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_is_complete(struct smtp_server_command *cmd)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen{
b29403032a7ee56c309e94d92fbf1728bacb88f4Timo Sirainen struct smtp_server_connection *conn = cmd->context.conn;
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return (conn->input_broken || (cmd->next != NULL) || cmd->reply_early ||
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen !smtp_server_connection_pending_command_data(conn));
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainen}
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_ehlo(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_helo(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_xclient(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_starttls(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_auth(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_mail(struct smtp_server_cmd_ctx *cmd,
b29403032a7ee56c309e94d92fbf1728bacb88f4Timo Sirainen const char *params);
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainenvoid smtp_server_cmd_rcpt(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
e619ecbbc00cba9e6e1e8322caa59776507fac02Timo Sirainenvoid smtp_server_cmd_data(struct smtp_server_cmd_ctx *cmd,
e619ecbbc00cba9e6e1e8322caa59776507fac02Timo Sirainen const char *params);
e619ecbbc00cba9e6e1e8322caa59776507fac02Timo Sirainenvoid smtp_server_cmd_bdat(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_rset(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
e619ecbbc00cba9e6e1e8322caa59776507fac02Timo Sirainenvoid smtp_server_cmd_noop(struct smtp_server_cmd_ctx *cmd,
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainen const char *params);
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainenvoid smtp_server_cmd_vrfy(struct smtp_server_cmd_ctx *cmd,
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_cmd_quit(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen/*
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen * Connection
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainentypedef void smtp_server_input_callback_t(void *context);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_debug(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *format, ...) ATTR_FORMAT(2, 3);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_error(struct smtp_server_connection *conn,
b29403032a7ee56c309e94d92fbf1728bacb88f4Timo Sirainen const char *format, ...) ATTR_FORMAT(2, 3);
b29403032a7ee56c309e94d92fbf1728bacb88f4Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct connection_list *smtp_server_connection_list_init(void);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
919733fcead68b0e9617cfff86ae5c74d097c6cdTimo Sirainenvoid smtp_server_connection_switch_ioloop(struct smtp_server_connection *conn);
345253fb28498b2e0a60f4a2a8644c65feee7e75Timo Sirainenvoid smtp_server_connection_trigger_output(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenbool smtp_server_connection_pending_payload(struct smtp_server_connection *conn);
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainen
65988f5a8abed57e9894fec77105941e046d3490Timo Sirainenvoid smtp_server_connection_cork(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_uncork(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_input_halt(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_input_resume(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_input_capture(
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainen struct smtp_server_connection *conn,
919733fcead68b0e9617cfff86ae5c74d097c6cdTimo Sirainen smtp_server_input_callback_t *callback, void *context);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define smtp_server_connection_input_capture(conn, callback, context) \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen smtp_server_connection_input_capture(conn + \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen (smtp_server_input_callback_t *)callback, context)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_timeout_stop(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_timeout_start(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_timeout_reset(struct smtp_server_connection *conn);
055f4599bba1874fa1148a8fa488517fa077619cTimo Sirainen
055f4599bba1874fa1148a8fa488517fa077619cTimo Sirainenvoid smtp_server_connection_send_line(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_reply_immediate(
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_connection *conn, unsigned int status,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *fmt, ...) ATTR_FORMAT(3, 4);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_reset_state(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_set_state(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen enum smtp_server_state state);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint smtp_server_connection_ssl_init(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_clear(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_transaction *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_connection_get_transaction(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_set_proxy_data(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_proxy_data *proxy_data);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainen/*
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen * Transaction
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_transaction *
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainensmtp_server_transaction_create(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_address *mail_from,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_params_mail *params,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct timeval *timestamp);
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainenvoid smtp_server_transaction_free(struct smtp_server_transaction **_trans);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct smtp_server_recipient *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_transaction_add_rcpt(struct smtp_server_transaction *trans,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_address *rcpt_to,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const struct smtp_params_rcpt *params);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenbool smtp_server_transaction_has_rcpt(struct smtp_server_transaction *trans);
unsigned int
smtp_server_transaction_rcpt_count(struct smtp_server_transaction *trans);
#endif