From: Stephan Bosch Date: Thu, 16 Aug 2018 20:15:36 +0000 (+0200) Subject: lib-smtp: client: Put determining the status of the command pipeline in a separate... X-Git-Tag: 2.3.9~908 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bec82a70eef0edb8d76c599b445b48f2a4dc74b;p=thirdparty%2Fdovecot%2Fcore.git lib-smtp: client: Put determining the status of the command pipeline in a separate function. --- diff --git a/src/lib-smtp/smtp-client-command.c b/src/lib-smtp/smtp-client-command.c index 15c28f1d65..dd5f8f1f5e 100644 --- a/src/lib-smtp/smtp-client-command.c +++ b/src/lib-smtp/smtp-client-command.c @@ -559,6 +559,51 @@ smtp_client_command_send_line(struct smtp_client_command *cmd) return 1; } +static bool +smtp_client_command_pipeline_is_open(struct smtp_client_connection *conn) +{ + struct smtp_client_command *cmd = conn->cmd_send_queue_head; + + if (cmd == NULL) + return TRUE; + + if (cmd->plug) { + smtp_client_command_debug(cmd, "Pipeline is plugged"); + return FALSE; + } + + if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY && + (cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) == 0) { + /* wait until we're fully connected */ + smtp_client_command_debug(cmd, + "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 */ + smtp_client_command_debug(cmd, "Pipeline occupied"); + return FALSE; + } + while (cmd != NULL) { + if ((conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0 || + (cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PIPELINE) == 0 || + cmd->locked) { + /* cannot pipeline with previous command; + wait for reply */ + smtp_client_command_debug(cmd, "Pipeline blocked"); + return FALSE; + } + cmd = cmd->next; + } + + cmd = conn->cmd_send_queue_head; + return TRUE; +} + static int smtp_client_command_do_send_more(struct smtp_client_connection *conn) { struct smtp_client_command *cmd; @@ -566,46 +611,12 @@ static int smtp_client_command_do_send_more(struct smtp_client_connection *conn) for (;;) { /* check whether we can send anything */ - cmd = conn->cmd_send_queue_head; if (cmd == NULL) return 0; - - if (cmd->plug) { - smtp_client_command_debug(cmd, "Pipeline is plugged"); + if (!smtp_client_command_pipeline_is_open(conn)) return 0; - } - if (conn->state < SMTP_CLIENT_CONNECTION_STATE_READY && - (cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PRELOGIN) == 0) { - /* wait until we're fully connected */ - smtp_client_command_debug(cmd, - "Connection not ready [state=%s]", - smtp_client_connection_state_names[conn->state]); - return 0; - } - - cmd = conn->cmd_wait_list_head; - if (cmd != NULL && - (conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0) { - /* cannot pipeline; wait for reply */ - smtp_client_command_debug(cmd, "Pipeline occupied"); - return 0; - } - while (cmd != NULL) { - if ((conn->caps.standard & SMTP_CAPABILITY_PIPELINING) == 0 || - (cmd->flags & SMTP_CLIENT_COMMAND_FLAG_PIPELINE) == 0 || - cmd->locked) { - /* cannot pipeline with previous command; - wait for reply */ - smtp_client_command_debug(cmd, - "Pipeline blocked"); - return 0; - } - cmd = cmd->next; - } - - cmd = conn->cmd_send_queue_head; cmd->state = SMTP_CLIENT_COMMAND_STATE_SENDING; conn->sending_command = TRUE;