mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
SMTP-multi: non-blocking connect
Use Curl_ssl_connect_nonblocking() when upgrading the connection to TLS/SSL while using the multi interface.
This commit is contained in:
parent
88e825de86
commit
521e88e009
35
lib/smtp.c
35
lib/smtp.c
@ -115,6 +115,7 @@ static int smtp_getsock(struct connectdata *conn,
|
|||||||
static CURLcode smtp_doing(struct connectdata *conn,
|
static CURLcode smtp_doing(struct connectdata *conn,
|
||||||
bool *dophase_done);
|
bool *dophase_done);
|
||||||
static CURLcode smtp_setup_connection(struct connectdata * conn);
|
static CURLcode smtp_setup_connection(struct connectdata * conn);
|
||||||
|
static CURLcode smtp_state_upgrade_tls(struct connectdata *conn);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -290,6 +291,7 @@ static void state(struct connectdata *conn,
|
|||||||
"EHLO",
|
"EHLO",
|
||||||
"HELO",
|
"HELO",
|
||||||
"STARTTLS",
|
"STARTTLS",
|
||||||
|
"UPGRADETLS",
|
||||||
"AUTHPLAIN",
|
"AUTHPLAIN",
|
||||||
"AUTHLOGIN",
|
"AUTHLOGIN",
|
||||||
"AUTHPASSWD",
|
"AUTHPASSWD",
|
||||||
@ -481,16 +483,36 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn,
|
|||||||
result = smtp_authenticate(conn);
|
result = smtp_authenticate(conn);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Curl_ssl_connect is BLOCKING */
|
if(data->state.used_interface == Curl_if_multi) {
|
||||||
result = Curl_ssl_connect(conn, FIRSTSOCKET);
|
state(conn, SMTP_UPGRADETLS);
|
||||||
if(CURLE_OK == result) {
|
return smtp_state_upgrade_tls(conn);
|
||||||
smtp_to_smtps(conn);
|
}
|
||||||
result = smtp_state_ehlo(conn);
|
else {
|
||||||
|
result = Curl_ssl_connect(conn, FIRSTSOCKET);
|
||||||
|
if(CURLE_OK == result) {
|
||||||
|
smtp_to_smtps(conn);
|
||||||
|
result = smtp_state_ehlo(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CURLcode smtp_state_upgrade_tls(struct connectdata *conn)
|
||||||
|
{
|
||||||
|
struct smtp_conn *smtpc = &conn->proto.smtpc;
|
||||||
|
CURLcode result;
|
||||||
|
|
||||||
|
result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &smtpc->ssldone);
|
||||||
|
|
||||||
|
if(smtpc->ssldone) {
|
||||||
|
smtp_to_smtps(conn);
|
||||||
|
result = smtp_state_ehlo(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* for EHLO responses */
|
/* for EHLO responses */
|
||||||
static CURLcode smtp_state_ehlo_resp(struct connectdata *conn,
|
static CURLcode smtp_state_ehlo_resp(struct connectdata *conn,
|
||||||
int smtpcode,
|
int smtpcode,
|
||||||
@ -910,6 +932,9 @@ static CURLcode smtp_statemach_act(struct connectdata *conn)
|
|||||||
struct pingpong *pp = &smtpc->pp;
|
struct pingpong *pp = &smtpc->pp;
|
||||||
size_t nread = 0;
|
size_t nread = 0;
|
||||||
|
|
||||||
|
if(smtpc->state == SMTP_UPGRADETLS)
|
||||||
|
return smtp_state_upgrade_tls(conn);
|
||||||
|
|
||||||
if(pp->sendleft)
|
if(pp->sendleft)
|
||||||
/* we have a piece of a command still left to send */
|
/* we have a piece of a command still left to send */
|
||||||
return Curl_pp_flushsend(pp);
|
return Curl_pp_flushsend(pp);
|
||||||
|
@ -34,6 +34,7 @@ typedef enum {
|
|||||||
SMTP_EHLO,
|
SMTP_EHLO,
|
||||||
SMTP_HELO,
|
SMTP_HELO,
|
||||||
SMTP_STARTTLS,
|
SMTP_STARTTLS,
|
||||||
|
SMTP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS (multi mode only) */
|
||||||
SMTP_AUTHPLAIN,
|
SMTP_AUTHPLAIN,
|
||||||
SMTP_AUTHLOGIN,
|
SMTP_AUTHLOGIN,
|
||||||
SMTP_AUTHPASSWD,
|
SMTP_AUTHPASSWD,
|
||||||
|
Loading…
Reference in New Issue
Block a user