From 7ac7af5e395a2e77762a33c25d932e88f8a34905 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Mon, 17 Dec 2018 04:08:47 +0100 Subject: [PATCH] lib-smtp: smtp-server - Replace smtp_*_debug() with e_debug(). --- src/lib-smtp/smtp-server-cmd-auth.c | 5 +-- src/lib-smtp/smtp-server-cmd-data.c | 21 +++------ src/lib-smtp/smtp-server-cmd-starttls.c | 2 +- src/lib-smtp/smtp-server-command.c | 28 +++--------- src/lib-smtp/smtp-server-connection.c | 58 ++++++++----------------- src/lib-smtp/smtp-server-reply.c | 23 ++-------- 6 files changed, 39 insertions(+), 98 deletions(-) diff --git a/src/lib-smtp/smtp-server-cmd-auth.c b/src/lib-smtp/smtp-server-cmd-auth.c index 4d469af011..74a219787d 100644 --- a/src/lib-smtp/smtp-server-cmd-auth.c +++ b/src/lib-smtp/smtp-server-cmd-auth.c @@ -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) { @@ -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); diff --git a/src/lib-smtp/smtp-server-cmd-data.c b/src/lib-smtp/smtp-server-cmd-data.c index 75677c9ac2..7340cf2f9f 100644 --- a/src/lib-smtp/smtp-server-cmd-data.c +++ b/src/lib-smtp/smtp-server-cmd-data.c @@ -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"); @@ -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); @@ -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)) @@ -373,8 +368,7 @@ 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); } } @@ -382,8 +376,7 @@ cmd_data_next(struct smtp_server_cmd_ctx *cmd, 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 && diff --git a/src/lib-smtp/smtp-server-cmd-starttls.c b/src/lib-smtp/smtp-server-cmd-starttls.c index e33c088ff2..5da10631d8 100644 --- a/src/lib-smtp/smtp-server-cmd-starttls.c +++ b/src/lib-smtp/smtp-server-cmd-starttls.c @@ -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; diff --git a/src/lib-smtp/smtp-server-command.c b/src/lib-smtp/smtp-server-command.c index 8e15d77729..0e7ecf8a6d 100644 --- a/src/lib-smtp/smtp-server-command.c +++ b/src/lib-smtp/smtp-server-command.c @@ -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); -} - /* * */ @@ -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; @@ -435,7 +420,7 @@ 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); } @@ -443,7 +428,7 @@ 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); @@ -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); @@ -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); @@ -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; } diff --git a/src/lib-smtp/smtp-server-connection.c b/src/lib-smtp/smtp-server-connection.c index b74c2987bb..ad71cae25b 100644 --- a/src/lib-smtp/smtp-server-connection.c +++ b/src/lib-smtp/smtp-server-connection.c @@ -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 */ @@ -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); } @@ -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, @@ -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 */ @@ -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++; @@ -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) { @@ -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) { @@ -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"); } @@ -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; } @@ -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); @@ -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); } } @@ -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; } @@ -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; } @@ -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 */ @@ -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) @@ -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)); @@ -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); @@ -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)); @@ -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 && @@ -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); diff --git a/src/lib-smtp/smtp-server-reply.c b/src/lib-smtp/smtp-server-reply.c index 22a8b1ad58..ddea0abbd2 100644 --- a/src/lib-smtp/smtp-server-reply.c +++ b/src/lib-smtp/smtp-server-reply.c @@ -9,21 +9,6 @@ #include "smtp-server-private.h" -/* - * Logging - */ - -static inline void ATTR_FORMAT(2, 3) -smtp_server_reply_debug(struct smtp_server_reply *reply, - const char *format, ...) -{ - va_list args; - - va_start(args, format); - e_debug(reply->event, "%s", t_strdup_vprintf(format, args)); - va_end(args); -} - /* * Reply */ @@ -34,7 +19,7 @@ static void smtp_server_reply_destroy(struct smtp_server_reply *reply) return; if (reply->event != NULL) { - smtp_server_reply_debug(reply, "Destroy"); + e_debug(reply->event, "Destroy"); event_unref(&reply->event); } @@ -244,7 +229,7 @@ void smtp_server_reply_submit(struct smtp_server_reply *reply) i_assert(!reply->submitted); i_assert(reply->content != NULL); i_assert(str_len(reply->content->text) >= 5); - smtp_server_reply_debug(reply, "Submitted"); + e_debug(reply->event, "Submitted"); reply->command->replies_submitted++; reply->submitted = TRUE; @@ -460,8 +445,8 @@ static int smtp_server_reply_send_real(struct smtp_server_reply *reply) return -1; } - smtp_server_reply_debug(reply, "Sent: %s", - smtp_server_reply_get_one_line(reply)); + e_debug(reply->event, "Sent: %s", + smtp_server_reply_get_one_line(reply)); return ret; }