#ifdef CURL_DISABLE_VERBOSE_STRINGS
#define ftp_pasv_verbose(a,b,c,d) Curl_nop_stmt
-#define FTP_CSTATE(c) ""
-#define FTP_DSTATE(d) ""
+#define FTP_CSTATE(c) ((void)(c), "")
#else /* CURL_DISABLE_VERBOSE_STRINGS */
/* for tracing purposes */
static const char * const ftp_state_names[]={
"STOR",
"QUIT"
};
-#define FTP_CSTATE(c) ((c)? ftp_state_names[(c)->proto.ftpc.state] : "???")
-#define FTP_DSTATE(d) (((d) && (d)->conn)? \
- ftp_state_names[(d)->conn->proto.ftpc.state] : "???")
+#define FTP_CSTATE(ftpc) ((ftpc)? ftp_state_names[(ftpc)->state] : "???")
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
/* This is the ONLY way to change FTP state! */
static void _ftp_state(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
ftpstate newstate
#ifdef DEBUGBUILD
, int lineno
#endif
)
{
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
-
#if defined(CURL_DISABLE_VERBOSE_STRINGS)
#ifdef DEBUGBUILD
(void)lineno;
#else /* CURL_DISABLE_VERBOSE_STRINGS */
if(ftpc->state != newstate)
#ifdef DEBUGBUILD
- CURL_TRC_FTP(data, "[%s] -> [%s] (line %d)", FTP_DSTATE(data),
+ CURL_TRC_FTP(data, "[%s] -> [%s] (line %d)", FTP_CSTATE(ftpc),
ftp_state_names[newstate], lineno);
#else
- CURL_TRC_FTP(data, "[%s] -> [%s]", FTP_DSTATE(data),
+ CURL_TRC_FTP(data, "[%s] -> [%s]", FTP_CSTATE(ftpc),
ftp_state_names[newstate]);
#endif
#endif /* !CURL_DISABLE_VERBOSE_STRINGS */
/* Local API functions */
#ifndef DEBUGBUILD
-#define ftp_state(x,y) _ftp_state(x,y)
+#define ftp_state(x,y,z) _ftp_state(x,y,z)
#else /* !DEBUGBUILD */
-#define ftp_state(x,y) _ftp_state(x,y,__LINE__)
+#define ftp_state(x,y,z) _ftp_state(x,y,z,__LINE__)
#endif /* DEBUGBUILD */
static CURLcode ftp_sendquote(struct Curl_easy *data,
- struct connectdata *conn,
+ struct ftp_conn *ftpc,
struct curl_slist *quote);
-static CURLcode ftp_quit(struct Curl_easy *data, struct connectdata *conn);
-static CURLcode ftp_parse_url_path(struct Curl_easy *data);
-static CURLcode ftp_regular_transfer(struct Curl_easy *data, bool *done);
+static CURLcode ftp_quit(struct Curl_easy *data, struct ftp_conn *ftpc);
+static CURLcode ftp_parse_url_path(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp);
+static CURLcode ftp_regular_transfer(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
+ bool *done);
#ifndef CURL_DISABLE_VERBOSE_STRINGS
static void ftp_pasv_verbose(struct Curl_easy *data,
struct Curl_addrinfo *ai,
char *newhost, /* ASCII version */
int port);
#endif
-static CURLcode ftp_state_prepare_transfer(struct Curl_easy *data);
-static CURLcode ftp_state_mdtm(struct Curl_easy *data);
+static CURLcode ftp_state_mdtm(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp);
static CURLcode ftp_state_quote(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool init, ftpstate instate);
static CURLcode ftp_nb_type(struct Curl_easy *data,
- struct connectdata *conn,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool ascii, ftpstate newstate);
-static int ftp_need_type(struct connectdata *conn,
- bool ascii);
+static int ftp_need_type(struct ftp_conn *ftpc, bool ascii);
static CURLcode ftp_do(struct Curl_easy *data, bool *done);
static CURLcode ftp_done(struct Curl_easy *data,
CURLcode, bool premature);
bool *dophase_done);
static CURLcode ftp_setup_connection(struct Curl_easy *data,
struct connectdata *conn);
-static CURLcode init_wc_data(struct Curl_easy *data);
-static CURLcode wc_statemach(struct Curl_easy *data);
+static CURLcode init_wc_data(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp);
+static CURLcode wc_statemach(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp);
static void wc_data_dtor(void *ptr);
-static CURLcode ftp_state_retr(struct Curl_easy *data, curl_off_t filesize);
+static CURLcode ftp_state_retr(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
+ curl_off_t filesize);
static CURLcode ftp_readresp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int sockindex,
struct pingpong *pp,
int *ftpcode,
size_t *size);
static CURLcode ftp_dophase_done(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool connected);
/*
};
#endif
-static void close_secondarysocket(struct Curl_easy *data)
+static void close_secondarysocket(struct Curl_easy *data,
+ struct ftp_conn *ftpc)
{
- CURL_TRC_FTP(data, "[%s] closing DATA connection", FTP_DSTATE(data));
+ (void)ftpc;
+ CURL_TRC_FTP(data, "[%s] closing DATA connection", FTP_CSTATE(ftpc));
Curl_conn_close(data, SECONDARYSOCKET);
Curl_conn_cf_discard_all(data, data->conn, SECONDARYSOCKET);
}
{
static const char nl = '\n';
struct ftp_cw_lc_ctx *ctx = writer->ctx;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
- if(!(type & CLIENTWRITE_BODY) ||
- data->conn->proto.ftpc.transfertype != 'A')
+ if(!ftpc)
+ return CURLE_FAILED_INIT;
+
+ if(!(type & CLIENTWRITE_BODY) || ftpc->transfertype != 'A')
return Curl_cwriter_write(data, writer->next, type, buf, blen);
/* ASCII mode BODY data, convert lineends */
* ftp_check_ctrl_on_data_wait()
*
*/
-static CURLcode ftp_check_ctrl_on_data_wait(struct Curl_easy *data)
+static CURLcode ftp_check_ctrl_on_data_wait(struct Curl_easy *data,
+ struct ftp_conn *ftpc)
{
struct connectdata *conn = data->conn;
curl_socket_t ctrl_sock = conn->sock[FIRSTSOCKET];
- struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
ssize_t nread;
int ftpcode;
/***********************************************************************
*
- * InitiateTransfer()
+ * ftp_initiate_transfer()
*
* After connection from server is accepted this function is called to
* setup transfer parameters and initiate the data transfer.
*
*/
-static CURLcode InitiateTransfer(struct Curl_easy *data)
+static CURLcode ftp_initiate_transfer(struct Curl_easy *data,
+ struct ftp_conn *ftpc)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
bool connected;
- CURL_TRC_FTP(data, "InitiateTransfer()");
+ CURL_TRC_FTP(data, "ftp_initiate_transfer()");
result = Curl_conn_connect(data, SECONDARYSOCKET, TRUE, &connected);
if(result || !connected)
return result;
- if(conn->proto.ftpc.state_saved == FTP_STOR) {
+ if(ftpc->state_saved == FTP_STOR) {
/* When we know we are uploading a specified file, we can get the file
size prior to the actual upload. */
Curl_pgrsSetUploadSize(data, data->state.infilesize);
/* set the SO_SNDBUF for the secondary socket for those who need it */
- Curl_sndbuf_init(conn->sock[SECONDARYSOCKET]);
+ Curl_sndbuf_init(data->conn->sock[SECONDARYSOCKET]);
/* FTP upload, shutdown DATA, ignore shutdown errors, as we rely
* on the server response on the CONTROL connection. */
else {
/* FTP download, shutdown, do not ignore errors */
Curl_xfer_setup2(data, CURL_XFER_RECV,
- conn->proto.ftpc.retr_size_saved, TRUE, FALSE);
+ ftpc->retr_size_saved, TRUE, FALSE);
}
- conn->proto.ftpc.pp.pending_resp = TRUE; /* expect server response */
- ftp_state(data, FTP_STOP);
+ ftpc->pp.pending_resp = TRUE; /* expect server response */
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OK;
}
}
static CURLcode ftp_readresp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int sockindex,
struct pingpong *pp,
int *ftpcode, /* return the ftp-code if done */
#ifdef HAVE_GSSAPI
{
struct connectdata *conn = data->conn;
- char * const buf = Curl_dyn_ptr(&data->conn->proto.ftpc.pp.recvbuf);
+ char * const buf = Curl_dyn_ptr(&ftpc->pp.recvbuf);
/* handle the security-oriented responses 6xx ***/
switch(code) {
#endif
/* store the latest code for later retrieval, except during shutdown */
- if(!data->conn->proto.ftpc.shutdown)
+ if(!ftpc->shutdown)
data->info.httpcode = code;
if(ftpcode)
* generically is a good idea.
*/
infof(data, "We got a 421 - timeout");
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OPERATION_TIMEDOUT;
}
struct connectdata *conn = data->conn;
curl_socket_t sockfd = conn->sock[FIRSTSOCKET];
CURLcode result = CURLE_OK;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
struct pingpong *pp = &ftpc->pp;
size_t nread;
int cache_skip = 0;
int value_to_be_ignored = 0;
CURL_TRC_FTP(data, "getFTPResponse start");
-
+ *nreadp = 0;
if(ftpcode)
*ftpcode = 0; /* 0 for errors */
else
/* make the pointer point to something for the rest of this function */
ftpcode = &value_to_be_ignored;
- *nreadp = 0;
+ if(!ftpc)
+ return CURLE_FAILED_INIT;
while(!*ftpcode && !result) {
/* check and reset timeout value every lap */
break;
}
- result = ftp_readresp(data, FIRSTSOCKET, pp, ftpcode, &nread);
+ result = ftp_readresp(data, ftpc, FIRSTSOCKET, pp, ftpcode, &nread);
if(result)
break;
}
static CURLcode ftp_state_user(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
struct connectdata *conn)
{
- CURLcode result = Curl_pp_sendf(data,
- &conn->proto.ftpc.pp, "USER %s",
+ CURLcode result = Curl_pp_sendf(data, &ftpc->pp, "USER %s",
conn->user ? conn->user : "");
if(!result) {
- struct ftp_conn *ftpc = &conn->proto.ftpc;
ftpc->ftp_trying_alternative = FALSE;
- ftp_state(data, FTP_USER);
+ ftp_state(data, ftpc, FTP_USER);
}
return result;
}
static CURLcode ftp_state_pwd(struct Curl_easy *data,
- struct connectdata *conn)
+ struct ftp_conn *ftpc)
{
- CURLcode result = Curl_pp_sendf(data, &conn->proto.ftpc.pp, "%s", "PWD");
+ CURLcode result = Curl_pp_sendf(data, &ftpc->pp, "%s", "PWD");
if(!result)
- ftp_state(data, FTP_PWD);
+ ftp_state(data, ftpc, FTP_PWD);
return result;
}
struct connectdata *conn,
curl_socket_t *socks)
{
- return Curl_pp_getsock(data, &conn->proto.ftpc.pp, socks);
+ struct ftp_conn *ftpc = Curl_conn_meta_get(conn, CURL_META_FTP_CONN);
+ return ftpc ? Curl_pp_getsock(data, &ftpc->pp, socks) : GETSOCK_BLANK;
}
/* For the FTP "DO_MORE" phase only */
static int ftp_domore_getsock(struct Curl_easy *data,
struct connectdata *conn, curl_socket_t *socks)
{
- struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(conn, CURL_META_FTP_CONN);
(void)data;
+ if(!ftpc)
+ return GETSOCK_BLANK;
+
/* When in DO_MORE state, we could be either waiting for us to connect to a
* remote site, or we could wait for that site to connect to us. Or just
* handle ordinary commands.
*/
- CURL_TRC_FTP(data, "[%s] ftp_domore_getsock()", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] ftp_domore_getsock()", FTP_CSTATE(ftpc));
if(FTP_STOP == ftpc->state) {
/* if stopped and still in this state, then we are also waiting for a
* via its adjust_pollset() */
return GETSOCK_READSOCK(0);
}
- return Curl_pp_getsock(data, &conn->proto.ftpc.pp, socks);
+ return Curl_pp_getsock(data, &ftpc->pp, socks);
}
/* This is called after the FTP_QUOTE state is passed.
missing ones, if that option is enabled.
*/
static CURLcode ftp_state_cwd(struct Curl_easy *data,
- struct connectdata *conn)
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
if(ftpc->cwddone)
/* already done and fine */
- result = ftp_state_mdtm(data);
+ result = ftp_state_mdtm(data, ftpc, ftp);
else {
/* FTPFILE_NOCWD with full path: expect ftpc->cwddone! */
DEBUGASSERT((data->set.ftp_filemethod != FTPFILE_NOCWD) ||
ftpc->count2 = 0; /* count2 counts failed CWDs */
- if(conn->bits.reuse && ftpc->entrypath &&
+ if(data->conn->bits.reuse && ftpc->entrypath &&
/* no need to go to entrypath when we have an absolute path */
!(ftpc->dirdepth && ftpc->dirs[0][0] == '/')) {
/* This is a reused connection. Since we change directory to where the
for all upcoming ones in the ftp->dirs[] array */
result = Curl_pp_sendf(data, &ftpc->pp, "CWD %s", ftpc->entrypath);
if(!result)
- ftp_state(data, FTP_CWD);
+ ftp_state(data, ftpc, FTP_CWD);
}
else {
if(ftpc->dirdepth) {
result = Curl_pp_sendf(data, &ftpc->pp, "CWD %s",
ftpc->dirs[ftpc->cwdcount -1]);
if(!result)
- ftp_state(data, FTP_CWD);
+ ftp_state(data, ftpc, FTP_CWD);
}
else {
/* No CWD necessary */
- result = ftp_state_mdtm(data);
+ result = ftp_state_mdtm(data, ftpc, ftp);
}
}
}
} ftpport;
static CURLcode ftp_state_use_port(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
ftpport fcmd) /* start with this */
{
CURLcode result = CURLE_FTP_PORT_FAILED;
struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
curl_socket_t portsock = CURL_SOCKET_BAD;
char myhost[MAX_IPADR_LEN + 1] = "";
goto out;
}
CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), opened socket",
- FTP_DSTATE(data));
+ FTP_CSTATE(ftpc));
/* step 3, bind to a suitable local address */
goto out;
}
CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), socket bound to port %d",
- FTP_DSTATE(data), port);
+ FTP_CSTATE(ftpc), port);
/* step 4, listen on the socket */
goto out;
}
CURL_TRC_FTP(data, "[%s] ftp_state_use_port(), listening on %d",
- FTP_DSTATE(data), port);
+ FTP_CSTATE(ftpc), port);
/* step 5, send the proper FTP command */
/* store which command was sent */
ftpc->count1 = fcmd;
- ftp_state(data, FTP_PORT);
+ ftp_state(data, ftpc, FTP_PORT);
/* Replace any filter on SECONDARY with one listening on this socket */
result = Curl_conn_tcp_listen_set(data, conn, SECONDARYSOCKET, &portsock);
if(dns_entry)
Curl_resolv_unlink(data, &dns_entry);
if(result) {
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
}
else {
/* successfully setup the list socket filter. Do we need more? */
}
static CURLcode ftp_state_use_pasv(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
struct connectdata *conn)
{
- struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result = CURLE_OK;
/*
Here's the executive summary on what to do:
result = Curl_pp_sendf(data, &ftpc->pp, "%s", mode[modeoff]);
if(!result) {
ftpc->count1 = modeoff;
- ftp_state(data, FTP_PASV);
+ ftp_state(data, ftpc, FTP_PASV);
infof(data, "Connect data stream passively");
}
return result;
* request is made. Thus, if an actual transfer is to be made this is where we
* take off for real.
*/
-static CURLcode ftp_state_prepare_transfer(struct Curl_easy *data)
+static CURLcode ftp_state_prepare_transfer(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
struct connectdata *conn = data->conn;
if(ftp->transfer != PPTRANSFER_BODY) {
/* does not transfer any data */
/* still possibly do PRE QUOTE jobs */
- ftp_state(data, FTP_RETR_PREQUOTE);
- result = ftp_state_quote(data, TRUE, FTP_RETR_PREQUOTE);
+ ftp_state(data, ftpc, FTP_RETR_PREQUOTE);
+ result = ftp_state_quote(data, ftpc, ftp, TRUE, FTP_RETR_PREQUOTE);
}
else if(data->set.ftp_use_port) {
/* We have chosen to use the PORT (or similar) command */
- result = ftp_state_use_port(data, EPRT);
+ result = ftp_state_use_port(data, ftpc, EPRT);
}
else {
/* We have chosen (this is default) to use the PASV (or similar) command */
if(data->set.ftp_use_pret) {
/* The user has requested that we send a PRET command
to prepare the server for the upcoming PASV */
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- if(!conn->proto.ftpc.file)
+ if(!ftpc->file)
result = Curl_pp_sendf(data, &ftpc->pp, "PRET %s",
data->set.str[STRING_CUSTOMREQUEST] ?
data->set.str[STRING_CUSTOMREQUEST] :
(data->state.list_only ? "NLST" : "LIST"));
else if(data->state.upload)
- result = Curl_pp_sendf(data, &ftpc->pp, "PRET STOR %s",
- conn->proto.ftpc.file);
+ result = Curl_pp_sendf(data, &ftpc->pp, "PRET STOR %s", ftpc->file);
else
- result = Curl_pp_sendf(data, &ftpc->pp, "PRET RETR %s",
- conn->proto.ftpc.file);
+ result = Curl_pp_sendf(data, &ftpc->pp, "PRET RETR %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_PRET);
+ ftp_state(data, ftpc, FTP_PRET);
}
else
- result = ftp_state_use_pasv(data, conn);
+ result = ftp_state_use_pasv(data, ftpc, conn);
}
return result;
}
static CURLcode ftp_state_rest(struct Curl_easy *data,
- struct connectdata *conn)
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
if((ftp->transfer != PPTRANSFER_BODY) && ftpc->file) {
/* if a "head"-like request is being made (on a file) */
whether it supports range */
result = Curl_pp_sendf(data, &ftpc->pp, "REST %d", 0);
if(!result)
- ftp_state(data, FTP_REST);
+ ftp_state(data, ftpc, FTP_REST);
}
else
- result = ftp_state_prepare_transfer(data);
+ result = ftp_state_prepare_transfer(data, ftpc, ftp);
return result;
}
static CURLcode ftp_state_size(struct Curl_easy *data,
- struct connectdata *conn)
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
if((ftp->transfer == PPTRANSFER_INFO) && ftpc->file) {
/* if a "head"-like request is being made (on a file) */
/* we know ftpc->file is a valid pointer to a filename */
result = Curl_pp_sendf(data, &ftpc->pp, "SIZE %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_SIZE);
+ ftp_state(data, ftpc, FTP_SIZE);
}
else
- result = ftp_state_rest(data, conn);
+ result = ftp_state_rest(data, ftpc, ftp);
return result;
}
-static CURLcode ftp_state_list(struct Curl_easy *data)
+static CURLcode ftp_state_list(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
/* If this output is to be machine-parsed, the NLST command might be better
to use, since the LIST command output is not specified or standard in any
if(!cmd)
return CURLE_OUT_OF_MEMORY;
- result = Curl_pp_sendf(data, &conn->proto.ftpc.pp, "%s", cmd);
+ result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd);
free(cmd);
if(!result)
- ftp_state(data, FTP_LIST);
+ ftp_state(data, ftpc, FTP_LIST);
return result;
}
-static CURLcode ftp_state_retr_prequote(struct Curl_easy *data)
+static CURLcode ftp_state_retr_prequote(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
/* We have sent the TYPE, now we must send the list of prequote strings */
- return ftp_state_quote(data, TRUE, FTP_RETR_PREQUOTE);
+ return ftp_state_quote(data, ftpc, ftp, TRUE, FTP_RETR_PREQUOTE);
}
-static CURLcode ftp_state_stor_prequote(struct Curl_easy *data)
+static CURLcode ftp_state_stor_prequote(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
/* We have sent the TYPE, now we must send the list of prequote strings */
- return ftp_state_quote(data, TRUE, FTP_STOR_PREQUOTE);
+ return ftp_state_quote(data, ftpc, ftp, TRUE, FTP_STOR_PREQUOTE);
}
-static CURLcode ftp_state_type(struct Curl_easy *data)
+static CURLcode ftp_state_type(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
/* If we have selected NOBODY and HEADER, it means that we only want file
information. Which in FTP cannot be much more than the file size and
date. */
if(data->req.no_body && ftpc->file &&
- ftp_need_type(conn, data->state.prefer_ascii)) {
+ ftp_need_type(ftpc, data->state.prefer_ascii)) {
/* The SIZE command is _not_ RFC 959 specified, and therefore many servers
may not support it! It is however the only way we have to get a file's
size! */
/* Some servers return different sizes for different modes, and thus we
must set the proper type before we check the size */
- result = ftp_nb_type(data, conn, data->state.prefer_ascii, FTP_TYPE);
+ result = ftp_nb_type(data, ftpc, ftp, data->state.prefer_ascii, FTP_TYPE);
if(result)
return result;
}
else
- result = ftp_state_size(data, conn);
+ result = ftp_state_size(data, ftpc, ftp);
return result;
}
/* This is called after the CWD commands have been done in the beginning of
the DO phase */
-static CURLcode ftp_state_mdtm(struct Curl_easy *data)
+static CURLcode ftp_state_mdtm(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
/* Requested time of file or time-depended transfer? */
if((data->set.get_filetime || data->set.timecondition) && ftpc->file) {
result = Curl_pp_sendf(data, &ftpc->pp, "MDTM %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_MDTM);
+ ftp_state(data, ftpc, FTP_MDTM);
}
else
- result = ftp_state_type(data);
+ result = ftp_state_type(data, ftpc, ftp);
return result;
}
/* This is called after the TYPE and possible quote commands have been sent */
static CURLcode ftp_state_ul_setup(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool sizechecked)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
- struct FTP *ftp = data->req.p.ftp;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
bool append = data->set.remote_append;
if((data->state.resume_from && !sizechecked) ||
/* Got no given size to start from, figure it out */
result = Curl_pp_sendf(data, &ftpc->pp, "SIZE %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_STOR_SIZE);
+ ftp_state(data, ftpc, FTP_STOR_SIZE);
return result;
}
* ftp_done() because we did not transfer anything! */
ftp->transfer = PPTRANSFER_NONE;
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OK;
}
}
result = Curl_pp_sendf(data, &ftpc->pp, append ? "APPE %s" : "STOR %s",
ftpc->file);
if(!result)
- ftp_state(data, FTP_STOR);
+ ftp_state(data, ftpc, FTP_STOR);
return result;
}
static CURLcode ftp_state_quote(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool init,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
bool quote = FALSE;
struct curl_slist *item;
result = Curl_pp_sendf(data, &ftpc->pp, "%s", cmd);
if(result)
return result;
- ftp_state(data, instate);
+ ftp_state(data, ftpc, instate);
quote = TRUE;
}
}
switch(instate) {
case FTP_QUOTE:
default:
- result = ftp_state_cwd(data, conn);
+ result = ftp_state_cwd(data, ftpc, ftp);
break;
case FTP_RETR_PREQUOTE:
if(ftp->transfer != PPTRANSFER_BODY)
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
else {
if(ftpc->known_filesize != -1) {
Curl_pgrsSetDownloadSize(data, ftpc->known_filesize);
- result = ftp_state_retr(data, ftpc->known_filesize);
+ result = ftp_state_retr(data, ftpc, ftp, ftpc->known_filesize);
}
else {
if(data->set.ignorecl || data->state.prefer_ascii) {
*/
result = Curl_pp_sendf(data, &ftpc->pp, "RETR %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_RETR);
+ ftp_state(data, ftpc, FTP_RETR);
}
else {
result = Curl_pp_sendf(data, &ftpc->pp, "SIZE %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_RETR_SIZE);
+ ftp_state(data, ftpc, FTP_RETR_SIZE);
}
}
}
break;
case FTP_STOR_PREQUOTE:
- result = ftp_state_ul_setup(data, FALSE);
+ result = ftp_state_ul_setup(data, ftpc, ftp, FALSE);
break;
case FTP_POSTQUOTE:
break;
/* called from ftp_state_pasv_resp to switch to PASV in case of EPSV
problems */
static CURLcode ftp_epsv_disable(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
struct connectdata *conn)
{
CURLcode result = CURLE_OK;
Curl_conn_cf_discard_all(data, conn, SECONDARYSOCKET);
data->state.errorbuf = FALSE; /* allow error message to get
rewritten */
- result = Curl_pp_sendf(data, &conn->proto.ftpc.pp, "%s", "PASV");
+ result = Curl_pp_sendf(data, &ftpc->pp, "%s", "PASV");
if(!result) {
- conn->proto.ftpc.count1++;
+ ftpc->count1++;
/* remain in/go to the FTP_PASV state */
- ftp_state(data, FTP_PASV);
+ ftp_state(data, ftpc, FTP_PASV);
}
return result;
}
}
static CURLcode ftp_state_pasv_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int ftpcode)
{
struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result;
struct Curl_dns_entry *dns = NULL;
unsigned short connectport; /* the local port connect() should use! */
}
else if(ftpc->count1 == 0) {
/* EPSV failed, move on to PASV */
- return ftp_epsv_disable(data, conn);
+ return ftp_epsv_disable(data, ftpc, conn);
}
else {
failf(data, "Bad PASV/EPSV response: %03d", ftpcode);
if(result) {
Curl_resolv_unlink(data, &dns); /* we are done using this dns entry */
if(ftpc->count1 == 0 && ftpcode == 229)
- return ftp_epsv_disable(data, conn);
+ return ftp_epsv_disable(data, ftpc, conn);
return result;
}
return CURLE_OUT_OF_MEMORY;
conn->bits.do_more = TRUE;
- ftp_state(data, FTP_STOP); /* this phase is completed */
+ ftp_state(data, ftpc, FTP_STOP); /* this phase is completed */
return result;
}
static CURLcode ftp_state_port_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode)
{
struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
ftpport fcmd = (ftpport)ftpc->count1;
CURLcode result = CURLE_OK;
}
else
/* try next */
- result = ftp_state_use_port(data, fcmd);
+ result = ftp_state_use_port(data, ftpc, fcmd);
}
else {
infof(data, "Connect data stream actively");
- ftp_state(data, FTP_STOP); /* end of DO phase */
- result = ftp_dophase_done(data, FALSE);
+ ftp_state(data, ftpc, FTP_STOP); /* end of DO phase */
+ result = ftp_dophase_done(data, ftpc, ftp, FALSE);
}
return result;
}
static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
switch(ftpcode) {
case 213:
infof(data, "The requested document is not new enough");
ftp->transfer = PPTRANSFER_NONE; /* mark to not transfer data */
data->info.timecond = TRUE;
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OK;
}
break;
infof(data, "The requested document is not old enough");
ftp->transfer = PPTRANSFER_NONE; /* mark to not transfer data */
data->info.timecond = TRUE;
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OK;
}
break;
}
if(!result)
- result = ftp_state_type(data);
+ result = ftp_state_type(data, ftpc, ftp);
return result;
}
static CURLcode ftp_state_type_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
if(ftpcode/100 != 2) {
/* "sasserftpd" and "(u)r(x)bot ftpd" both responds with 226 after a
ftpcode);
if(instate == FTP_TYPE)
- result = ftp_state_size(data, conn);
+ result = ftp_state_size(data, ftpc, ftp);
else if(instate == FTP_LIST_TYPE)
- result = ftp_state_list(data);
+ result = ftp_state_list(data, ftpc, ftp);
else if(instate == FTP_RETR_TYPE)
- result = ftp_state_retr_prequote(data);
+ result = ftp_state_retr_prequote(data, ftpc, ftp);
else if(instate == FTP_STOR_TYPE)
- result = ftp_state_stor_prequote(data);
+ result = ftp_state_stor_prequote(data, ftpc, ftp);
return result;
}
static CURLcode ftp_state_retr(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
curl_off_t filesize)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- CURL_TRC_FTP(data, "[%s] ftp_state_retr()", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] ftp_state_retr()", FTP_CSTATE(ftpc));
if(data->set.max_filesize && (filesize > data->set.max_filesize)) {
failf(data, "Maximum file size exceeded");
return CURLE_FILESIZE_EXCEEDED;
/* Set ->transfer so that we will not get any error in ftp_done()
* because we did not transfer the any file */
ftp->transfer = PPTRANSFER_NONE;
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
return CURLE_OK;
}
result = Curl_pp_sendf(data, &ftpc->pp, "REST %" FMT_OFF_T,
data->state.resume_from);
if(!result)
- ftp_state(data, FTP_RETR_REST);
+ ftp_state(data, ftpc, FTP_RETR_REST);
}
else {
/* no resume */
result = Curl_pp_sendf(data, &ftpc->pp, "RETR %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_RETR);
+ ftp_state(data, ftpc, FTP_RETR);
}
return result;
}
static CURLcode ftp_state_size_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode,
ftpstate instate)
{
CURLcode result = CURLE_OK;
curl_off_t filesize = -1;
- char *buf = Curl_dyn_ptr(&data->conn->proto.ftpc.pp.recvbuf);
- size_t len = data->conn->proto.ftpc.pp.nfinal;
+ char *buf = Curl_dyn_ptr(&ftpc->pp.recvbuf);
+ size_t len = ftpc->pp.nfinal;
/* get the size from the ascii string: */
if(ftpcode == 213) {
}
#endif
Curl_pgrsSetDownloadSize(data, filesize);
- result = ftp_state_rest(data, data->conn);
+ result = ftp_state_rest(data, ftpc, ftp);
}
else if(instate == FTP_RETR_SIZE) {
Curl_pgrsSetDownloadSize(data, filesize);
- result = ftp_state_retr(data, filesize);
+ result = ftp_state_retr(data, ftpc, ftp, filesize);
}
else if(instate == FTP_STOR_SIZE) {
data->state.resume_from = filesize;
- result = ftp_state_ul_setup(data, TRUE);
+ result = ftp_state_ul_setup(data, ftpc, ftp, TRUE);
}
return result;
}
static CURLcode ftp_state_rest_resp(struct Curl_easy *data,
- struct connectdata *conn,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
switch(instate) {
case FTP_REST:
return result;
}
#endif
- result = ftp_state_prepare_transfer(data);
+ result = ftp_state_prepare_transfer(data, ftpc, ftp);
break;
case FTP_RETR_REST:
else {
result = Curl_pp_sendf(data, &ftpc->pp, "RETR %s", ftpc->file);
if(!result)
- ftp_state(data, FTP_RETR);
+ ftp_state(data, ftpc, FTP_RETR);
}
break;
}
}
static CURLcode ftp_state_stor_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int ftpcode, ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
if(ftpcode >= 400) {
failf(data, "Failed FTP upload: %0d", ftpcode);
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
/* oops, we never close the sockets! */
return CURLE_UPLOAD_FAILED;
}
- conn->proto.ftpc.state_saved = instate;
+ ftpc->state_saved = instate;
/* PORT means we are now awaiting the server to connect to us. */
if(data->set.ftp_use_port) {
- struct ftp_conn *ftpc = &conn->proto.ftpc;
bool connected;
- ftp_state(data, FTP_STOP); /* no longer in STOR state */
+ ftp_state(data, ftpc, FTP_STOP); /* no longer in STOR state */
result = Curl_conn_connect(data, SECONDARYSOCKET, FALSE, &connected);
if(result)
if(!connected) {
infof(data, "Data conn was not available immediately");
ftpc->wait_data_conn = TRUE;
- return ftp_check_ctrl_on_data_wait(data);
+ return ftp_check_ctrl_on_data_wait(data, ftpc);
}
ftpc->wait_data_conn = FALSE;
}
- return InitiateTransfer(data);
+ return ftp_initiate_transfer(data, ftpc);
}
/* for LIST and RETR responses */
static CURLcode ftp_state_get_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
int ftpcode,
ftpstate instate)
{
CURLcode result = CURLE_OK;
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
if((ftpcode == 150) || (ftpcode == 125)) {
*
* Example D above makes this parsing a little tricky */
const char *bytes;
- char *buf = Curl_dyn_ptr(&conn->proto.ftpc.pp.recvbuf);
+ char *buf = Curl_dyn_ptr(&ftpc->pp.recvbuf);
bytes = strstr(buf, " bytes");
if(bytes) {
long in = (long)(--bytes-buf);
infof(data, "Getting file with size: %" FMT_OFF_T, size);
/* FTP download: */
- conn->proto.ftpc.state_saved = instate;
- conn->proto.ftpc.retr_size_saved = size;
+ ftpc->state_saved = instate;
+ ftpc->retr_size_saved = size;
if(data->set.ftp_use_port) {
- struct ftp_conn *ftpc = &conn->proto.ftpc;
bool connected;
result = Curl_conn_connect(data, SECONDARYSOCKET, FALSE, &connected);
if(!connected) {
infof(data, "Data conn was not available immediately");
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
ftpc->wait_data_conn = TRUE;
- return ftp_check_ctrl_on_data_wait(data);
+ return ftp_check_ctrl_on_data_wait(data, ftpc);
}
ftpc->wait_data_conn = FALSE;
}
- return InitiateTransfer(data);
+ return ftp_initiate_transfer(data, ftpc);
}
else {
if((instate == FTP_LIST) && (ftpcode == 450)) {
/* simply no matching files in the dir listing */
ftp->transfer = PPTRANSFER_NONE; /* do not download anything */
- ftp_state(data, FTP_STOP); /* this phase is over */
+ ftp_state(data, ftpc, FTP_STOP); /* this phase is over */
}
else {
failf(data, "RETR response: %03d", ftpcode);
}
/* after USER, PASS and ACCT */
-static CURLcode ftp_state_loggedin(struct Curl_easy *data)
+static CURLcode ftp_state_loggedin(struct Curl_easy *data,
+ struct ftp_conn *ftpc)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
- if(conn->bits.ftp_use_control_ssl) {
+ if(data->conn->bits.ftp_use_control_ssl) {
/* PBSZ = PROTECTION BUFFER SIZE.
The 'draft-murray-auth-ftp-ssl' (draft 12, page 7) says:
parameter of '0' to indicate that no buffering is taking place
and the data connection should not be encapsulated.
*/
- result = Curl_pp_sendf(data, &conn->proto.ftpc.pp, "PBSZ %d", 0);
+ result = Curl_pp_sendf(data, &ftpc->pp, "PBSZ %d", 0);
if(!result)
- ftp_state(data, FTP_PBSZ);
+ ftp_state(data, ftpc, FTP_PBSZ);
}
else {
- result = ftp_state_pwd(data, conn);
+ result = ftp_state_pwd(data, ftpc);
}
return result;
}
/* for USER and PASS responses */
static CURLcode ftp_state_user_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int ftpcode)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
/* some need password anyway, and others just return 2xx ignored */
if((ftpcode == 331) && (ftpc->state == FTP_USER)) {
/* 331 Password required for ...
(the server requires to send the user's password too) */
result = Curl_pp_sendf(data, &ftpc->pp, "PASS %s",
- conn->passwd ? conn->passwd : "");
+ data->conn->passwd ? data->conn->passwd : "");
if(!result)
- ftp_state(data, FTP_PASS);
+ ftp_state(data, ftpc, FTP_PASS);
}
else if(ftpcode/100 == 2) {
/* 230 User ... logged in.
(the user logged in with or without password) */
- result = ftp_state_loggedin(data);
+ result = ftp_state_loggedin(data, ftpc);
}
else if(ftpcode == 332) {
if(data->set.str[STRING_FTP_ACCOUNT]) {
result = Curl_pp_sendf(data, &ftpc->pp, "ACCT %s",
data->set.str[STRING_FTP_ACCOUNT]);
if(!result)
- ftp_state(data, FTP_ACCT);
+ ftp_state(data, ftpc, FTP_ACCT);
}
else {
failf(data, "ACCT requested but none available");
data->set.str[STRING_FTP_ALTERNATIVE_TO_USER]);
if(!result) {
ftpc->ftp_trying_alternative = TRUE;
- ftp_state(data, FTP_USER);
+ ftp_state(data, ftpc, FTP_USER);
}
}
else {
/* for ACCT response */
static CURLcode ftp_state_acct_resp(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
int ftpcode)
{
CURLcode result = CURLE_OK;
result = CURLE_FTP_WEIRD_PASS_REPLY; /* FIX */
}
else
- result = ftp_state_loggedin(data);
+ result = ftp_state_loggedin(data, ftpc);
return result;
}
-static CURLcode ftp_statemachine(struct Curl_easy *data,
- struct connectdata *conn)
+static CURLcode ftp_pp_statemachine(struct Curl_easy *data,
+ struct connectdata *conn)
{
CURLcode result;
int ftpcode;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- struct pingpong *pp = &ftpc->pp;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(conn, CURL_META_FTP_CONN);
+ struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY);
+ struct pingpong *pp;
static const char * const ftpauth[] = { "SSL", "TLS" };
size_t nread = 0;
+ if(!ftpc || !ftp)
+ return CURLE_FAILED_INIT;
+ pp = &ftpc->pp;
if(pp->sendleft)
return Curl_pp_flushsend(data, pp);
- result = ftp_readresp(data, FIRSTSOCKET, pp, &ftpcode, &nread);
+ result = ftp_readresp(data, ftpc, FIRSTSOCKET, pp, &ftpcode, &nread);
if(result)
return result;
/* 230 User logged in - already! Take as 220 if TLS required. */
if(data->set.use_ssl <= CURLUSESSL_TRY ||
conn->bits.ftp_use_control_ssl)
- return ftp_state_user_resp(data, ftpcode);
+ return ftp_state_user_resp(data, ftpc, ftpcode);
}
else if(ftpcode != 220) {
failf(data, "Got a %03d ftp-server response when 220 was expected",
result = Curl_pp_sendf(data, &ftpc->pp, "AUTH %s",
ftpauth[ftpc->count1]);
if(!result)
- ftp_state(data, FTP_AUTH);
+ ftp_state(data, ftpc, FTP_AUTH);
}
else
- result = ftp_state_user(data, conn);
+ result = ftp_state_user(data, ftpc, conn);
break;
case FTP_AUTH:
if(!result) {
conn->bits.ftp_use_data_ssl = FALSE; /* clear-text data */
conn->bits.ftp_use_control_ssl = TRUE; /* SSL on control */
- result = ftp_state_user(data, conn);
+ result = ftp_state_user(data, ftpc, conn);
}
}
else if(ftpc->count3 < 1) {
result = CURLE_USE_SSL_FAILED;
else
/* ignore the failure and continue */
- result = ftp_state_user(data, conn);
+ result = ftp_state_user(data, ftpc, conn);
}
break;
case FTP_USER:
case FTP_PASS:
- result = ftp_state_user_resp(data, ftpcode);
+ result = ftp_state_user_resp(data, ftpc, ftpcode);
break;
case FTP_ACCT:
- result = ftp_state_acct_resp(data, ftpcode);
+ result = ftp_state_acct_resp(data, ftpc, ftpcode);
break;
case FTP_PBSZ:
Curl_pp_sendf(data, &ftpc->pp, "PROT %c",
data->set.use_ssl == CURLUSESSL_CONTROL ? 'C' : 'P');
if(!result)
- ftp_state(data, FTP_PROT);
+ ftp_state(data, ftpc, FTP_PROT);
break;
case FTP_PROT:
*/
result = Curl_pp_sendf(data, &ftpc->pp, "%s", "CCC");
if(!result)
- ftp_state(data, FTP_CCC);
+ ftp_state(data, ftpc, FTP_CCC);
}
else
- result = ftp_state_pwd(data, conn);
+ result = ftp_state_pwd(data, ftpc);
break;
case FTP_CCC:
}
if(!result)
/* Then continue as normal */
- result = ftp_state_pwd(data, conn);
+ result = ftp_state_pwd(data, ftpc);
break;
case FTP_PWD:
data->state.most_recent_ftp_entrypath = strdup(ftpc->entrypath);
if(!data->state.most_recent_ftp_entrypath)
return CURLE_OUT_OF_MEMORY;
- ftp_state(data, FTP_SYST);
+ ftp_state(data, ftpc, FTP_SYST);
break;
}
infof(data, "Failed to figure out path");
}
}
- ftp_state(data, FTP_STOP); /* we are done with the CONNECT phase! */
- CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_DSTATE(data));
+ ftp_state(data, ftpc, FTP_STOP); /* we are done with CONNECT phase! */
+ CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_CSTATE(ftpc));
break;
case FTP_SYST:
/* remember target server OS */
free(ftpc->server_os);
ftpc->server_os = os;
- ftp_state(data, FTP_NAMEFMT);
+ ftp_state(data, ftpc, FTP_NAMEFMT);
break;
}
/* Nothing special for the target server. */
/* Cannot identify server OS. Continue anyway and cross fingers. */
}
- ftp_state(data, FTP_STOP); /* we are done with the CONNECT phase! */
- CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_DSTATE(data));
+ ftp_state(data, ftpc, FTP_STOP); /* we are done with CONNECT phase! */
+ CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_CSTATE(ftpc));
break;
case FTP_NAMEFMT:
if(ftpcode == 250) {
/* Name format change successful: reload initial path. */
- ftp_state_pwd(data, conn);
+ ftp_state_pwd(data, ftpc);
break;
}
- ftp_state(data, FTP_STOP); /* we are done with the CONNECT phase! */
- CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_DSTATE(data));
+ ftp_state(data, ftpc, FTP_STOP); /* we are done with CONNECT phase! */
+ CURL_TRC_FTP(data, "[%s] protocol connect phase DONE", FTP_CSTATE(ftpc));
break;
case FTP_QUOTE:
result = CURLE_QUOTE_ERROR;
}
else
- result = ftp_state_quote(data, FALSE, ftpc->state);
+ result = ftp_state_quote(data, ftpc, ftp, FALSE, ftpc->state);
break;
case FTP_CWD:
result = Curl_pp_sendf(data, &ftpc->pp, "MKD %s",
ftpc->dirs[ftpc->cwdcount - 1]);
if(!result)
- ftp_state(data, FTP_MKD);
+ ftp_state(data, ftpc, FTP_MKD);
}
else {
/* return failure */
result = Curl_pp_sendf(data, &ftpc->pp, "CWD %s",
ftpc->dirs[ftpc->cwdcount - 1]);
else
- result = ftp_state_mdtm(data);
+ result = ftp_state_mdtm(data, ftpc, ftp);
}
break;
result = CURLE_REMOTE_ACCESS_DENIED;
}
else {
- ftp_state(data, FTP_CWD);
+ ftp_state(data, ftpc, FTP_CWD);
/* send CWD */
result = Curl_pp_sendf(data, &ftpc->pp, "CWD %s",
ftpc->dirs[ftpc->cwdcount - 1]);
break;
case FTP_MDTM:
- result = ftp_state_mdtm_resp(data, ftpcode);
+ result = ftp_state_mdtm_resp(data, ftpc, ftp, ftpcode);
break;
case FTP_TYPE:
case FTP_LIST_TYPE:
case FTP_RETR_TYPE:
case FTP_STOR_TYPE:
- result = ftp_state_type_resp(data, ftpcode, ftpc->state);
+ result = ftp_state_type_resp(data, ftpc, ftp, ftpcode, ftpc->state);
break;
case FTP_SIZE:
case FTP_RETR_SIZE:
case FTP_STOR_SIZE:
- result = ftp_state_size_resp(data, ftpcode, ftpc->state);
+ result = ftp_state_size_resp(data, ftpc, ftp, ftpcode, ftpc->state);
break;
case FTP_REST:
case FTP_RETR_REST:
- result = ftp_state_rest_resp(data, conn, ftpcode, ftpc->state);
+ result = ftp_state_rest_resp(data, ftpc, ftp, ftpcode, ftpc->state);
break;
case FTP_PRET:
failf(data, "PRET command not accepted: %03d", ftpcode);
return CURLE_FTP_PRET_FAILED;
}
- result = ftp_state_use_pasv(data, conn);
+ result = ftp_state_use_pasv(data, ftpc, conn);
break;
case FTP_PASV:
- result = ftp_state_pasv_resp(data, ftpcode);
+ result = ftp_state_pasv_resp(data, ftpc, ftpcode);
break;
case FTP_PORT:
- result = ftp_state_port_resp(data, ftpcode);
+ result = ftp_state_port_resp(data, ftpc, ftp, ftpcode);
break;
case FTP_LIST:
case FTP_RETR:
- result = ftp_state_get_resp(data, ftpcode, ftpc->state);
+ result = ftp_state_get_resp(data, ftpc, ftp, ftpcode, ftpc->state);
break;
case FTP_STOR:
- result = ftp_state_stor_resp(data, ftpcode, ftpc->state);
+ result = ftp_state_stor_resp(data, ftpc, ftpcode, ftpc->state);
break;
case FTP_QUIT:
default:
/* internal error */
- ftp_state(data, FTP_STOP);
+ ftp_state(data, ftpc, FTP_STOP);
break;
}
} /* if(ftpcode) */
/* called repeatedly until done from multi.c */
-static CURLcode ftp_multi_statemach(struct Curl_easy *data,
- bool *done)
+static CURLcode ftp_statemach(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ bool *done)
{
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result = Curl_pp_statemach(data, &ftpc->pp, FALSE, FALSE);
/* Check for the state outside of the Curl_socket_check() return code checks
return result;
}
+/* called repeatedly until done from multi.c */
+static CURLcode ftp_multi_statemach(struct Curl_easy *data,
+ bool *done)
+{
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ return ftpc ? ftp_statemach(data, ftpc, done) : CURLE_FAILED_INIT;
+}
+
static CURLcode ftp_block_statemach(struct Curl_easy *data,
- struct connectdata *conn)
+ struct ftp_conn *ftpc)
{
- struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
CURLcode result = CURLE_OK;
{
CURLcode result;
struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- struct pingpong *pp = &ftpc->pp;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ struct pingpong *pp;
*done = FALSE; /* default to not done yet */
-
+ if(!ftpc)
+ return CURLE_FAILED_INIT;
+ pp = &ftpc->pp;
/* We always support persistent connections on ftp */
connkeep(conn, "FTP default");
- PINGPONG_SETUP(pp, ftp_statemachine, ftp_endofresp);
+ PINGPONG_SETUP(pp, ftp_pp_statemachine, ftp_endofresp);
if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
/* BLOCKING */
/* When we connect, we start in the state where we await the 220
response */
- ftp_state(data, FTP_WAIT220);
+ ftp_state(data, ftpc, FTP_WAIT220);
- result = ftp_multi_statemach(data, done);
+ result = ftp_statemach(data, ftpc, done);
return result;
}
bool premature)
{
struct connectdata *conn = data->conn;
- struct FTP *ftp = data->req.p.ftp;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- struct pingpong *pp = &ftpc->pp;
+ struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY);
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ struct pingpong *pp;
ssize_t nread;
int ftpcode;
CURLcode result = CURLE_OK;
char *rawPath = NULL;
size_t pathLen = 0;
- if(!ftp)
+ if(!ftp || !ftpc)
return CURLE_OK;
+ pp = &ftpc->pp;
switch(status) {
case CURLE_BAD_DOWNLOAD_RESUME:
case CURLE_FTP_WEIRD_PASV_REPLY:
}
}
- close_secondarysocket(data);
+ close_secondarysocket(data, ftpc);
}
if(!result && (ftp->transfer == PPTRANSFER_BODY) && ftpc->ctl_valid &&
connclose(conn, "Timeout or similar in FTP DONE operation"); /* close */
}
- if(result) {
- Curl_safefree(ftp->pathalloc);
+ if(result)
return result;
- }
if(ftpc->dont_check && data->req.maxdownload > 0) {
/* we have just sent ABOR and there is no reliable way to check if it was
/* Send any post-transfer QUOTE strings? */
if(!status && !result && !premature && data->set.postquote)
- result = ftp_sendquote(data, conn, data->set.postquote);
- CURL_TRC_FTP(data, "[%s] done, result=%d", FTP_DSTATE(data), result);
- Curl_safefree(ftp->pathalloc);
+ result = ftp_sendquote(data, ftpc, data->set.postquote);
+ CURL_TRC_FTP(data, "[%s] done, result=%d", FTP_CSTATE(ftpc), result);
return result;
}
static
CURLcode ftp_sendquote(struct Curl_easy *data,
- struct connectdata *conn, struct curl_slist *quote)
+ struct ftp_conn *ftpc,
+ struct curl_slist *quote)
{
struct curl_slist *item;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
struct pingpong *pp = &ftpc->pp;
item = quote;
*
* Returns TRUE if we in the current situation should send TYPE
*/
-static int ftp_need_type(struct connectdata *conn,
+static int ftp_need_type(struct ftp_conn *ftpc,
bool ascii_wanted)
{
- return conn->proto.ftpc.transfertype != (ascii_wanted ? 'A' : 'I');
+ return ftpc->transfertype != (ascii_wanted ? 'A' : 'I');
}
/***********************************************************************
* If the transfer type is not sent, simulate on OK response in newstate
*/
static CURLcode ftp_nb_type(struct Curl_easy *data,
- struct connectdata *conn,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool ascii, ftpstate newstate)
{
- struct ftp_conn *ftpc = &conn->proto.ftpc;
CURLcode result;
char want = (char)(ascii ? 'A' : 'I');
if(ftpc->transfertype == want) {
- ftp_state(data, newstate);
- return ftp_state_type_resp(data, 200, newstate);
+ ftp_state(data, ftpc, newstate);
+ return ftp_state_type_resp(data, ftpc, ftp, 200, newstate);
}
result = Curl_pp_sendf(data, &ftpc->pp, "TYPE %c", want);
if(!result) {
- ftp_state(data, newstate);
+ ftp_state(data, ftpc, newstate);
/* keep track of our current transfer type */
ftpc->transfertype = want;
static CURLcode ftp_do_more(struct Curl_easy *data, int *completep)
{
struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY);
CURLcode result = CURLE_OK;
bool connected = FALSE;
bool complete = FALSE;
-
/* the ftp struct is inited in ftp_connect(). If we are connecting to an HTTP
* proxy then the state will not be valid until after that connection is
* complete */
- struct FTP *ftp = NULL;
+ if(!ftpc || !ftp)
+ return CURLE_FAILED_INIT;
/* if the second connection has been set up, try to connect it fully
* to the remote host. This may not complete at this time, for several
* reasons:
if(result && !is_eptr && (ftpc->count1 == 0)) {
*completep = -1; /* go back to DOING please */
/* this is a EPSV connect failing, try PASV instead */
- return ftp_epsv_disable(data, conn);
+ return ftp_epsv_disable(data, ftpc, conn);
}
*completep = (int)complete;
return result;
}
}
- /* Curl_proxy_connect might have moved the protocol state */
- ftp = data->req.p.ftp;
-
if(ftpc->state) {
/* already in a state so skip the initial commands.
They are only done to kickstart the do_more state */
- result = ftp_multi_statemach(data, &complete);
+ result = ftp_statemach(data, ftpc, &complete);
*completep = (int)complete;
if(serv_conned) {
/* It looks data connection is established */
ftpc->wait_data_conn = FALSE;
- result = InitiateTransfer(data);
+ result = ftp_initiate_transfer(data, ftpc);
if(result)
return result;
connected back to us */
}
else {
- result = ftp_check_ctrl_on_data_wait(data);
+ result = ftp_check_ctrl_on_data_wait(data, ftpc);
if(result)
return result;
}
}
else if(data->state.upload) {
- result = ftp_nb_type(data, conn, data->state.prefer_ascii,
+ result = ftp_nb_type(data, ftpc, ftp, data->state.prefer_ascii,
FTP_STOR_TYPE);
if(result)
return result;
- result = ftp_multi_statemach(data, &complete);
+ result = ftp_statemach(data, ftpc, &complete);
*completep = (int)complete;
}
else {
/* But only if a body transfer was requested. */
if(ftp->transfer == PPTRANSFER_BODY) {
- result = ftp_nb_type(data, conn, TRUE, FTP_LIST_TYPE);
+ result = ftp_nb_type(data, ftpc, ftp, TRUE, FTP_LIST_TYPE);
if(result)
return result;
}
/* otherwise just fall through */
}
else {
- result = ftp_nb_type(data, conn, data->state.prefer_ascii,
+ result = ftp_nb_type(data, ftpc, ftp, data->state.prefer_ascii,
FTP_RETR_TYPE);
if(result)
return result;
}
- result = ftp_multi_statemach(data, &complete);
+ result = ftp_statemach(data, ftpc, &complete);
*completep = (int)complete;
}
return result;
if(!ftpc->wait_data_conn) {
/* no waiting for the data connection so this is now complete */
*completep = 1;
- CURL_TRC_FTP(data, "[%s] DO-MORE phase ends with %d", FTP_DSTATE(data),
+ CURL_TRC_FTP(data, "[%s] DO-MORE phase ends with %d", FTP_CSTATE(ftpc),
(int)result);
}
static
CURLcode ftp_perform(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool *connected, /* connect status after PASV / PORT */
bool *dophase_done)
{
/* this is FTP and no proxy */
CURLcode result = CURLE_OK;
- CURL_TRC_FTP(data, "[%s] DO phase starts", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] DO phase starts", FTP_CSTATE(ftpc));
if(data->req.no_body) {
/* requested no body means no transfer... */
- struct FTP *ftp = data->req.p.ftp;
ftp->transfer = PPTRANSFER_INFO;
}
*dophase_done = FALSE; /* not done yet */
/* start the first command in the DO phase */
- result = ftp_state_quote(data, TRUE, FTP_QUOTE);
+ result = ftp_state_quote(data, ftpc, ftp, TRUE, FTP_QUOTE);
if(result)
return result;
/* run the state-machine */
- result = ftp_multi_statemach(data, dophase_done);
+ result = ftp_statemach(data, ftpc, dophase_done);
*connected = Curl_conn_is_connected(data->conn, SECONDARYSOCKET);
if(*connected)
infof(data, "[FTP] [%s] perform, DATA connection established",
- FTP_DSTATE(data));
+ FTP_CSTATE(ftpc));
else
CURL_TRC_FTP(data, "[%s] perform, awaiting DATA connect",
- FTP_DSTATE(data));
+ FTP_CSTATE(ftpc));
if(*dophase_done)
- CURL_TRC_FTP(data, "[%s] DO phase is complete1", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] DO phase is complete1", FTP_CSTATE(ftpc));
return result;
}
free(ftpwc);
}
-static CURLcode init_wc_data(struct Curl_easy *data)
+static CURLcode init_wc_data(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
char *last_slash;
- struct FTP *ftp = data->req.p.ftp;
char *path = ftp->path;
struct WildcardData *wildcard = data->wildcard;
CURLcode result = CURLE_OK;
last_slash++;
if(last_slash[0] == '\0') {
wildcard->state = CURLWC_CLEAN;
- return ftp_parse_url_path(data);
+ return ftp_parse_url_path(data, ftpc, ftp);
}
wildcard->pattern = strdup(last_slash);
if(!wildcard->pattern)
}
else { /* only list */
wildcard->state = CURLWC_CLEAN;
- return ftp_parse_url_path(data);
+ return ftp_parse_url_path(data, ftpc, ftp);
}
}
data->set.ftp_filemethod = FTPFILE_MULTICWD;
/* try to parse ftp URL */
- result = ftp_parse_url_path(data);
+ result = ftp_parse_url_path(data, ftpc, ftp);
if(result) {
goto fail;
}
return result;
}
-static CURLcode wc_statemach(struct Curl_easy *data)
+static CURLcode wc_statemach(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
struct WildcardData * const wildcard = data->wildcard;
- struct connectdata *conn = data->conn;
CURLcode result = CURLE_OK;
for(;;) {
switch(wildcard->state) {
case CURLWC_INIT:
- result = init_wc_data(data);
+ result = init_wc_data(data, ftpc, ftp);
if(wildcard->state == CURLWC_CLEAN)
/* only listing! */
return result;
case CURLWC_DOWNLOADING: {
/* filelist has at least one file, lets get first one */
- struct ftp_conn *ftpc = &conn->proto.ftpc;
struct Curl_llist_node *head = Curl_llist_head(&wildcard->filelist);
struct curl_fileinfo *finfo = Curl_node_elem(head);
- struct FTP *ftp = data->req.p.ftp;
char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename);
if(!tmp_path)
if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE)
ftpc->known_filesize = finfo->size;
- result = ftp_parse_url_path(data);
+ result = ftp_parse_url_path(data, ftpc, ftp);
if(result)
return result;
static CURLcode ftp_do(struct Curl_easy *data, bool *done)
{
CURLcode result = CURLE_OK;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY);
*done = FALSE; /* default to false */
+ if(!ftpc || !ftp)
+ return CURLE_FAILED_INIT;
ftpc->wait_data_conn = FALSE; /* default to no such wait */
#ifdef CURL_PREFER_LF_LINEENDS
#endif /* CURL_PREFER_LF_LINEENDS */
if(data->state.wildcardmatch) {
- result = wc_statemach(data);
+ result = wc_statemach(data, ftpc, ftp);
if(data->wildcard->state == CURLWC_SKIP ||
data->wildcard->state == CURLWC_DONE) {
/* do not call ftp_regular_transfer */
return result;
}
else { /* no wildcard FSM needed */
- result = ftp_parse_url_path(data);
+ result = ftp_parse_url_path(data, ftpc, ftp);
if(result)
return result;
}
- result = ftp_regular_transfer(data, done);
+ result = ftp_regular_transfer(data, ftpc, ftp, done);
return result;
}
* connection.
*
*/
-static CURLcode ftp_quit(struct Curl_easy *data, struct connectdata *conn)
+static CURLcode ftp_quit(struct Curl_easy *data,
+ struct ftp_conn *ftpc)
{
CURLcode result = CURLE_OK;
- if(conn->proto.ftpc.ctl_valid) {
+ if(ftpc->ctl_valid) {
CURL_TRC_FTP(data, "sending QUIT to close session");
- result = Curl_pp_sendf(data, &conn->proto.ftpc.pp, "%s", "QUIT");
+ result = Curl_pp_sendf(data, &ftpc->pp, "%s", "QUIT");
if(result) {
failf(data, "Failure sending QUIT command: %s",
curl_easy_strerror(result));
- conn->proto.ftpc.ctl_valid = FALSE; /* mark control connection as bad */
- connclose(conn, "QUIT command failed"); /* mark for connection closure */
- ftp_state(data, FTP_STOP);
+ ftpc->ctl_valid = FALSE; /* mark control connection as bad */
+ connclose(data->conn, "QUIT command failed"); /* mark for closure */
+ ftp_state(data, ftpc, FTP_STOP);
return result;
}
- ftp_state(data, FTP_QUIT);
+ ftp_state(data, ftpc, FTP_QUIT);
- result = ftp_block_statemach(data, conn);
+ result = ftp_block_statemach(data, ftpc);
}
return result;
struct connectdata *conn,
bool dead_connection)
{
- struct ftp_conn *ftpc = &conn->proto.ftpc;
- struct pingpong *pp = &ftpc->pp;
+ struct ftp_conn *ftpc = Curl_conn_meta_get(conn, CURL_META_FTP_CONN);
+ if(!ftpc)
+ return CURLE_FAILED_INIT;
/* 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.
ftpc->ctl_valid = FALSE;
/* The FTP session may or may not have been allocated/setup at this point! */
- (void)ftp_quit(data, conn); /* ignore errors on the QUIT */
-
- freedirs(ftpc);
- Curl_safefree(ftpc->account);
- Curl_safefree(ftpc->alternative_to_user);
- Curl_safefree(ftpc->entrypath);
- Curl_safefree(ftpc->prevpath);
- Curl_safefree(ftpc->server_os);
- Curl_pp_disconnect(pp);
+ (void)ftp_quit(data, ftpc); /* ignore errors on the QUIT */
return CURLE_OK;
}
*
*/
static
-CURLcode ftp_parse_url_path(struct Curl_easy *data)
+CURLcode ftp_parse_url_path(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp)
{
- /* the ftp struct is already inited in ftp_connect() */
- struct FTP *ftp = data->req.p.ftp;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
const char *slashPos = NULL;
const char *fileName = NULL;
CURLcode result = CURLE_OK;
if((data->set.ftp_filemethod == FTPFILE_NOCWD) && (rawPath[0] == '/'))
ftpc->cwddone = TRUE; /* skip CWD for absolute paths */
else { /* newly created FTP connections are already in entry path */
- const char *oldPath = conn->bits.reuse ? ftpc->prevpath : "";
+ const char *oldPath = data->conn->bits.reuse ? ftpc->prevpath : "";
if(oldPath) {
size_t n = pathLen;
if(data->set.ftp_filemethod == FTPFILE_NOCWD)
}
/* call this when the DO phase has completed */
-static CURLcode ftp_dophase_done(struct Curl_easy *data, bool connected)
+static CURLcode ftp_dophase_done(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
+ bool connected)
{
- struct connectdata *conn = data->conn;
- struct FTP *ftp = data->req.p.ftp;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
-
if(connected) {
int completed;
CURLcode result = ftp_do_more(data, &completed);
if(result) {
- close_secondarysocket(data);
+ close_secondarysocket(data, ftpc);
return result;
}
}
Curl_xfer_setup_nop(data);
else if(!connected)
/* since we did not connect now, we want do_more to get called */
- conn->bits.do_more = TRUE;
+ data->conn->bits.do_more = TRUE;
ftpc->ctl_valid = TRUE; /* seems good */
static CURLcode ftp_doing(struct Curl_easy *data,
bool *dophase_done)
{
- CURLcode result = ftp_multi_statemach(data, dophase_done);
+ struct ftp_conn *ftpc = Curl_conn_meta_get(data->conn, CURL_META_FTP_CONN);
+ struct FTP *ftp = Curl_meta_get(data, CURL_META_FTP_EASY);
+ CURLcode result;
+
+ if(!ftpc || !ftp)
+ return CURLE_FAILED_INIT;
+ result = ftp_statemach(data, ftpc, dophase_done);
if(result)
- CURL_TRC_FTP(data, "[%s] DO phase failed", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] DO phase failed", FTP_CSTATE(ftpc));
else if(*dophase_done) {
- result = ftp_dophase_done(data, FALSE /* not connected */);
+ result = ftp_dophase_done(data, ftpc, ftp, FALSE /* not connected */);
- CURL_TRC_FTP(data, "[%s] DO phase is complete2", FTP_DSTATE(data));
+ CURL_TRC_FTP(data, "[%s] DO phase is complete2", FTP_CSTATE(ftpc));
}
return result;
}
*/
static
CURLcode ftp_regular_transfer(struct Curl_easy *data,
+ struct ftp_conn *ftpc,
+ struct FTP *ftp,
bool *dophase_done)
{
CURLcode result = CURLE_OK;
bool connected = FALSE;
- struct connectdata *conn = data->conn;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
data->req.size = -1; /* make sure this is unknown at this point */
Curl_pgrsSetUploadCounter(data, 0);
ftpc->ctl_valid = TRUE; /* starts good */
- result = ftp_perform(data,
+ result = ftp_perform(data, ftpc, ftp,
&connected, /* have we connected after PASV/PORT */
dophase_done); /* all commands in the DO-phase done? */
/* the DO phase has not completed yet */
return CURLE_OK;
- result = ftp_dophase_done(data, connected);
+ result = ftp_dophase_done(data, ftpc, ftp, connected);
if(result)
return result;
return result;
}
+static void ftp_easy_dtor(void *key, size_t klen, void *entry)
+{
+ struct FTP *ftp = entry;
+ (void)key;
+ (void)klen;
+ Curl_safefree(ftp->pathalloc);
+ free(ftp);
+}
+
+static void ftp_conn_dtor(void *key, size_t klen, void *entry)
+{
+ struct ftp_conn *ftpc = entry;
+ (void)key;
+ (void)klen;
+ freedirs(ftpc);
+ Curl_safefree(ftpc->account);
+ Curl_safefree(ftpc->alternative_to_user);
+ Curl_safefree(ftpc->entrypath);
+ Curl_safefree(ftpc->prevpath);
+ Curl_safefree(ftpc->server_os);
+ Curl_pp_disconnect(&ftpc->pp);
+ free(ftpc);
+}
+
static CURLcode ftp_setup_connection(struct Curl_easy *data,
struct connectdata *conn)
{
char *type;
struct FTP *ftp;
CURLcode result = CURLE_OK;
- struct ftp_conn *ftpc = &conn->proto.ftpc;
+ struct ftp_conn *ftpc;
+
+ ftp = calloc(1, sizeof(*ftp));
+ if(!ftp ||
+ Curl_meta_set(data, CURL_META_FTP_EASY, ftp, ftp_easy_dtor))
+ return CURLE_OUT_OF_MEMORY;
- ftp = calloc(1, sizeof(struct FTP));
- if(!ftp)
+ ftpc = calloc(1, sizeof(*ftpc));
+ if(!ftpc ||
+ Curl_conn_meta_set(conn, CURL_META_FTP_CONN, ftpc, ftp_conn_dtor))
return CURLE_OUT_OF_MEMORY;
/* clone connection related data that is FTP specific */
ftpc->account = strdup(data->set.str[STRING_FTP_ACCOUNT]);
if(!ftpc->account) {
free(ftp);
+ Curl_conn_meta_remove(conn, CURL_META_FTP_CONN);
return CURLE_OUT_OF_MEMORY;
}
}
if(!ftpc->alternative_to_user) {
Curl_safefree(ftpc->account);
free(ftp);
+ Curl_conn_meta_remove(conn, CURL_META_FTP_CONN);
return CURLE_OUT_OF_MEMORY;
}
}
- data->req.p.ftp = ftp;
ftp->path = &data->state.up.path[1]; /* do not include the initial slash */
ftpc->use_ssl = data->set.use_ssl;
ftpc->ccc = data->set.ftp_ccc;
- CURL_TRC_FTP(data, "[%s] setup connection -> %d", FTP_CSTATE(conn), result);
+ CURL_TRC_FTP(data, "[%s] setup connection -> %d", FTP_CSTATE(ftpc), result);
return result;
}
+bool ftp_conns_match(struct connectdata *needle, struct connectdata *conn)
+{
+ struct ftp_conn *nftpc = Curl_conn_meta_get(needle, CURL_META_FTP_CONN);
+ struct ftp_conn *cftpc = Curl_conn_meta_get(conn, CURL_META_FTP_CONN);
+ /* Also match ACCOUNT, ALTERNATIVE-TO-USER, USE_SSL and CCC options */
+ if(!nftpc || !cftpc ||
+ Curl_timestrcmp(nftpc->account, cftpc->account) ||
+ Curl_timestrcmp(nftpc->alternative_to_user,
+ cftpc->alternative_to_user) ||
+ (nftpc->use_ssl != cftpc->use_ssl) ||
+ (nftpc->ccc != cftpc->ccc))
+ return FALSE;
+ return TRUE;
+}
+
#endif /* CURL_DISABLE_FTP */