diff options
author | dartraiden <wowemuh@gmail.com> | 2021-02-07 18:49:47 +0300 |
---|---|---|
committer | dartraiden <wowemuh@gmail.com> | 2021-02-07 18:49:47 +0300 |
commit | 2f0eaffffe7e5d3ac074797f880480494dbcc6f3 (patch) | |
tree | 161fa6a6df8387d618530a684de9f61f58640596 /libs/libcurl/src/file.c | |
parent | 061f5621d3f64835c376a7781af86a5e5ee1145c (diff) |
libcurl: update to 7.75.0
Diffstat (limited to 'libs/libcurl/src/file.c')
-rw-r--r-- | libs/libcurl/src/file.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/libs/libcurl/src/file.c b/libs/libcurl/src/file.c index a65eb7798d..dd8a1fd12a 100644 --- a/libs/libcurl/src/file.c +++ b/libs/libcurl/src/file.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 @@ -81,13 +81,15 @@ * Forward declarations. */ -static CURLcode file_do(struct connectdata *, bool *done); -static CURLcode file_done(struct connectdata *conn, +static CURLcode file_do(struct Curl_easy *data, bool *done); +static CURLcode file_done(struct Curl_easy *data, CURLcode status, bool premature); -static CURLcode file_connect(struct connectdata *conn, bool *done); -static CURLcode file_disconnect(struct connectdata *conn, +static CURLcode file_connect(struct Curl_easy *data, bool *done); +static CURLcode file_disconnect(struct Curl_easy *data, + struct connectdata *conn, bool dead_connection); -static CURLcode file_setup_connection(struct connectdata *conn); +static CURLcode file_setup_connection(struct Curl_easy *data, + struct connectdata *conn); /* * FILE scheme handler. @@ -116,11 +118,13 @@ const struct Curl_handler Curl_handler_file = { }; -static CURLcode file_setup_connection(struct connectdata *conn) +static CURLcode file_setup_connection(struct Curl_easy *data, + struct connectdata *conn) { + (void)conn; /* allocate the FILE specific struct */ - conn->data->req.p.file = calloc(1, sizeof(struct FILEPROTO)); - if(!conn->data->req.p.file) + data->req.p.file = calloc(1, sizeof(struct FILEPROTO)); + if(!data->req.p.file) return CURLE_OUT_OF_MEMORY; return CURLE_OK; @@ -131,9 +135,8 @@ static CURLcode file_setup_connection(struct connectdata *conn) * do protocol-specific actions at connect-time. We emulate a * connect-then-transfer protocol and "connect" to the file here */ -static CURLcode file_connect(struct connectdata *conn, bool *done) +static CURLcode file_connect(struct Curl_easy *data, bool *done) { - struct Curl_easy *data = conn->data; char *real_path; struct FILEPROTO *file = data->req.p.file; int fd; @@ -198,7 +201,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) file->fd = fd; if(!data->set.upload && (fd == -1)) { failf(data, "Couldn't open file %s", data->state.up.path); - file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); + file_done(data, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } *done = TRUE; @@ -206,10 +209,10 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) return CURLE_OK; } -static CURLcode file_done(struct connectdata *conn, - CURLcode status, bool premature) +static CURLcode file_done(struct Curl_easy *data, + CURLcode status, bool premature) { - struct FILEPROTO *file = conn->data->req.p.file; + struct FILEPROTO *file = data->req.p.file; (void)status; /* not used */ (void)premature; /* not used */ @@ -224,11 +227,13 @@ static CURLcode file_done(struct connectdata *conn, return CURLE_OK; } -static CURLcode file_disconnect(struct connectdata *conn, +static CURLcode file_disconnect(struct Curl_easy *data, + struct connectdata *conn, bool dead_connection) { (void)dead_connection; /* not used */ - return file_done(conn, 0, 0); + (void)conn; + return file_done(data, 0, 0); } #ifdef DOS_FILESYSTEM @@ -237,14 +242,13 @@ static CURLcode file_disconnect(struct connectdata *conn, #define DIRSEP '/' #endif -static CURLcode file_upload(struct connectdata *conn) +static CURLcode file_upload(struct Curl_easy *data) { - struct FILEPROTO *file = conn->data->req.p.file; + struct FILEPROTO *file = data->req.p.file; const char *dir = strchr(file->path, DIRSEP); int fd; int mode; CURLcode result = CURLE_OK; - struct Curl_easy *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; struct_stat file_stat; @@ -254,7 +258,7 @@ static CURLcode file_upload(struct connectdata *conn) * Since FILE: doesn't do the full init, we need to provide some extra * assignments here. */ - conn->data->req.upload_fromhere = buf; + data->req.upload_fromhere = buf; if(!dir) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ @@ -273,7 +277,7 @@ static CURLcode file_upload(struct connectdata *conn) else mode = MODE_DEFAULT|O_TRUNC; - fd = open(file->path, mode, conn->data->set.new_file_perms); + fd = open(file->path, mode, data->set.new_file_perms); if(fd < 0) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; @@ -297,7 +301,7 @@ static CURLcode file_upload(struct connectdata *conn) size_t nread; size_t nwrite; size_t readcount; - result = Curl_fillreadbuffer(conn, data->set.buffer_size, &readcount); + result = Curl_fillreadbuffer(data, data->set.buffer_size, &readcount); if(result) break; @@ -333,12 +337,12 @@ static CURLcode file_upload(struct connectdata *conn) Curl_pgrsSetUploadCounter(data, bytecount); - if(Curl_pgrsUpdate(conn)) + if(Curl_pgrsUpdate(data)) result = CURLE_ABORTED_BY_CALLBACK; else result = Curl_speedcheck(data, Curl_now()); } - if(!result && Curl_pgrsUpdate(conn)) + if(!result && Curl_pgrsUpdate(data)) result = CURLE_ABORTED_BY_CALLBACK; close(fd); @@ -354,7 +358,7 @@ static CURLcode file_upload(struct connectdata *conn) * opposed to sockets) we instead perform the whole do-operation in this * function. */ -static CURLcode file_do(struct connectdata *conn, bool *done) +static CURLcode file_do(struct Curl_easy *data, bool *done) { /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) @@ -365,10 +369,9 @@ static CURLcode file_do(struct connectdata *conn, bool *done) struct_stat statbuf; /* struct_stat instead of struct stat just to allow the Windows version to have a different struct without having to redefine the simple word 'stat' */ - curl_off_t expected_size = 0; + curl_off_t expected_size = -1; bool size_known; bool fstated = FALSE; - struct Curl_easy *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; int fd; @@ -379,17 +382,17 @@ static CURLcode file_do(struct connectdata *conn, bool *done) Curl_pgrsStartNow(data); if(data->set.upload) - return file_upload(conn); + return file_upload(data); - file = conn->data->req.p.file; + file = data->req.p.file; /* get the fd from the connection phase */ fd = file->fd; /* VMS: This only works reliable for STREAMLF files */ if(-1 != fstat(fd, &statbuf)) { - /* we could stat it, then read out the size */ - expected_size = statbuf.st_size; + if(!S_ISDIR(statbuf.st_mode)) + expected_size = statbuf.st_size; /* and store the modification time */ data->info.filetime = statbuf.st_mtime; fstated = TRUE; @@ -407,14 +410,16 @@ static CURLcode file_do(struct connectdata *conn, bool *done) struct tm buffer; const struct tm *tm = &buffer; char header[80]; - msnprintf(header, sizeof(header), - "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", - expected_size); - result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0); - if(result) - return result; + if(expected_size >= 0) { + msnprintf(header, sizeof(header), + "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", + expected_size); + result = Curl_client_write(data, CLIENTWRITE_HEADER, header, 0); + if(result) + return result; + } - result = Curl_client_write(conn, CLIENTWRITE_HEADER, + result = Curl_client_write(data, CLIENTWRITE_HEADER, (char *)"Accept-ranges: bytes\r\n", 0); if(result) return result; @@ -435,7 +440,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) tm->tm_min, tm->tm_sec, data->set.opt_no_body ? "": "\r\n"); - result = Curl_client_write(conn, CLIENTWRITE_HEADER, header, 0); + result = Curl_client_write(data, CLIENTWRITE_HEADER, header, 0); if(result) return result; /* set the file size to make it available post transfer */ @@ -445,7 +450,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) } /* Check whether file range has been specified */ - result = Curl_range(conn); + result = Curl_range(data); if(result) return result; @@ -514,18 +519,18 @@ static CURLcode file_do(struct connectdata *conn, bool *done) if(size_known) expected_size -= nread; - result = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread); + result = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread); if(result) return result; Curl_pgrsSetDownloadCounter(data, bytecount); - if(Curl_pgrsUpdate(conn)) + if(Curl_pgrsUpdate(data)) result = CURLE_ABORTED_BY_CALLBACK; else result = Curl_speedcheck(data, Curl_now()); } - if(Curl_pgrsUpdate(conn)) + if(Curl_pgrsUpdate(data)) result = CURLE_ABORTED_BY_CALLBACK; return result; |