Skip to content

Commit

Permalink
lib-smtp: smtp-server - Replace smtp_*_debug() with e_debug().
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanbosch committed Mar 2, 2019
1 parent cb89fd6 commit 7ac7af5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 98 deletions.
5 changes: 2 additions & 3 deletions src/lib-smtp/smtp-server-cmd-auth.c
Expand Up @@ -96,7 +96,7 @@ static void cmd_auth_input(struct smtp_server_cmd_ctx *cmd)
}
/* handle syntax error */
if (ret < 0) {
smtp_server_connection_debug(conn,
e_debug(conn->event,
"Client sent invalid AUTH response: %s", error);

switch (error_code) {
Expand All @@ -120,8 +120,7 @@ static void cmd_auth_input(struct smtp_server_cmd_ctx *cmd)
return;
}

smtp_server_connection_debug(conn,
"Received AUTH response: %s", auth_response);
e_debug(conn->event, "Received AUTH response: %s", auth_response);

smtp_server_command_input_lock(cmd);

Expand Down
21 changes: 7 additions & 14 deletions src/lib-smtp/smtp-server-cmd-data.c
Expand Up @@ -245,8 +245,7 @@ static void cmd_data_input_error(struct smtp_server_cmd_ctx *cmd)
i_stream_get_error(data_input));
smtp_server_connection_close(&conn, "Read failure");
} else {
smtp_server_connection_debug(conn,
"Connection lost during data transfer: "
e_debug(conn->event, "Connection lost during data transfer: "
"Remote disconnected");
smtp_server_connection_close(&conn,
"Remote closed connection unexpectedly");
Expand All @@ -271,19 +270,16 @@ static int cmd_data_do_handle_input(struct smtp_server_cmd_ctx *cmd)
if (!smtp_server_cmd_data_check_size(cmd)) {
return -1;
} else if (!i_stream_have_bytes_left(conn->state.data_input)) {
smtp_server_command_debug(cmd,
"End of data");
e_debug(cmd->event, "End of data");
smtp_server_command_input_lock(cmd);
smtp_server_connection_timeout_stop(conn);
} else if (!data_cmd->chunk_last &&
!i_stream_have_bytes_left(data_cmd->chunk_input)) {
smtp_server_command_debug(cmd,
"End of chunk");
e_debug(cmd->event, "End of chunk");
cmd_data_chunk_finish(cmd);
} else if (i_stream_get_data_size(
conn->state.data_input) > 0) {
smtp_server_command_debug(cmd,
"Not all client data read");
e_debug(cmd->event, "Not all client data read");
smtp_server_connection_timeout_stop(cmd->conn);
} else {
smtp_server_connection_timeout_start(cmd->conn);
Expand Down Expand Up @@ -345,8 +341,7 @@ cmd_data_next(struct smtp_server_cmd_ctx *cmd,
conn->state.pending_rcpt_cmds == 0);
i_assert(trans != NULL);

smtp_server_command_debug(cmd,
"Command is next to be replied");
e_debug(cmd->event, "Command is next to be replied");

/* check whether we have had successful mail and rcpt commands */
if (!smtp_server_connection_data_check_state(cmd))
Expand All @@ -373,17 +368,15 @@ cmd_data_next(struct smtp_server_cmd_ctx *cmd,
i_stream_chain_append(conn->state.data_chain,
data_cmd->chunk_input);
if (data_cmd->chunk_last) {
smtp_server_command_debug(cmd,
"Seen the last chunk");
e_debug(cmd->event, "Seen the last chunk");
i_stream_chain_append_eof(conn->state.data_chain);
}
}

if (data_cmd->chunk_first) {
struct smtp_server_command *cmd_temp = command;

smtp_server_command_debug(cmd,
"First chunk");
e_debug(cmd->event, "First chunk");

smtp_server_command_ref(cmd_temp);
i_assert(callbacks != NULL &&
Expand Down
2 changes: 1 addition & 1 deletion src/lib-smtp/smtp-server-cmd-starttls.c
Expand Up @@ -16,7 +16,7 @@ static int cmd_starttls_start(struct smtp_server_connection *conn)
{
const struct smtp_server_callbacks *callbacks = conn->callbacks;

smtp_server_connection_debug(conn, "Starting TLS");
e_debug(conn->event, "Starting TLS");

if (callbacks != NULL && callbacks->conn_start_tls != NULL) {
struct smtp_server_connection *tmp_conn = conn;
Expand Down
28 changes: 6 additions & 22 deletions src/lib-smtp/smtp-server-command.c
Expand Up @@ -122,21 +122,6 @@ void smtp_server_commands_init(struct smtp_server *server)
SMTP_SERVER_CMD_FLAG_PREAUTH);
}

/*
* Logging
*/

void smtp_server_command_debug(struct smtp_server_cmd_ctx *cmd,
const char *format, ...)
{
struct smtp_server_connection *conn = cmd->conn;
va_list args;

va_start(args, format);
e_debug(conn->event, "%s", t_strdup_vprintf(format, args));
va_end(args);
}

/*
*
*/
Expand Down Expand Up @@ -280,7 +265,7 @@ bool smtp_server_command_unref(struct smtp_server_command **_cmd)
return TRUE;
cmd->destroying = TRUE;

smtp_server_command_debug(&cmd->context, "Destroy");
e_debug(cmd->context.event, "Destroy");

if (cmd->state < SMTP_SERVER_COMMAND_STATE_FINISHED) {
cmd->state = SMTP_SERVER_COMMAND_STATE_ABORTED;
Expand Down Expand Up @@ -435,15 +420,15 @@ smtp_server_command_get_reply_count(struct smtp_server_command *cmd)
void smtp_server_command_ready_to_reply(struct smtp_server_command *cmd)
{
cmd->state = SMTP_SERVER_COMMAND_STATE_READY_TO_REPLY;
smtp_server_command_debug(&cmd->context, "Ready to reply");
e_debug(cmd->context.event, "Ready to reply");
smtp_server_connection_trigger_output(cmd->context.conn);
}

bool smtp_server_command_next_to_reply(struct smtp_server_command **_cmd)
{
struct smtp_server_command *cmd = *_cmd;

smtp_server_command_debug(&cmd->context, "Next to reply");
e_debug(cmd->context.event, "Next to reply");

return smtp_server_command_call_hooks(
_cmd, SMTP_SERVER_COMMAND_HOOK_NEXT);
Expand All @@ -457,7 +442,7 @@ smtp_server_command_replied(struct smtp_server_command **_cmd)
if (cmd->replies_submitted < cmd->replies_expected)
return TRUE;

smtp_server_command_debug(&cmd->context, "Replied");
e_debug(cmd->context.event, "Replied");

return smtp_server_command_call_hooks(
_cmd, SMTP_SERVER_COMMAND_HOOK_REPLIED);
Expand All @@ -470,7 +455,7 @@ bool smtp_server_command_completed(struct smtp_server_command **_cmd)
if (cmd->replies_submitted < cmd->replies_expected)
return TRUE;

smtp_server_command_debug(&cmd->context, "Completed");
e_debug(cmd->context.event, "Completed");

return smtp_server_command_call_hooks(
_cmd, SMTP_SERVER_COMMAND_HOOK_COMPLETED);
Expand All @@ -491,8 +476,7 @@ smtp_server_command_handle_reply(struct smtp_server_command *cmd)
case SMTP_SERVER_COMMAND_STATE_NEW:
case SMTP_SERVER_COMMAND_STATE_PROCESSING:
if (!smtp_server_command_is_complete(cmd)) {
smtp_server_command_debug(&cmd->context,
"Not ready to reply");
e_debug(cmd->context.event, "Not ready to reply");
cmd->state = SMTP_SERVER_COMMAND_STATE_SUBMITTED_REPLY;
break;
}
Expand Down
58 changes: 19 additions & 39 deletions src/lib-smtp/smtp-server-connection.c
Expand Up @@ -31,20 +31,6 @@ const char *const smtp_server_state_names[] = {
"DATA"
};

/*
* Logging
*/

void smtp_server_connection_debug(struct smtp_server_connection *conn,
const char *format, ...)
{
va_list args;

va_start(args, format);
e_debug(conn->event, "%s", t_strdup_vprintf(format, args));
va_end(args);
}

/*
* Connection
*/
Expand Down Expand Up @@ -205,7 +191,7 @@ smtp_server_connection_idle_timeout(struct smtp_server_connection *conn)
void smtp_server_connection_timeout_stop(struct smtp_server_connection *conn)
{
if (conn->to_idle != NULL) {
smtp_server_connection_debug(conn, "Timeout stop");
e_debug(conn->event, "Timeout stop");

timeout_remove(&conn->to_idle);
}
Expand All @@ -218,7 +204,7 @@ void smtp_server_connection_timeout_start(struct smtp_server_connection *conn)

if (conn->to_idle == NULL &&
conn->set.max_client_idle_time_msecs > 0) {
smtp_server_connection_debug(conn, "Timeout start");
e_debug(conn->event, "Timeout start");

conn->to_idle = timeout_add(
conn->set.max_client_idle_time_msecs,
Expand Down Expand Up @@ -359,7 +345,7 @@ int smtp_server_connection_ssl_init(struct smtp_server_connection *conn)
return -1;
}

smtp_server_connection_debug(conn, "Starting SSL handshake");
e_debug(conn->event, "Starting SSL handshake");

if (conn->raw_input != conn->conn.input) {
/* recreate rawlog after STARTTLS */
Expand Down Expand Up @@ -436,8 +422,7 @@ smtp_server_connection_handle_input(struct smtp_server_connection *conn)
pending_command = NULL;
}

smtp_server_connection_debug(conn,
"Received new command: %s %s",
e_debug(conn->event, "Received new command: %s %s",
cmd_name, cmd_params);

conn->stats.command_count++;
Expand Down Expand Up @@ -479,7 +464,7 @@ smtp_server_connection_handle_input(struct smtp_server_connection *conn)
smtp_server_connection_close(&conn,
"Read failure");
} else {
smtp_server_connection_debug(conn,
e_debug(conn->event,
"Connection lost: Remote disconnected");

if (conn->command_queue_head == NULL) {
Expand All @@ -504,7 +489,7 @@ smtp_server_connection_handle_input(struct smtp_server_connection *conn)
if (ret < 0) {
struct smtp_server_command *cmd;

smtp_server_connection_debug(conn,
e_debug(conn->event,
"Client sent invalid command: %s", error);

switch (error_code) {
Expand Down Expand Up @@ -626,8 +611,7 @@ void smtp_server_connection_handle_output_error(
smtp_server_connection_close(&conn,
"Write failure");
} else {
smtp_server_connection_debug(conn,
"Connection lost: Remote disconnected");
e_debug(conn->event, "Connection lost: Remote disconnected");
smtp_server_connection_close(&conn,
"Remote closed connection unexpectedly");
}
Expand All @@ -642,8 +626,7 @@ smtp_server_connection_next_reply(struct smtp_server_connection *conn)
cmd = conn->command_queue_head;
if (cmd == NULL) {
/* no commands pending */
smtp_server_connection_debug(conn,
"No more commands pending");
e_debug(conn->event, "No more commands pending");
return FALSE;
}

Expand Down Expand Up @@ -731,8 +714,7 @@ smtp_server_connection_output(struct smtp_server_connection *conn)
{
int ret;

smtp_server_connection_debug(conn,
"Sending replies");
e_debug(conn->event, "Sending replies");

smtp_server_connection_ref(conn);
o_stream_cork(conn->conn.output);
Expand All @@ -752,8 +734,7 @@ void smtp_server_connection_trigger_output(
struct smtp_server_connection *conn)
{
if (conn->conn.output != NULL) {
smtp_server_connection_debug(conn,
"Trigger output");
e_debug(conn->event, "Trigger output");
o_stream_set_flush_pending(conn->conn.output, TRUE);
}
}
Expand Down Expand Up @@ -979,7 +960,7 @@ smtp_server_connection_create(struct smtp_server *server,
/* halt input until started */
smtp_server_connection_halt(conn);

smtp_server_connection_debug(conn, "Connection created");
e_debug(conn->event, "Connection created");

return conn;
}
Expand Down Expand Up @@ -1017,7 +998,7 @@ smtp_server_connection_create_from_streams(struct smtp_server *server,
/* halt input until started */
smtp_server_connection_halt(conn);

smtp_server_connection_debug(conn, "Connection created");
e_debug(conn->event, "Connection created");

return conn;
}
Expand Down Expand Up @@ -1060,7 +1041,7 @@ smtp_server_connection_disconnect(struct smtp_server_connection *conn,
reason = smtp_server_connection_get_disconnect_reason(conn);
else
reason = t_str_oneline(reason);
smtp_server_connection_debug(conn, "Disconnected: %s", reason);
e_debug(conn->event, "Disconnected: %s", reason);
conn->disconnect_reason = i_strdup(reason);

/* preserve statistics */
Expand Down Expand Up @@ -1116,7 +1097,7 @@ bool smtp_server_connection_unref(struct smtp_server_connection **_conn)

smtp_server_connection_disconnect(conn, NULL);

smtp_server_connection_debug(conn, "Connection destroy");
e_debug(conn->event, "Connection destroy");

if (conn->callbacks != NULL &&
conn->callbacks->conn_destroy != NULL)
Expand Down Expand Up @@ -1144,7 +1125,7 @@ void smtp_server_connection_send_line(struct smtp_server_connection *conn,
str = t_str_new(256);
str_vprintfa(str, fmt, args);

smtp_server_connection_debug(conn, "Sent: %s", str_c(str));
e_debug(conn->event, "Sent: %s", str_c(str));

str_append(str, "\r\n");
o_stream_nsend(conn->conn.output, str_data(str), str_len(str));
Expand All @@ -1170,8 +1151,7 @@ void smtp_server_connection_reply_lines(struct smtp_server_connection *conn,
T_BEGIN {
string_t *str;

smtp_server_connection_debug(conn, "Sent: %s",
smtp_reply_log(&reply));
e_debug(conn->event, "Sent: %s", smtp_reply_log(&reply));

str = t_str_new(256);
smtp_reply_write(str, &reply);
Expand All @@ -1193,7 +1173,7 @@ void smtp_server_connection_reply_immediate(
str_printfa(str, "%03u ", status);
str_vprintfa(str, fmt, args);

smtp_server_connection_debug(conn, "Sent: %s", str_c(str));
e_debug(conn->event, "Sent: %s", str_c(str));

str_append(str, "\r\n");
o_stream_nsend(conn->conn.output, str_data(str), str_len(str));
Expand Down Expand Up @@ -1343,7 +1323,7 @@ smtp_server_connection_get_security_string(struct smtp_server_connection *conn)

void smtp_server_connection_reset_state(struct smtp_server_connection *conn)
{
smtp_server_connection_debug(conn, "Connection state reset");
e_debug(conn->event, "Connection state reset");

if (conn->state.trans != NULL) {
if (conn->callbacks != NULL &&
Expand All @@ -1370,7 +1350,7 @@ void smtp_server_connection_reset_state(struct smtp_server_connection *conn)

void smtp_server_connection_clear(struct smtp_server_connection *conn)
{
smtp_server_connection_debug(conn, "Connection clear");
e_debug(conn->event, "Connection clear");

i_free(conn->helo_domain);
i_zero(&conn->helo);
Expand Down

0 comments on commit 7ac7af5

Please sign in to comment.