2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#include "lib.h"
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch#include "smtp-server-private.h"
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch/* QUIT command */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Boschvoid smtp_server_cmd_quit(struct smtp_server_cmd_ctx *cmd,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const char *params)
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch{
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct smtp_server_connection *conn = cmd->conn;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch struct smtp_server_command *command = cmd->cmd;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch const struct smtp_server_callbacks *callbacks = conn->callbacks;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch int ret;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* "QUIT" CRLF */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch if (*params != '\0') {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_reply(cmd,
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch 501, "5.5.4", "Invalid parameters");
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch return;
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch }
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_connection_input_halt(conn);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_command_ref(command);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch if (callbacks != NULL && callbacks->conn_cmd_quit != NULL) {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* specific implementation of QUIT command */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch if ((ret=callbacks->conn_cmd_quit(conn->context, cmd)) <= 0) {
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch i_assert(ret == 0 ||
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_command_is_replied(command));
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch /* command is waiting for external event or it failed */
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch smtp_server_command_unref(&command);
2cbbe9b4829adb184c83dbf780316f4144559054Stephan Bosch return;
}
}
if (!smtp_server_command_is_replied(command)) {
/* set generic QUIT success reply if none is provided */
smtp_server_reply_quit(cmd);
}
smtp_server_command_unref(&command);
}