smtp-server-private.h revision 1d4c4128808d04cf4b8396ce04ce524da9194782
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_COMMAND_POOL_MAX (8 * 1024)
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen#define SMTP_SERVER_DEFAULT_MAX_COMMAND_LINE (4 * 1024)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen#define SMTP_SERVER_DEFAULT_MAX_BAD_COMMANDS 10
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen (SMTP_CAPABILITY_SIZE | SMTP_CAPABILITY_ENHANCEDSTATUSCODES | \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen SMTP_CAPABILITY_8BITMIME | SMTP_CAPABILITY_CHUNKING)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo SirainenARRAY_DEFINE_TYPE(smtp_server_reply, struct smtp_server_reply);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* New command; callback to command start handler executing. */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* This command is being processed; command data is fully read, but no
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen reply is yet submitted */
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 /* 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 /* The reply for the command is sent */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* Request is aborted; still lingering due to references */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int status;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int index;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* replies may share content */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* private hooks */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* next: command is next to reply but has not submittted all replies yet */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* replied: command has submitted all replies */
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen /* completed: server is about to send last replies for this command */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* destroy: command is about to be destroyed */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen /* private context data */
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int pending_mail_cmds, pending_rcpt_cmds;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen struct istream *data_input, *data_chain_input;
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen const struct smtp_server_callbacks *callbacks;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_helo_data helo, *pending_helo;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen unsigned int id;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_command *command_queue_head, *command_queue_tail;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen ARRAY(struct smtp_server_command_reg) commands_reg;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstatic inline const char *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_label(struct smtp_server_command *cmd)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return "[INVALID]";
055f4599bba1874fa1148a8fa488517fa077619cTimo Sirainenstatic inline const char *
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_connection_label(struct smtp_server_connection *conn)
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenbool smtp_server_connection_pending_command_data(
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_reply_free(struct smtp_server_command *cmd);
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);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenconst char *smtp_server_reply_get_one_line(struct smtp_server_reply *reply);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_commands_init(struct smtp_server *server);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_command_debug(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_alloc(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_new(struct smtp_server_connection *conn,
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 Sirainenvoid smtp_server_command_submit_reply(struct smtp_server_command *cmd);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenint smtp_server_connection_flush(struct smtp_server_connection *conn);
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 Sirainenstatic inline bool
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_command_is_complete(struct smtp_server_command *cmd)
b29403032a7ee56c309e94d92fbf1728bacb88f4Timo Sirainen struct smtp_server_connection *conn = cmd->context.conn;
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen return (conn->input_broken || (cmd->next != NULL) || cmd->reply_early ||
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen !smtp_server_connection_pending_command_data(conn));
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 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 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);
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 Sirainenvoid smtp_server_cmd_quit(struct smtp_server_cmd_ctx *cmd,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen const char *params);
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainentypedef void smtp_server_input_callback_t(void *context);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_debug(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_error(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenstruct connection_list *smtp_server_connection_list_init(void);
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 Sirainenvoid smtp_server_connection_cork(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_uncork(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_input_halt(struct smtp_server_connection *conn);
e1b83f64e62cc3e8967c75fcc3f9b5dbb243d3b3Timo Sirainenvoid smtp_server_connection_input_resume(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 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen (smtp_server_input_callback_t *)callback, context)
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 Sirainenvoid smtp_server_connection_send_line(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen struct smtp_server_connection *conn, unsigned int status,
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 Sirainenint smtp_server_connection_ssl_init(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_clear(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_connection_get_transaction(struct smtp_server_connection *conn);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainenvoid smtp_server_connection_set_proxy_data(struct smtp_server_connection *conn,
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainen * Transaction
64510d2cc23a79d2142030bf5bade44baa490db3Timo Sirainensmtp_server_transaction_create(struct smtp_server_connection *conn,
f335accff54f408a8bbb328f8098ad458f2ff58eTimo Sirainenvoid smtp_server_transaction_free(struct smtp_server_transaction **_trans);
050975ee630c761ab237fce7b8f84fe189bb02d2Timo Sirainensmtp_server_transaction_add_rcpt(struct smtp_server_transaction *trans,