summaryrefslogtreecommitdiff
path: root/lib/pop3.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pop3.c')
-rw-r--r--lib/pop3.c345
1 files changed, 176 insertions, 169 deletions
diff --git a/lib/pop3.c b/lib/pop3.c
index e71860e48..af3bca5b0 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -88,22 +88,27 @@
#include "memdebug.h"
/* Local API functions */
-static CURLcode pop3_regular_transfer(struct connectdata *conn, bool *done);
-static CURLcode pop3_do(struct connectdata *conn, bool *done);
-static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
+static CURLcode pop3_regular_transfer(struct Curl_easy *data, bool *done);
+static CURLcode pop3_do(struct Curl_easy *data, bool *done);
+static CURLcode pop3_done(struct Curl_easy *data, CURLcode status,
bool premature);
-static CURLcode pop3_connect(struct connectdata *conn, bool *done);
-static CURLcode pop3_disconnect(struct connectdata *conn, bool dead);
-static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done);
-static int pop3_getsock(struct connectdata *conn, curl_socket_t *socks);
-static CURLcode pop3_doing(struct connectdata *conn, bool *dophase_done);
-static CURLcode pop3_setup_connection(struct connectdata *conn);
+static CURLcode pop3_connect(struct Curl_easy *data, bool *done);
+static CURLcode pop3_disconnect(struct Curl_easy *data,
+ struct connectdata *conn, bool dead);
+static CURLcode pop3_multi_statemach(struct Curl_easy *data, bool *done);
+static int pop3_getsock(struct Curl_easy *data,
+ struct connectdata *conn, curl_socket_t *socks);
+static CURLcode pop3_doing(struct Curl_easy *data, bool *dophase_done);
+static CURLcode pop3_setup_connection(struct Curl_easy *data,
+ struct connectdata *conn);
static CURLcode pop3_parse_url_options(struct connectdata *conn);
-static CURLcode pop3_parse_url_path(struct connectdata *conn);
-static CURLcode pop3_parse_custom_request(struct connectdata *conn);
-static CURLcode pop3_perform_auth(struct connectdata *conn, const char *mech,
+static CURLcode pop3_parse_url_path(struct Curl_easy *data);
+static CURLcode pop3_parse_custom_request(struct Curl_easy *data);
+static CURLcode pop3_perform_auth(struct Curl_easy *data,
+ struct connectdata *conn, const char *mech,
const char *initresp);
-static CURLcode pop3_continue_auth(struct connectdata *conn, const char *resp);
+static CURLcode pop3_continue_auth(struct Curl_easy *data,
+ struct connectdata *conn, const char *resp);
static void pop3_get_message(char *buffer, char **outptr);
/*
@@ -195,10 +200,11 @@ static void pop3_to_pop3s(struct connectdata *conn)
* capabilities from the CAPA response including the supported authentication
* types and allowed SASL mechanisms.
*/
-static bool pop3_endofresp(struct connectdata *conn, char *line, size_t len,
- int *resp)
+static bool pop3_endofresp(struct Curl_easy *data, struct connectdata *conn,
+ char *line, size_t len, int *resp)
{
struct pop3_conn *pop3c = &conn->proto.pop3c;
+ (void)data;
/* Do we have an error response? */
if(len >= 4 && !memcmp("-ERR", line, 4)) {
@@ -279,9 +285,9 @@ static void pop3_get_message(char *buffer, char **outptr)
*
* This is the ONLY way to change POP3 state!
*/
-static void state(struct connectdata *conn, pop3state newstate)
+static void state(struct Curl_easy *data, pop3state newstate)
{
- struct pop3_conn *pop3c = &conn->proto.pop3c;
+ struct pop3_conn *pop3c = &data->conn->proto.pop3c;
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
/* for debug purposes */
static const char * const names[] = {
@@ -300,7 +306,7 @@ static void state(struct connectdata *conn, pop3state newstate)
};
if(pop3c->state != newstate)
- infof(conn->data, "POP3 %p state change from %s to %s\n",
+ infof(data, "POP3 %p state change from %s to %s\n",
(void *)pop3c, names[pop3c->state], names[newstate]);
#endif
@@ -314,7 +320,8 @@ static void state(struct connectdata *conn, pop3state newstate)
* Sends the CAPA command in order to obtain a list of server side supported
* capabilities.
*/
-static CURLcode pop3_perform_capa(struct connectdata *conn)
+static CURLcode pop3_perform_capa(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -324,10 +331,10 @@ static CURLcode pop3_perform_capa(struct connectdata *conn)
pop3c->tls_supported = FALSE; /* Clear the TLS capability */
/* Send the CAPA command */
- result = Curl_pp_sendf(&pop3c->pp, "%s", "CAPA");
+ result = Curl_pp_sendf(data, &pop3c->pp, "%s", "CAPA");
if(!result)
- state(conn, POP3_CAPA);
+ state(data, POP3_CAPA);
return result;
}
@@ -338,13 +345,14 @@ static CURLcode pop3_perform_capa(struct connectdata *conn)
*
* Sends the STLS command to start the upgrade to TLS.
*/
-static CURLcode pop3_perform_starttls(struct connectdata *conn)
+static CURLcode pop3_perform_starttls(struct Curl_easy *data,
+ struct connectdata *conn)
{
/* Send the STLS command */
- CURLcode result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "STLS");
+ CURLcode result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "%s", "STLS");
if(!result)
- state(conn, POP3_STARTTLS);
+ state(data, POP3_STARTTLS);
return result;
}
@@ -355,7 +363,8 @@ static CURLcode pop3_perform_starttls(struct connectdata *conn)
*
* Performs the upgrade to TLS.
*/
-static CURLcode pop3_perform_upgrade_tls(struct connectdata *conn)
+static CURLcode pop3_perform_upgrade_tls(struct Curl_easy *data,
+ struct connectdata *conn)
{
/* Start the SSL connection */
struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -364,11 +373,11 @@ static CURLcode pop3_perform_upgrade_tls(struct connectdata *conn)
if(!result) {
if(pop3c->state != POP3_UPGRADETLS)
- state(conn, POP3_UPGRADETLS);
+ state(data, POP3_UPGRADETLS);
if(pop3c->ssldone) {
pop3_to_pop3s(conn);
- result = pop3_perform_capa(conn);
+ result = pop3_perform_capa(data, conn);
}
}
@@ -381,23 +390,24 @@ static CURLcode pop3_perform_upgrade_tls(struct connectdata *conn)
*
* Sends a clear text USER command to authenticate with.
*/
-static CURLcode pop3_perform_user(struct connectdata *conn)
+static CURLcode pop3_perform_user(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
/* Check we have a username and password to authenticate with and end the
connect phase if we don't */
if(!conn->bits.user_passwd) {
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
/* Send the USER command */
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "USER %s",
+ result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "USER %s",
conn->user ? conn->user : "");
if(!result)
- state(conn, POP3_USER);
+ state(data, POP3_USER);
return result;
}
@@ -409,7 +419,8 @@ static CURLcode pop3_perform_user(struct connectdata *conn)
*
* Sends an APOP command to authenticate with.
*/
-static CURLcode pop3_perform_apop(struct connectdata *conn)
+static CURLcode pop3_perform_apop(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -421,7 +432,7 @@ static CURLcode pop3_perform_apop(struct connectdata *conn)
/* Check we have a username and password to authenticate with and end the
connect phase if we don't */
if(!conn->bits.user_passwd) {
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
@@ -444,10 +455,10 @@ static CURLcode pop3_perform_apop(struct connectdata *conn)
for(i = 0; i < MD5_DIGEST_LEN; i++)
msnprintf(&secret[2 * i], 3, "%02x", digest[i]);
- result = Curl_pp_sendf(&pop3c->pp, "APOP %s %s", conn->user, secret);
+ result = Curl_pp_sendf(data, &pop3c->pp, "APOP %s %s", conn->user, secret);
if(!result)
- state(conn, POP3_APOP);
+ state(data, POP3_APOP);
return result;
}
@@ -460,7 +471,8 @@ static CURLcode pop3_perform_apop(struct connectdata *conn)
* Sends an AUTH command allowing the client to login with the given SASL
* authentication mechanism.
*/
-static CURLcode pop3_perform_auth(struct connectdata *conn,
+static CURLcode pop3_perform_auth(struct Curl_easy *data,
+ struct connectdata *conn,
const char *mech,
const char *initresp)
{
@@ -469,11 +481,11 @@ static CURLcode pop3_perform_auth(struct connectdata *conn,
if(initresp) { /* AUTH <mech> ...<crlf> */
/* Send the AUTH command with the initial response */
- result = Curl_pp_sendf(&pop3c->pp, "AUTH %s %s", mech, initresp);
+ result = Curl_pp_sendf(data, &pop3c->pp, "AUTH %s %s", mech, initresp);
}
else {
/* Send the AUTH command */
- result = Curl_pp_sendf(&pop3c->pp, "AUTH %s", mech);
+ result = Curl_pp_sendf(data, &pop3c->pp, "AUTH %s", mech);
}
return result;
@@ -485,12 +497,13 @@ static CURLcode pop3_perform_auth(struct connectdata *conn,
*
* Sends SASL continuation data or cancellation.
*/
-static CURLcode pop3_continue_auth(struct connectdata *conn,
+static CURLcode pop3_continue_auth(struct Curl_easy *data,
+ struct connectdata *conn,
const char *resp)
{
struct pop3_conn *pop3c = &conn->proto.pop3c;
- return Curl_pp_sendf(&pop3c->pp, "%s", resp);
+ return Curl_pp_sendf(data, &pop3c->pp, "%s", resp);
}
/***********************************************************************
@@ -501,7 +514,8 @@ static CURLcode pop3_continue_auth(struct connectdata *conn,
* authentication mechanism, falling back to APOP and clear text should a
* common mechanism not be available between the client and server.
*/
-static CURLcode pop3_perform_authentication(struct connectdata *conn)
+static CURLcode pop3_perform_authentication(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
struct pop3_conn *pop3c = &conn->proto.pop3c;
@@ -510,7 +524,7 @@ static CURLcode pop3_perform_authentication(struct connectdata *conn)
/* Check we have enough data to authenticate with and end the
connect phase if we don't */
if(!Curl_sasl_can_authenticate(&pop3c->sasl, conn)) {
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
@@ -520,22 +534,22 @@ static CURLcode pop3_perform_authentication(struct connectdata *conn)
if(!result)
if(progress == SASL_INPROGRESS)
- state(conn, POP3_AUTH);
+ state(data, POP3_AUTH);
}
if(!result && progress == SASL_IDLE) {
#ifndef CURL_DISABLE_CRYPTO_AUTH
if(pop3c->authtypes & pop3c->preftype & POP3_TYPE_APOP)
/* Perform APOP authentication */
- result = pop3_perform_apop(conn);
+ result = pop3_perform_apop(data, conn);
else
#endif
if(pop3c->authtypes & pop3c->preftype & POP3_TYPE_CLEARTEXT)
/* Perform clear text authentication */
- result = pop3_perform_user(conn);
+ result = pop3_perform_user(data, conn);
else {
/* Other mechanisms not supported */
- infof(conn->data, "No known authentication mechanisms supported!\n");
+ infof(data, "No known authentication mechanisms supported!\n");
result = CURLE_LOGIN_DENIED;
}
}
@@ -549,15 +563,15 @@ static CURLcode pop3_perform_authentication(struct connectdata *conn)
*
* Sends a POP3 based command.
*/
-static CURLcode pop3_perform_command(struct connectdata *conn)
+static CURLcode pop3_perform_command(struct Curl_easy *data)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct POP3 *pop3 = data->req.p.pop3;
const char *command = NULL;
/* Calculate the default command */
- if(pop3->id[0] == '\0' || conn->data->set.ftp_list_only) {
+ if(pop3->id[0] == '\0' || data->set.ftp_list_only) {
command = "LIST";
if(pop3->id[0] != '\0')
@@ -569,16 +583,16 @@ static CURLcode pop3_perform_command(struct connectdata *conn)
/* Send the command */
if(pop3->id[0] != '\0')
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s %s",
+ result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "%s %s",
(pop3->custom && pop3->custom[0] != '\0' ?
pop3->custom : command), pop3->id);
else
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s",
+ result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "%s",
(pop3->custom && pop3->custom[0] != '\0' ?
pop3->custom : command));
if(!result)
- state(conn, POP3_COMMAND);
+ state(data, POP3_COMMAND);
return result;
}
@@ -589,24 +603,25 @@ static CURLcode pop3_perform_command(struct connectdata *conn)
*
* Performs the quit action prior to sclose() be called.
*/
-static CURLcode pop3_perform_quit(struct connectdata *conn)
+static CURLcode pop3_perform_quit(struct Curl_easy *data,
+ struct connectdata *conn)
{
/* Send the QUIT command */
- CURLcode result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", "QUIT");
+ CURLcode result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "%s", "QUIT");
if(!result)
- state(conn, POP3_QUIT);
+ state(data, POP3_QUIT);
return result;
}
/* For the initial server greeting */
-static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
+static CURLcode pop3_state_servergreet_resp(struct Curl_easy *data,
int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
@@ -654,18 +669,18 @@ static CURLcode pop3_state_servergreet_resp(struct connectdata *conn,
}
}
- result = pop3_perform_capa(conn);
+ result = pop3_perform_capa(data, conn);
}
return result;
}
/* For CAPA responses */
-static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code,
+static CURLcode pop3_state_capa_resp(struct Curl_easy *data, int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
const char *line = data->state.buffer;
size_t len = strlen(line);
@@ -728,36 +743,35 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code,
/* We don't have a SSL/TLS connection yet, but SSL is requested */
if(pop3c->tls_supported)
/* Switch to TLS connection now */
- result = pop3_perform_starttls(conn);
+ result = pop3_perform_starttls(data, conn);
else if(data->set.use_ssl == CURLUSESSL_TRY)
/* Fallback and carry on with authentication */
- result = pop3_perform_authentication(conn);
+ result = pop3_perform_authentication(data, conn);
else {
failf(data, "STLS not supported.");
result = CURLE_USE_SSL_FAILED;
}
}
else
- result = pop3_perform_authentication(conn);
+ result = pop3_perform_authentication(data, conn);
}
else {
/* Clear text is supported when CAPA isn't recognised */
pop3c->authtypes |= POP3_TYPE_CLEARTEXT;
- result = pop3_perform_authentication(conn);
+ result = pop3_perform_authentication(data, conn);
}
return result;
}
/* For STARTTLS responses */
-static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
+static CURLcode pop3_state_starttls_resp(struct Curl_easy *data,
+ struct connectdata *conn,
int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
-
(void)instate; /* no use for this yet */
if(pop3code != '+') {
@@ -766,21 +780,21 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn,
result = CURLE_USE_SSL_FAILED;
}
else
- result = pop3_perform_authentication(conn);
+ result = pop3_perform_authentication(data, conn);
}
else
- result = pop3_perform_upgrade_tls(conn);
+ result = pop3_perform_upgrade_tls(data, conn);
return result;
}
/* For SASL authentication responses */
-static CURLcode pop3_state_auth_resp(struct connectdata *conn,
+static CURLcode pop3_state_auth_resp(struct Curl_easy *data,
int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
saslprogress progress;
@@ -790,18 +804,18 @@ static CURLcode pop3_state_auth_resp(struct connectdata *conn,
if(!result)
switch(progress) {
case SASL_DONE:
- state(conn, POP3_STOP); /* Authenticated */
+ state(data, POP3_STOP); /* Authenticated */
break;
case SASL_IDLE: /* No mechanism left after cancellation */
#ifndef CURL_DISABLE_CRYPTO_AUTH
if(pop3c->authtypes & pop3c->preftype & POP3_TYPE_APOP)
/* Perform APOP authentication */
- result = pop3_perform_apop(conn);
+ result = pop3_perform_apop(data, conn);
else
#endif
if(pop3c->authtypes & pop3c->preftype & POP3_TYPE_CLEARTEXT)
/* Perform clear text authentication */
- result = pop3_perform_user(conn);
+ result = pop3_perform_user(data, conn);
else {
failf(data, "Authentication cancelled");
result = CURLE_LOGIN_DENIED;
@@ -816,12 +830,10 @@ static CURLcode pop3_state_auth_resp(struct connectdata *conn,
#ifndef CURL_DISABLE_CRYPTO_AUTH
/* For APOP responses */
-static CURLcode pop3_state_apop_resp(struct connectdata *conn, int pop3code,
+static CURLcode pop3_state_apop_resp(struct Curl_easy *data, int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
-
(void)instate; /* no use for this yet */
if(pop3code != '+') {
@@ -830,19 +842,18 @@ static CURLcode pop3_state_apop_resp(struct connectdata *conn, int pop3code,
}
else
/* End of connect phase */
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
#endif
/* For USER responses */
-static CURLcode pop3_state_user_resp(struct connectdata *conn, int pop3code,
+static CURLcode pop3_state_user_resp(struct Curl_easy *data, int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
-
+ struct connectdata *conn = data->conn;
(void)instate; /* no use for this yet */
if(pop3code != '+') {
@@ -851,21 +862,19 @@ static CURLcode pop3_state_user_resp(struct connectdata *conn, int pop3code,
}
else
/* Send the PASS command */
- result = Curl_pp_sendf(&conn->proto.pop3c.pp, "PASS %s",
+ result = Curl_pp_sendf(data, &conn->proto.pop3c.pp, "PASS %s",
conn->passwd ? conn->passwd : "");
if(!result)
- state(conn, POP3_PASS);
+ state(data, POP3_PASS);
return result;
}
/* For PASS responses */
-static CURLcode pop3_state_pass_resp(struct connectdata *conn, int pop3code,
+static CURLcode pop3_state_pass_resp(struct Curl_easy *data, int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
-
(void)instate; /* no use for this yet */
if(pop3code != '+') {
@@ -874,18 +883,18 @@ static CURLcode pop3_state_pass_resp(struct connectdata *conn, int pop3code,
}
else
/* End of connect phase */
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
/* For command responses */
-static CURLcode pop3_state_command_resp(struct connectdata *conn,
+static CURLcode pop3_state_command_resp(struct Curl_easy *data,
int pop3code,
pop3state instate)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
+ struct connectdata *conn = data->conn;
struct POP3 *pop3 = data->req.p.pop3;
struct pop3_conn *pop3c = &conn->proto.pop3c;
struct pingpong *pp = &pop3c->pp;
@@ -893,7 +902,7 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
(void)instate; /* no use for this yet */
if(pop3code != '+') {
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return CURLE_RECV_ERROR;
}
@@ -917,7 +926,7 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
"headers" after the body */
if(!data->set.opt_no_body) {
- result = Curl_pop3_write(conn, pp->cache, pp->cache_size);
+ result = Curl_pop3_write(data, pp->cache, pp->cache_size);
if(result)
return result;
}
@@ -931,12 +940,13 @@ static CURLcode pop3_state_command_resp(struct connectdata *conn,
}
/* End of DO phase */
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
return result;
}
-static CURLcode pop3_statemach_act(struct connectdata *conn)
+static CURLcode pop3_statemachine(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result = CURLE_OK;
curl_socket_t sock = conn->sock[FIRSTSOCKET];
@@ -944,10 +954,11 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
struct pop3_conn *pop3c = &conn->proto.pop3c;
struct pingpong *pp = &pop3c->pp;
size_t nread = 0;
+ (void)data;
/* Busy upgrading the connection; right now all I/O is SSL/TLS, not POP3 */
if(pop3c->state == POP3_UPGRADETLS)
- return pop3_perform_upgrade_tls(conn);
+ return pop3_perform_upgrade_tls(data, conn);
/* Flush any data that needs to be sent */
if(pp->sendleft)
@@ -955,9 +966,9 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
do {
/* Read the response from the server */
- result = Curl_pp_readresp(sock, pp, &pop3code, &nread);
- if(result)
- return result;
+ result = Curl_pp_readresp(data, sock, pp, &pop3code, &nread);
+ if(result)
+ return result;
if(!pop3code)
break;
@@ -965,44 +976,44 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
/* We have now received a full POP3 server response */
switch(pop3c->state) {
case POP3_SERVERGREET:
- result = pop3_state_servergreet_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_servergreet_resp(data, pop3code, pop3c->state);
break;
case POP3_CAPA:
- result = pop3_state_capa_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_capa_resp(data, pop3code, pop3c->state);
break;
case POP3_STARTTLS:
- result = pop3_state_starttls_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_starttls_resp(data, conn, pop3code, pop3c->state);
break;
case POP3_AUTH:
- result = pop3_state_auth_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_auth_resp(data, pop3code, pop3c->state);
break;
#ifndef CURL_DISABLE_CRYPTO_AUTH
case POP3_APOP:
- result = pop3_state_apop_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_apop_resp(data, pop3code, pop3c->state);
break;
#endif
case POP3_USER:
- result = pop3_state_user_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_user_resp(data, pop3code, pop3c->state);
break;
case POP3_PASS:
- result = pop3_state_pass_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_pass_resp(data, pop3code, pop3c->state);
break;
case POP3_COMMAND:
- result = pop3_state_command_resp(conn, pop3code, pop3c->state);
+ result = pop3_state_command_resp(data, pop3code, pop3c->state);
break;
case POP3_QUIT:
/* fallthrough, just stop! */
default:
/* internal error */
- state(conn, POP3_STOP);
+ state(data, POP3_STOP);
break;
}
} while(!result && pop3c->state != POP3_STOP && Curl_pp_moredata(pp));
@@ -1011,9 +1022,10 @@ static CURLcode pop3_statemach_act(struct connectdata *conn)
}
/* Called repeatedly until done from multi.c */
-static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done)
+static CURLcode pop3_multi_statemach(struct Curl_easy *data, bool *done)
{
CURLcode result = CURLE_OK;
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
if((conn->handler->flags & PROTOPT_SSL) && !pop3c->ssldone) {
@@ -1022,30 +1034,30 @@ static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done)
return result;
}
- result = Curl_pp_statemach(&pop3c->pp, FALSE, FALSE);
+ result = Curl_pp_statemach(data, &pop3c->pp, FALSE, FALSE);
*done = (pop3c->state == POP3_STOP) ? TRUE : FALSE;
return result;
}
-static CURLcode pop3_block_statemach(struct connectdata *conn,
+static CURLcode pop3_block_statemach(struct Curl_easy *data,
+ struct connectdata *conn,
bool disconnecting)
{
CURLcode result = CURLE_OK;
struct pop3_conn *pop3c = &conn->proto.pop3c;
while(pop3c->state != POP3_STOP && !result)
- result = Curl_pp_statemach(&pop3c->pp, TRUE, disconnecting);
+ result = Curl_pp_statemach(data, &pop3c->pp, TRUE, disconnecting);
return result;
}
/* Allocate and initialize the POP3 struct for the current Curl_easy if
required */
-static CURLcode pop3_init(struct connectdata *conn)
+static CURLcode pop3_init(struct Curl_easy *data)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct POP3 *pop3;
pop3 = data->req.p.pop3 = calloc(sizeof(struct POP3), 1);
@@ -1056,8 +1068,10 @@ static CURLcode pop3_init(struct connectdata *conn)
}
/* For the POP3 "protocol connect" and "doing" phases only */
-static int pop3_getsock(struct connectdata *conn, curl_socket_t *socks)
+static int pop3_getsock(struct Curl_easy *data,
+ struct connectdata *conn, curl_socket_t *socks)
{
+ (void)data;
return Curl_pp_getsock(&conn->proto.pop3c.pp, socks);
}
@@ -1071,9 +1085,10 @@ static int pop3_getsock(struct connectdata *conn, curl_socket_t *socks)
* The variable 'done' points to will be TRUE if the protocol-layer connect
* phase is done when this function returns, or FALSE if not.
*/
-static CURLcode pop3_connect(struct connectdata *conn, bool *done)
+static CURLcode pop3_connect(struct Curl_easy *data, bool *done)
{
CURLcode result = CURLE_OK;
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
struct pingpong *pp = &pop3c->pp;
@@ -1082,11 +1097,7 @@ static CURLcode pop3_connect(struct connectdata *conn, bool *done)
/* We always support persistent connections in POP3 */
connkeep(conn, "POP3 default");
- /* Set the default response time-out */
- pp->response_time = RESP_TIMEOUT;
- pp->statemach_act = pop3_statemach_act;
- pp->endofresp = pop3_endofresp;
- pp->conn = conn;
+ PINGPONG_SETUP(pp, pop3_statemachine, pop3_endofresp);
/* Set the default preferred authentication type and mechanism */
pop3c->preftype = POP3_TYPE_ANY;
@@ -1094,7 +1105,7 @@ static CURLcode pop3_connect(struct connectdata *conn, bool *done)
/* Initialise the pingpong layer */
Curl_pp_setup(pp);
- Curl_pp_init(pp);
+ Curl_pp_init(data, pp);
/* Parse the URL options */
result = pop3_parse_url_options(conn);
@@ -1102,9 +1113,9 @@ static CURLcode pop3_connect(struct connectdata *conn, bool *done)
return result;
/* Start off waiting for the server greeting response */
- state(conn, POP3_SERVERGREET);
+ state(data, POP3_SERVERGREET);
- result = pop3_multi_statemach(conn, done);
+ result = pop3_multi_statemach(data, done);
return result;
}
@@ -1118,11 +1129,10 @@ static CURLcode pop3_connect(struct connectdata *conn, bool *done)
*
* Input argument is already checked for validity.
*/
-static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
+static CURLcode pop3_done(struct Curl_easy *data, CURLcode status,
bool premature)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct POP3 *pop3 = data->req.p.pop3;
(void)premature;
@@ -1131,7 +1141,7 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
return CURLE_OK;
if(status) {
- connclose(conn, "POP3 done with bad status");
+ connclose(data->conn, "POP3 done with bad status");
result = status; /* use the already set error code */
}
@@ -1152,16 +1162,17 @@ static CURLcode pop3_done(struct connectdata *conn, CURLcode status,
* This is the actual DO function for POP3. Get a message/listing according to
* the options previously setup.
*/
-static CURLcode pop3_perform(struct connectdata *conn, bool *connected,
+static CURLcode pop3_perform(struct Curl_easy *data, bool *connected,
bool *dophase_done)
{
/* This is POP3 and no proxy */
CURLcode result = CURLE_OK;
- struct POP3 *pop3 = conn->data->req.p.pop3;
+ struct connectdata *conn = data->conn;
+ struct POP3 *pop3 = data->req.p.pop3;
- DEBUGF(infof(conn->data, "DO phase starts\n"));
+ DEBUGF(infof(data, "DO phase starts\n"));
- if(conn->data->set.opt_no_body) {
+ if(data->set.opt_no_body) {
/* Requested no body means no transfer */
pop3->transfer = FTPTRANSFER_INFO;
}
@@ -1169,17 +1180,16 @@ static CURLcode pop3_perform(struct connectdata *conn, bool *connected,
*dophase_done = FALSE; /* not done yet */
/* Start the first command in the DO phase */
- result = pop3_perform_command(conn);
+ result = pop3_perform_command(data);
if(result)
return result;
/* Run the state-machine */
- result = pop3_multi_statemach(conn, dophase_done);
-
+ result = pop3_multi_statemach(data, dophase_done);
*connected = conn->bits.tcpconnect[FIRSTSOCKET];
if(*dophase_done)
- DEBUGF(infof(conn->data, "DO phase is complete\n"));
+ DEBUGF(infof(data, "DO phase is complete\n"));
return result;
}
@@ -1193,23 +1203,22 @@ static CURLcode pop3_perform(struct connectdata *conn, bool *connected,
*
* The input argument is already checked for validity.
*/
-static CURLcode pop3_do(struct connectdata *conn, bool *done)
+static CURLcode pop3_do(struct Curl_easy *data, bool *done)
{
CURLcode result = CURLE_OK;
-
*done = FALSE; /* default to false */
/* Parse the URL path */
- result = pop3_parse_url_path(conn);
+ result = pop3_parse_url_path(data);
if(result)
return result;
/* Parse the custom request */
- result = pop3_parse_custom_request(conn);
+ result = pop3_parse_custom_request(data);
if(result)
return result;
- result = pop3_regular_transfer(conn, done);
+ result = pop3_regular_transfer(data, done);
return result;
}
@@ -1221,19 +1230,20 @@ static CURLcode pop3_do(struct connectdata *conn, bool *done)
* Disconnect from an POP3 server. Cleanup protocol-specific per-connection
* resources. BLOCKING.
*/
-static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection)
+static CURLcode pop3_disconnect(struct Curl_easy *data,
+ struct connectdata *conn, bool dead_connection)
{
struct pop3_conn *pop3c = &conn->proto.pop3c;
+ (void)data;
/* We cannot send quit unconditionally. If this connection is stale or
bad in any way, sending quit and waiting around here will make the
disconnect wait in vain and cause more problems than we need to. */
- /* The POP3 session may or may not have been allocated/setup at this
- point! */
- if(!dead_connection && pop3c->pp.conn && pop3c->pp.conn->bits.protoconnstart)
- if(!pop3_perform_quit(conn))
- (void)pop3_block_statemach(conn, TRUE); /* ignore errors on QUIT */
+ if(!dead_connection && conn->bits.protoconnstart) {
+ if(!pop3_perform_quit(data, conn))
+ (void)pop3_block_statemach(data, conn, TRUE); /* ignore errors on QUIT */
+ }
/* Disconnect from the server */
Curl_pp_disconnect(&pop3c->pp);
@@ -1248,25 +1258,25 @@ static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection)
}
/* Call this when the DO phase has completed */
-static CURLcode pop3_dophase_done(struct connectdata *conn, bool connected)
+static CURLcode pop3_dophase_done(struct Curl_easy *data, bool connected)
{
- (void)conn;
+ (void)data;
(void)connected;
return CURLE_OK;
}
/* Called from multi.c while DOing */
-static CURLcode pop3_doing(struct connectdata *conn, bool *dophase_done)
+static CURLcode pop3_doing(struct Curl_easy *data, bool *dophase_done)
{
- CURLcode result = pop3_multi_statemach(conn, dophase_done);
+ CURLcode result = pop3_multi_statemach(data, dophase_done);
if(result)
- DEBUGF(infof(conn->data, "DO phase failed\n"));
+ DEBUGF(infof(data, "DO phase failed\n"));
else if(*dophase_done) {
- result = pop3_dophase_done(conn, FALSE /* not connected */);
+ result = pop3_dophase_done(data, FALSE /* not connected */);
- DEBUGF(infof(conn->data, "DO phase is complete\n"));
+ DEBUGF(infof(data, "DO phase is complete\n"));
}
return result;
@@ -1281,12 +1291,11 @@ static CURLcode pop3_doing(struct connectdata *conn, bool *dophase_done)
* Performs all commands done before a regular transfer between a local and a
* remote host.
*/
-static CURLcode pop3_regular_transfer(struct connectdata *conn,
+static CURLcode pop3_regular_transfer(struct Curl_easy *data,
bool *dophase_done)
{
CURLcode result = CURLE_OK;
bool connected = FALSE;
- struct Curl_easy *data = conn->data;
/* Make sure size is unknown at this point */
data->req.size = -1;
@@ -1298,19 +1307,20 @@ static CURLcode pop3_regular_transfer(struct connectdata *conn,
Curl_pgrsSetDownloadSize(data, -1);
/* Carry out the perform */
- result = pop3_perform(conn, &connected, dophase_done);
+ result = pop3_perform(data, &connected, dophase_done);
/* Perform post DO phase operations if necessary */
if(!result && *dophase_done)
- result = pop3_dophase_done(conn, connected);
+ result = pop3_dophase_done(data, connected);
return result;
}
-static CURLcode pop3_setup_connection(struct connectdata *conn)
+static CURLcode pop3_setup_connection(struct Curl_easy *data,
+ struct connectdata *conn)
{
/* Initialise the POP3 layer */
- CURLcode result = pop3_init(conn);
+ CURLcode result = pop3_init(data);
if(result)
return result;
@@ -1385,10 +1395,9 @@ static CURLcode pop3_parse_url_options(struct connectdata *conn)
*
* Parse the URL path into separate path components.
*/
-static CURLcode pop3_parse_url_path(struct connectdata *conn)
+static CURLcode pop3_parse_url_path(struct Curl_easy *data)
{
/* The POP3 struct is already initialised in pop3_connect() */
- struct Curl_easy *data = conn->data;
struct POP3 *pop3 = data->req.p.pop3;
const char *path = &data->state.up.path[1]; /* skip leading path */
@@ -1402,10 +1411,9 @@ static CURLcode pop3_parse_url_path(struct connectdata *conn)
*
* Parse the custom request.
*/
-static CURLcode pop3_parse_custom_request(struct connectdata *conn)
+static CURLcode pop3_parse_custom_request(struct Curl_easy *data)
{
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct POP3 *pop3 = data->req.p.pop3;
const char *custom = data->set.str[STRING_CUSTOMREQUEST];
@@ -1423,13 +1431,12 @@ static CURLcode pop3_parse_custom_request(struct connectdata *conn)
* This function scans the body after the end-of-body and writes everything
* until the end is found.
*/
-CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread)
+CURLcode Curl_pop3_write(struct Curl_easy *data, char *str, size_t nread)
{
/* This code could be made into a special function in the handler struct */
CURLcode result = CURLE_OK;
- struct Curl_easy *data = conn->data;
struct SingleRequest *k = &data->req;
-
+ struct connectdata *conn = data->conn;
struct pop3_conn *pop3c = &conn->proto.pop3c;
bool strip_dot = FALSE;
size_t last = 0;
@@ -1450,7 +1457,7 @@ CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread)
if(i) {
/* Write out the body part that didn't match */
- result = Curl_client_write(conn, CLIENTWRITE_BODY, &str[last],
+ result = Curl_client_write(data, CLIENTWRITE_BODY, &str[last],
i - last);
if(result)
@@ -1508,7 +1515,7 @@ CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread)
if(prev) {
/* If the partial match was the CRLF and dot then only write the CRLF
as the server would have inserted the dot */
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)POP3_EOB,
+ result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)POP3_EOB,
strip_dot ? prev - 1 : prev);
if(result)
@@ -1524,7 +1531,7 @@ CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread)
/* We have a full match so the transfer is done, however we must transfer
the CRLF at the start of the EOB as this is considered to be part of the
message as per RFC-1939, sect. 3 */
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char *)POP3_EOB, 2);
+ result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)POP3_EOB, 2);
k->keepon &= ~KEEP_RECV;
pop3c->eob = 0;
@@ -1537,7 +1544,7 @@ CURLcode Curl_pop3_write(struct connectdata *conn, char *str, size_t nread)
return CURLE_OK;
if(nread - last) {
- result = Curl_client_write(conn, CLIENTWRITE_BODY, &str[last],
+ result = Curl_client_write(data, CLIENTWRITE_BODY, &str[last],
nread - last);
}