break;
}
cmd->name = p_strdup(cmd->pool,
- t_str_ucase(t_strdup_until(cmd->data->data, p)));
+ t_str_ucase(t_strdup_until(cmd->data->data, p)));
return cmd->name;
}
return smtp_client_command_get_name(cmd);
}
-static void
-smtp_client_command_update_event(struct smtp_client_command *cmd)
+static void smtp_client_command_update_event(struct smtp_client_command *cmd)
{
- event_add_str(cmd->event, "cmd_name", smtp_client_command_get_name(cmd));
+ const char *label = smtp_client_command_get_label(cmd);
+
+ event_add_str(cmd->event, "cmd_name",
+ smtp_client_command_get_name(cmd));
event_set_append_log_prefix(
- cmd->event,
- t_strdup_printf("command %s: ",
- str_sanitize(smtp_client_command_get_label(cmd), 128)));
+ cmd->event, t_strdup_printf("command %s: ",
+ str_sanitize(label, 128)));
}
static struct smtp_client_command *
data = cmd->data->data;
data_len = cmd->data->used;
- if (data_len < name_len ||
- i_memcasecmp(data, name, name_len) != 0)
+ if (data_len < name_len || i_memcasecmp(data, name, name_len) != 0)
return FALSE;
return (data_len == name_len ||
data[name_len] == ' ' || data[name_len] == '\r');
smtp_client_command_drop_callback(cmd);
if ((!disconnected && !cmd->plug && cmd->aborting) ||
- state >= SMTP_CLIENT_COMMAND_STATE_FINISHED)
+ state >= SMTP_CLIENT_COMMAND_STATE_FINISHED)
return;
struct event_passthrough *e = event_create_passthrough(cmd->event);
struct smtp_reply failure;
smtp_reply_init(&failure,
- SMTP_CLIENT_COMMAND_ERROR_ABORTED,
- "Aborted");
+ SMTP_CLIENT_COMMAND_ERROR_ABORTED, "Aborted");
failure.enhanced_code = SMTP_REPLY_ENH_CODE(9, 0, 0);
e->set_name("smtp_client_command_finished");
break;
case SMTP_CLIENT_COMMAND_STATE_SENDING:
if (!disconnected) {
- /* it is being sent; cannot truly abort it now */
+ /* It is being sent; cannot truly abort it now */
break;
}
/* fall through */
case SMTP_CLIENT_COMMAND_STATE_SUBMITTED:
- /* not yet sent */
+ /* Not yet sent */
e_debug(cmd->event, "Removed from send queue");
i_assert(conn->cmd_send_queue_count > 0);
DLLIST2_REMOVE(&conn->cmd_send_queue_head,
- &conn->cmd_send_queue_tail, cmd);
+ &conn->cmd_send_queue_tail, cmd);
i_assert(conn->cmd_send_queue_count > 1 ||
(cmd->prev == NULL && cmd->next == NULL));
conn->cmd_send_queue_count--;
break;
case SMTP_CLIENT_COMMAND_STATE_WAITING:
if (!disconnected) {
- /* we're expecting a reply; cannot truly abort it now */
+ /* We're expecting a reply; cannot truly abort it now */
break;
}
e_debug(cmd->event, "Removed from wait list");
i_assert(conn->cmd_wait_list_count > 0);
DLLIST2_REMOVE(&conn->cmd_wait_list_head,
- &conn->cmd_wait_list_tail, cmd);
+ &conn->cmd_wait_list_tail, cmd);
conn->cmd_wait_list_count--;
break;
default:
}
if (disconnected || cmd->plug ||
- state <= SMTP_CLIENT_COMMAND_STATE_SUBMITTED) {
- /* can only destroy it when it is not pending */
+ state <= SMTP_CLIENT_COMMAND_STATE_SUBMITTED) {
+ /* Can only destroy it when it is not pending */
smtp_client_command_unref(&cmd);
}
cmd->delayed_failure = smtp_reply_clone(cmd->pool, reply);
cmd->delaying_failure = TRUE;
if (conn->to_cmd_fail == NULL) {
- conn->to_cmd_fail = timeout_add_short(0,
- smtp_client_commands_fail_delayed, conn);
+ conn->to_cmd_fail = timeout_add_short(
+ 0, smtp_client_commands_fail_delayed, conn);
}
DLLIST_PREPEND(&conn->cmd_fail_list, cmd);
return;
smtp_client_command_fail_reply(_cmd, &reply);
}
-static void
-smtp_client_command_fail_delayed(struct smtp_client_command **_cmd)
+static void smtp_client_command_fail_delayed(struct smtp_client_command **_cmd)
{
struct smtp_client_command *cmd = *_cmd;
return;
i_assert(cmds_list_count > 0);
- /* copy the array and reference the commands to be robust against more
+ /* Copy the array and reference the commands to be robust against more
than one command disappearing from the list */
t_array_init(&cmds_arr, cmds_list_count);
for (cmd = cmds_list; cmd != NULL; cmd = cmd->next) {
cmds = array_get_modifiable(&cmds_arr, &count);
for (i = 0; i < count; i++) {
cmd = cmds[i];
- /* fail the reply */
+ /* Fail the reply */
smtp_client_command_abort(&cmds[i]);
- /* drop our reference */
+ /* Drop our reference */
smtp_client_command_unref(&cmd);
}
}
return;
i_assert(cmds_list_count > 0);
- /* copy the array and reference the commands to be robust against more
+ /* Copy the array and reference the commands to be robust against more
than one command disappearing from the list */
t_array_init(&cmds_arr, cmds_list_count);
for (cmd = cmds_list; cmd != NULL; cmd = cmd->next) {
cmds = array_get_modifiable(&cmds_arr, &count);
for (i = 0; i < count; i++) {
cmd = cmds[i];
- /* fail the reply */
+ /* Fail the reply */
smtp_client_command_fail_reply(&cmds[i], reply);
- /* drop our reference */
+ /* Drop our reference */
smtp_client_command_unref(&cmd);
}
}
unsigned int replies)
{
i_assert(cmd->replies_expected == 1 ||
- cmd->replies_expected == replies);
+ cmd->replies_expected == replies);
i_assert(replies > 0);
i_assert(cmd->replies_seen <= 1);
cmd->replies_expected = replies;
i_assert(cmd->stream_dot);
i_assert(conn->dot_output != NULL);
- /* this concludes the dot stream with CRLF.CRLF */
+ /* This concludes the dot stream with CRLF.CRLF */
if ((ret = o_stream_finish(conn->dot_output)) < 0) {
o_stream_unref(&conn->dot_output);
smtp_client_connection_handle_output_error(conn);
if (cmd->stream_finished) {
if ((ret = smtp_client_command_finish_dot_stream(cmd)) <= 0)
return ret;
- /* done sending payload */
+ /* Done sending payload */
e_debug(cmd->event, "Finished sending payload");
i_stream_unref(&cmd->stream);
return 1;
output = conn->dot_output;
}
- /* we're sending the stream now */
+ /* We're sending the stream now */
o_stream_set_max_buffer_size(output, IO_BLOCK_SIZE);
res = o_stream_send_istream(output, stream);
o_stream_set_max_buffer_size(output, SIZE_MAX);
case OSTREAM_SEND_ISTREAM_RESULT_FINISHED:
i_assert(cmd->stream_size == 0 ||
stream->v_offset == cmd->stream_size);
- /* finished with the stream */
+ /* Finished with the stream */
e_debug(cmd->event, "Finished reading payload stream");
cmd->stream_finished = TRUE;
if (cmd->stream_dot) {
if (ret <= 0)
return ret;
}
- /* done sending payload */
+ /* Done sending payload */
e_debug(cmd->event, "Finished sending payload");
i_stream_unref(&cmd->stream);
return 1;
case OSTREAM_SEND_ISTREAM_RESULT_WAIT_INPUT:
- /* input is blocking (client needs to act; disable timeout) */
+ /* Input is blocking (client needs to act; disable timeout) */
conn->io_cmd_payload = io_add_istream(
stream, smtp_client_command_payload_input, cmd);
return 0;
case OSTREAM_SEND_ISTREAM_RESULT_WAIT_OUTPUT:
e_debug(cmd->event, "Partially sent payload");
i_assert(cmd->stream_size == 0 ||
- stream->v_offset < cmd->stream_size);
+ stream->v_offset < cmd->stream_size);
return 0;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
-
- /* the provided payload stream is broken;
+ /* The provided payload stream is broken;
fail this command separately */
e_error(cmd->event, "read(%s) failed: %s",
i_stream_get_name(stream), i_stream_get_error(stream));
smtp_client_command_fail(
&cmd, SMTP_CLIENT_COMMAND_ERROR_BROKEN_PAYLOAD,
"Broken payload stream");
- /* we're in the middle of sending a command, so the connection
+ /* We're in the middle of sending a command, so the connection
will also have to be aborted */
o_stream_unref(&conn->dot_output);
smtp_client_connection_fail(
"Broken payload stream");
return -1;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
- /* normal connection failure */
+ /* Normal connection failure */
o_stream_unref(&conn->dot_output);
smtp_client_connection_handle_output_error(conn);
return -1;
if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY &&
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) == 0) {
- /* wait until we're fully connected */
+ /* Wait until we're fully connected */
e_debug(cmd->event, "Connection not ready [state=%s]",
smtp_client_connection_state_names[conn->state]);
return FALSE;
cmd = conn->cmd_wait_list_head;
if (cmd != NULL &&
(conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0) {
- /* cannot pipeline; wait for reply */
+ /* Cannot pipeline; wait for reply */
e_debug(cmd->event, "Pipeline occupied");
return FALSE;
}
if ((conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0 ||
(cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PIPELINE) == 0 ||
cmd->locked) {
- /* cannot pipeline with previous command;
+ /* Cannot pipeline with previous command;
wait for reply */
e_debug(cmd->event, "Pipeline blocked");
return FALSE;
{
struct smtp_client_connection *conn = cmd->conn;
- /* move command to wait list. */
+ /* Move command to wait list. */
i_assert(conn->cmd_send_queue_count > 0);
i_assert(conn->cmd_send_queue_count > 1 ||
(cmd->prev == NULL && cmd->next == NULL));
cmd = conn->cmd_streaming;
i_assert(cmd->stream != NULL);
} else {
- /* check whether we can send anything */
+ /* Check whether we can send anything */
cmd = conn->cmd_send_queue_head;
if (cmd == NULL)
return 0;
if ((ret = smtp_client_command_send_line(cmd)) <= 0)
return ret;
- /* command line sent. move command to wait list. */
+ /* Command line sent. move command to wait list. */
smtp_cient_command_wait(cmd);
cmd->state = SMTP_CLIENT_COMMAND_STATE_WAITING;
}
cmd->ehlo = TRUE;
if (conn->state == SMTP_CLIENT_CONNECTION_STATE_DISCONNECTED) {
- /* Add commands to send queue for delayed failure reply
- from ioloop */
+ /* Add commands to send queue for delayed failure reply from
+ ioloop */
DLLIST2_APPEND(&conn->cmd_send_queue_head,
- &conn->cmd_send_queue_tail, cmd);
+ &conn->cmd_send_queue_tail, cmd);
conn->cmd_send_queue_count++;
if (conn->to_commands == NULL) {
conn->to_commands = timeout_add_short(
if ((cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) != 0 &&
conn->state < SMTP_CLIENT_CONNECTION_STATE_READY) {
- /* pre-login commands get inserted before everything else */
+ /* Pre-login commands get inserted before everything else */
smtp_client_command_insert_prioritized(
cmd, SMTP_CLIENT_COMMAND_FLAG_PRELOGIN);
if (!conn->corked)
if (after != NULL) {
if (after->state >= SMTP_CLIENT_COMMAND_STATE_WAITING) {
- /* not in the send queue anymore; just prepend */
+ /* Not in the send queue anymore; just prepend */
DLLIST2_PREPEND(&conn->cmd_send_queue_head,
&conn->cmd_send_queue_tail, cmd);
conn->cmd_send_queue_count++;
} else {
- /* insert after indicated command */
+ /* Insert after indicated command */
DLLIST2_INSERT_AFTER(&conn->cmd_send_queue_head,
&conn->cmd_send_queue_tail,
after, cmd);
conn->cmd_send_queue_count++;
}
} else if ((cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRIORITY) != 0) {
- /* insert at beginning of queue for priority commands */
+ /* Insert at beginning of queue for priority commands */
smtp_client_command_insert_prioritized(
cmd, SMTP_CLIENT_COMMAND_FLAG_PRIORITY);
} else {
- /* just append at end of queue */
+ /* Just append at end of queue */
DLLIST2_APPEND(&conn->cmd_send_queue_head,
&conn->cmd_send_queue_tail, cmd);
conn->cmd_send_queue_count++;
i_stream_get_name(input),
i_stream_get_error(input));
}
- /* size must be known if stream is to be sent in chunks */
+ /* Size must be known if stream is to be sent in chunks */
i_assert(dot);
cmd->stream_size = 0;
}
if (finished) {
i_assert(conn->cmd_wait_list_count > 0);
DLLIST2_REMOVE(&conn->cmd_wait_list_head,
- &conn->cmd_wait_list_tail, cmd);
+ &conn->cmd_wait_list_tail, cmd);
conn->cmd_wait_list_count--;
if (cmd->aborting)
cmd->state = SMTP_CLIENT_COMMAND_STATE_ABORTED;
static void
_cmd_bdat_send_chunks(struct _cmd_data_context *ctx,
- struct smtp_client_command *after);
+ struct smtp_client_command *after);
static void _cmd_data_context_free(struct _cmd_data_context *ctx)
{
if (ctx->cmd_data != NULL) {
- /* abort the main (possibly unsubmitted) data command */
+ /* Abort the main (possibly unsubmitted) data command */
smtp_client_command_set_abort_callback(ctx->cmd_data,
- NULL, NULL);
+ NULL, NULL);
ctx->cmd_data = NULL;
}
i_stream_unref(&ctx->data);
struct smtp_client_command **cmds;
unsigned int count, i;
- /* drop all pending commands */
+ /* Drop all pending commands */
cmds = array_get_modifiable(&ctx->cmds, &count);
for (i = 0; i < count; i++) {
smtp_client_command_set_abort_callback(cmds[i], NULL, NULL);
{
struct _cmd_data_context *ctx = (struct _cmd_data_context *)context;
- /* the main (possibly unsubmitted) data command got aborted */
+ /* The main (possibly unsubmitted) data command got aborted */
_cmd_data_abort(ctx);
_cmd_data_context_free(ctx);
}
struct smtp_client_command *cmd = ctx->cmd_data;
if (cmd != NULL) {
- /* fail the main (possibly unsubmitted) data command so that
+ /* Fail the main (possibly unsubmitted) data command so that
the caller gets notified */
smtp_client_command_fail_reply(&cmd, reply);
}
}
-static void
-_cmd_data_cb(const struct smtp_reply *reply, void *context)
+static void _cmd_data_cb(const struct smtp_reply *reply, void *context)
{
struct _cmd_data_context *ctx = (struct _cmd_data_context *)context;
struct smtp_client_command *const *cmds, *cmd;
unsigned int count;
- /* got DATA reply; one command must be pending */
+ /* Got DATA reply; one command must be pending */
cmds = array_get(&ctx->cmds, &count);
i_assert(count > 0);
if (reply->status == 354) {
- /* submit second stage: which is a command with only a stream */
+ /* Submit second stage: which is a command with only a stream */
cmd = ctx->cmd_data;
smtp_client_command_submit_after(cmd, cmds[0]);
- /* nothing else to do, so drop the context already */
+ /* Nothing else to do, so drop the context already */
_cmd_data_context_free(ctx);
} else {
- /* error */
+ /* Error */
_cmd_data_error(ctx, reply);
}
}
-static void
-_cmd_bdat_cb(const struct smtp_reply *reply, void *context)
+static void _cmd_bdat_cb(const struct smtp_reply *reply, void *context)
{
struct _cmd_data_context *ctx = (struct _cmd_data_context *)context;
- /* got BDAT reply, so there must be ones pending */
+ /* Got BDAT reply, so there must be ones pending */
i_assert(array_count(&ctx->cmds) > 0);
if ((reply->status / 100) != 2) {
- /* error */
+ /* Error */
_cmd_data_error(ctx, reply);
return;
}
- /* drop the command from the list */
+ /* Drop the command from the list */
array_pop_front(&ctx->cmds);
- /* send more BDAT commands if necessary */
+ /* Send more BDAT commands if necessary */
(void)_cmd_bdat_send_chunks(ctx, NULL);
if (array_count(&ctx->cmds) == 0) {
- /* all of the BDAT commands finished already */
+ /* All of the BDAT commands finished already */
_cmd_data_context_free(ctx);
}
}
{
struct _cmd_data_context *ctx = (struct _cmd_data_context *)context;
- /* send more BDAT commands if possible */
+ /* Send more BDAT commands if possible */
(void)_cmd_bdat_send_chunks(ctx, NULL);
}
size_t data_size, max_chunk_size;
if (smtp_client_command_get_state(ctx->cmd_data) >=
- SMTP_CLIENT_COMMAND_STATE_SUBMITTED) {
- /* finished or aborted */
+ SMTP_CLIENT_COMMAND_STATE_SUBMITTED) {
+ /* Finished or aborted */
return;
}
- /* pipeline management: determine where to submit the next command */
+ /* Pipeline management: determine where to submit the next command */
cmds = array_get(&ctx->cmds, &count);
cmd_prev = NULL;
if (after != NULL) {
max_chunk_size = set->max_data_chunk_size;
} else {
if (ctx->data->v_offset < ctx->data_offset) {
- /* previous BDAT command not completely sent */
+ /* Previous BDAT command not completely sent */
return;
}
max_chunk_size = i_stream_get_max_buffer_size(ctx->data);
data_size -= size;
if (array_count(&ctx->cmds) >= set->max_data_chunk_pipeline) {
- /* pipeline full */
+ /* Pipeline full */
if (ctx->data_left != 0) {
- /* data stream size known:
+ /* Data stream size known:
record where we left off */
ctx->data_left = data_size;
}
}
if (ctx->data_left != 0) {
- /* data stream size known:
- record where we left off */
+ /* Data stream size known: record where we left off */
ctx->data_left = data_size;
} else if (!ctx->data->eof) {
- /* more to read */
+ /* More to read */
if (cmd != NULL) {
smtp_client_command_set_sent_callback(
cmd, _cmd_bdat_sent_cb, ctx);
return;
}
- /* the last chunk, which may actually be empty */
+ /* The last chunk, which may actually be empty */
chunk = i_stream_create_range(ctx->data, ctx->data_offset, data_size);
- /* submit final command */
+ /* Submit final command */
cmd = ctx->cmd_data;
smtp_client_command_set_stream(cmd, chunk, FALSE);
i_stream_unref(&chunk);
smtp_client_command_submit_after(cmd, cmd_prev);
if (array_count(&ctx->cmds) == 0) {
- /* all of the previous BDAT commands got replies already */
+ /* All of the previous BDAT commands got replies already */
_cmd_data_context_free(ctx);
}
}
struct _cmd_data_context *ctx;
struct smtp_client_command *cmd, *cmd_data;
- /* create the final command early for reference by the caller;
+ /* Create the final command early for reference by the caller;
it will not be submitted for now. The DATA command is handled in
- two stages (== command submissions), the BDAT command in one or more. */
+ two stages (== command submissions), the BDAT command in one or more.
+ */
cmd = cmd_data = smtp_client_command_create(conn, flags,
callback, context);
- /* protect against race conditions */
+ /* Protect against race conditions */
cmd_data->delay_failure = TRUE;
- /* create context in the final command's pool */
+ /* Create context in the final command's pool */
ctx = p_new(cmd->pool, struct _cmd_data_context, 1);
ctx->conn = conn;
ctx->pool = cmd->pool;
ctx->cmd_data = cmd;
- /* capture abort event with our context */
+ /* Capture abort event with our context */
smtp_client_command_set_abort_callback(cmd, _cmd_data_abort_cb, ctx);
ctx->data = data;
/* DATA */
p_array_init(&ctx->cmds, ctx->pool, 1);
- /* Data stream is sent in one go in the second stage. Since the data
- is sent in a '<CRLF>.<CRLF>'-terminated stream, it size is not
- relevant here. */
+ /* Data stream is sent in one go in the second stage. Since the
+ data is sent in a '<CRLF>.<CRLF>'-terminated stream, it size
+ is not relevant here. */
smtp_client_command_set_stream(cmd, ctx->data, TRUE);
/* Submit the initial DATA command */
p_array_init(&ctx->cmds, ctx->pool,
conn->set.max_data_chunk_pipeline);
- /* The data stream is sent in multiple chunks. Either the size of the
- data stream is known or it is not. These cases are handled a little
- differently. */
+ /* The data stream is sent in multiple chunks. Either the size
+ of the data stream is known or it is not. These cases are
+ handled a little differently. */
if (i_stream_get_size(data, TRUE, &ctx->data_left) > 0) {
- /* size is known */
+ /* Size is known */
i_assert(ctx->data_left >= data->v_offset);
ctx->data_left -= data->v_offset;
} else {
- /* size is unknown */
+ /* Size is unknown */
ctx->data_left = 0;
/* Make sure we can send chunks of sufficient size by