diff options
author | Daniel Stenberg <daniel@haxx.se> | 2011-03-13 00:36:38 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2011-03-13 00:36:38 +0100 |
commit | c8fba59731b4a87dd9fd296091730cadf04d475b (patch) | |
tree | 1c366b510df0acaa78f7bec3df38e9cd6c75ecf8 /lib/imap.c | |
parent | 4d1d1b8518f58749ecbe12363412866ee4fc87e1 (diff) | |
parent | dd3760f2eb11745ea73d20bf7affe735f671fda5 (diff) |
Merge branch 'imap' of https://github.com/bnoordhuis/curl into bnoordhuis-imap
Diffstat (limited to 'lib/imap.c')
-rw-r--r-- | lib/imap.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/lib/imap.c b/lib/imap.c index 5e294158b..16410c7d5 100644 --- a/lib/imap.c +++ b/lib/imap.c @@ -108,6 +108,7 @@ static int imap_getsock(struct connectdata *conn, static CURLcode imap_doing(struct connectdata *conn, bool *dophase_done); static CURLcode imap_setup_connection(struct connectdata * conn); +static CURLcode imap_state_upgrade_tls(struct connectdata *conn); /* * IMAP protocol handler. @@ -342,17 +343,38 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn, result = CURLE_LOGIN_DENIED; } else { - /* Curl_ssl_connect is BLOCKING */ - result = Curl_ssl_connect(conn, FIRSTSOCKET); - if(CURLE_OK == result) { - conn->protocol |= PROT_IMAPS; - result = imap_state_login(conn); + if(data->state.used_interface == Curl_if_multi) { + state(conn, IMAP_UPGRADETLS); + return imap_state_upgrade_tls(conn); + } + else { + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(CURLE_OK == result) { + conn->protocol |= PROT_IMAPS; + result = imap_state_login(conn); + } } } state(conn, IMAP_STOP); return result; } +static CURLcode imap_state_upgrade_tls(struct connectdata *conn) +{ + struct imap_conn *imapc = &conn->proto.imapc; + CURLcode result; + + result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone); + + if(imapc->ssldone) { + conn->protocol |= PROT_IMAPS; + result = imap_state_login(conn); + state(conn, IMAP_STOP); + } + + return result; +} + /* for LOGIN responses */ static CURLcode imap_state_login_resp(struct connectdata *conn, int imapcode, @@ -524,6 +546,10 @@ static CURLcode imap_statemach_act(struct connectdata *conn) struct pingpong *pp = &imapc->pp; size_t nread = 0; + /* busy upgrading the connection; right now all I/O is SSL/TLS, not IMAP */ + if(imapc->state == IMAP_UPGRADETLS) + return imap_state_upgrade_tls(conn); + if(pp->sendleft) return Curl_pp_flushsend(pp); @@ -588,7 +614,14 @@ static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done) { struct imap_conn *imapc = &conn->proto.imapc; - CURLcode result = Curl_pp_multi_statemach(&imapc->pp); + CURLcode result; + + if((conn->protocol & PROT_IMAPS) && !imapc->ssldone) { + result = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &imapc->ssldone); + } + else { + result = Curl_pp_multi_statemach(&imapc->pp); + } *done = (bool)(imapc->state == IMAP_STOP); @@ -700,7 +733,7 @@ static CURLcode imap_connect(struct connectdata *conn, } #endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_PROXY */ - if(conn->protocol & PROT_IMAPS) { + if((conn->protocol & PROT_IMAPS) && data->state.used_interface != Curl_if_multi) { /* BLOCKING */ /* IMAPS is simply imap with SSL for the control channel */ /* now, perform the SSL initialization for this socket */ |