Curl_range: commonize FTP and FILE range handling

Closes #2205
This commit is contained in:
Max Dymond 2018-01-29 09:50:43 +00:00 committed by Daniel Stenberg
parent f02c34476d
commit e04417d98f
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
6 changed files with 135 additions and 122 deletions

View file

@ -59,6 +59,7 @@
#include "ftp.h"
#include "fileinfo.h"
#include "ftplistparser.h"
#include "curl_range.h"
#include "curl_sec.h"
#include "strtoofft.h"
#include "strcase.h"
@ -3462,62 +3463,6 @@ ftp_pasv_verbose(struct connectdata *conn,
}
#endif
/*
Check if this is a range download, and if so, set the internal variables
properly.
*/
static CURLcode ftp_range(struct connectdata *conn)
{
curl_off_t from, to;
char *ptr;
struct Curl_easy *data = conn->data;
struct ftp_conn *ftpc = &conn->proto.ftpc;
if(data->state.use_range && data->state.range) {
CURLofft from_t;
CURLofft to_t;
from_t = curlx_strtoofft(data->state.range, &ptr, 0, &from);
if(from_t == CURL_OFFT_FLOW)
return CURLE_RANGE_ERROR;
while(*ptr && (ISSPACE(*ptr) || (*ptr == '-')))
ptr++;
to_t = curlx_strtoofft(ptr, NULL, 0, &to);
if(to_t == CURL_OFFT_FLOW)
return CURLE_RANGE_ERROR;
if((to_t == CURL_OFFT_INVAL) && !from_t) {
/* X - */
data->state.resume_from = from;
DEBUGF(infof(conn->data, "FTP RANGE %" CURL_FORMAT_CURL_OFF_T
" to end of file\n", from));
}
else if(!to_t && (from_t == CURL_OFFT_INVAL)) {
/* -Y */
data->req.maxdownload = to;
data->state.resume_from = -to;
DEBUGF(infof(conn->data, "FTP RANGE the last %" CURL_FORMAT_CURL_OFF_T
" bytes\n", to));
}
else {
/* X-Y */
data->req.maxdownload = (to - from) + 1; /* include last byte */
data->state.resume_from = from;
DEBUGF(infof(conn->data, "FTP RANGE from %" CURL_FORMAT_CURL_OFF_T
" getting %" CURL_FORMAT_CURL_OFF_T " bytes\n",
from, data->req.maxdownload));
}
DEBUGF(infof(conn->data, "range-download from %" CURL_FORMAT_CURL_OFF_T
" to %" CURL_FORMAT_CURL_OFF_T ", totally %"
CURL_FORMAT_CURL_OFF_T " bytes\n",
from, to, data->req.maxdownload));
ftpc->dont_check = TRUE; /* don't check for successful transfer */
}
else
data->req.maxdownload = -1;
return CURLE_OK;
}
/*
* ftp_do_more()
*
@ -3640,7 +3585,13 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
/* download */
ftp->downloadsize = -1; /* unknown as of yet */
result = ftp_range(conn);
result = Curl_range(conn);
if(result == CURLE_OK && data->req.maxdownload >= 0) {
/* Don't check for successful transfer */
ftpc->dont_check = TRUE;
}
if(result)
;
else if(data->set.ftp_list_only || !ftpc->file) {