From ae1912cb0d494b48d514d937826c9fe83ec96c4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Dec 1999 14:20:26 +0000 Subject: Initial revision --- lib/file.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 lib/file.c (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c new file mode 100644 index 000000000..b5d198e57 --- /dev/null +++ b/lib/file.c @@ -0,0 +1,175 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Curl. + * + * The Initial Developer of the Original Code is Daniel Stenberg. + * + * Portions created by the Initial Developer are Copyright (C) 1999. + * All Rights Reserved. + * + * ------------------------------------------------------------ + * Main author: + * - Daniel Stenberg + * + * http://curl.haxx.nu + * + * $Source$ + * $Revision$ + * $Date$ + * $Author$ + * $State$ + * $Locker$ + * + * ------------------------------------------------------------ + ****************************************************************************/ + +/* -- WIN32 approved -- */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "setup.h" + +#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#include +#include +#include +#include +#else +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#ifdef HAVE_ARPA_INET_H +#include +#endif +#ifdef HAVE_NET_IF_H +#include +#endif +#include +#include + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif +#ifdef HAVE_FCNTL_H +#include +#endif + + +#endif + +#include "urldata.h" +#include +#include "progress.h" +#include "sendf.h" +#include "escape.h" + +#define _MPRINTF_REPLACE /* use our functions only */ +#include + + +UrgError file(struct UrlData *data, char *path, long *bytecountp) +{ + /* This implementation ignores the host name in conformance with + RFC 1738. Only local files (reachable via the standard file system) + are supported. This means that files on remotely mounted directories + (via NFS, Samba, NT sharing) can be accessed through a file:// URL + */ + + struct stat statbuf; + size_t expected_size=-1; + size_t nread; + char *buf = data->buffer; + int bytecount = 0; + struct timeval start = tvnow(); + struct timeval now = start; + int fd; + char *actual_path = curl_unescape(path); + +#ifdef WIN32 + int i; + + /* change path separators from '/' to '\\' for Windows */ + for (i=0; actual_path[i] != '\0'; ++i) + if (actual_path[i] == '/') + actual_path[i] = '\\'; + + fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ +#else + fd = open(actual_path, O_RDONLY); +#endif + free(actual_path); + + if(fd == -1) { + failf(data, "Couldn't open file %s", path); + return URG_FILE_COULDNT_READ_FILE; + } + if( -1 != fstat(fd, &statbuf)) { + /* we could stat it, then read out the size */ + expected_size = statbuf.st_size; + } + + /* The following is a shortcut implementation of file reading + this is both more efficient than the former call to download() and + it avoids problems with select() and recv() on file descriptors + in Winsock */ + ProgressInit (data, expected_size); + while (1) { + nread = read(fd, buf, BUFSIZE-1); + + if (0 <= nread) + buf[nread] = 0; + + if (nread <= 0) + break; + bytecount += nread; + /* NOTE: The following call to fwrite does CR/LF translation on + Windows systems if the target is stdout. Use -O or -o parameters + to prevent CR/LF translation (this then goes to a binary mode + file descriptor). */ + if(nread != data->fwrite (buf, 1, nread, data->out)) { + failf (data, "Failed writing output"); + return URG_WRITE_ERROR; + } + now = tvnow(); + ProgressShow (data, bytecount, start, now, FALSE); + } + now = tvnow(); + ProgressShow (data, bytecount, start, now, TRUE); + + close(fd); + + return URG_OK; +} -- cgit v1.2.1 From 5a99be254566758d8ff42d905cad98b1ee7a2e87 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 14 Feb 2000 22:57:42 +0000 Subject: updated to use the new set of progress-functions --- lib/file.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b5d198e57..99759f477 100644 --- a/lib/file.c +++ b/lib/file.c @@ -145,7 +145,12 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors in Winsock */ +#if 0 ProgressInit (data, expected_size); +#endif + if(expected_size != -1) + pgrsSetDownloadSize(data, expected_size); + while (1) { nread = read(fd, buf, BUFSIZE-1); @@ -164,10 +169,16 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) return URG_WRITE_ERROR; } now = tvnow(); + pgrsUpdate(data); +#if 0 ProgressShow (data, bytecount, start, now, FALSE); +#endif } now = tvnow(); +#if 0 ProgressShow (data, bytecount, start, now, TRUE); +#endif + pgrsUpdate(data); close(fd); -- cgit v1.2.1 From ff3fd842d8338feb5277a0450991c882dd4d84b2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 19 Mar 2000 19:54:13 +0000 Subject: Marco G. Salvagno's OS/2 fixes --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 99759f477..af966016b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -118,10 +118,10 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) int fd; char *actual_path = curl_unescape(path); -#ifdef WIN32 +#if defined(WIN32) || defined(__EMX__) int i; - /* change path separators from '/' to '\\' for Windows */ + /* change path separators from '/' to '\\' for Windows and OS/2 */ for (i=0; actual_path[i] != '\0'; ++i) if (actual_path[i] == '/') actual_path[i] = '\\'; -- cgit v1.2.1 From 96dde76b99897352aa3d0877a0b621a9e605733e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 May 2000 14:12:12 +0000 Subject: moved here from the newlib branch --- lib/file.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index af966016b..532a65fb3 100644 --- a/lib/file.c +++ b/lib/file.c @@ -100,23 +100,25 @@ #include -UrgError file(struct UrlData *data, char *path, long *bytecountp) +CURLcode file(struct connectdata *conn) { /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) are supported. This means that files on remotely mounted directories (via NFS, Samba, NT sharing) can be accessed through a file:// URL */ - + CURLcode res = CURLE_OK; + char *path = conn->path; struct stat statbuf; size_t expected_size=-1; size_t nread; + struct UrlData *data = conn->data; char *buf = data->buffer; int bytecount = 0; struct timeval start = tvnow(); struct timeval now = start; int fd; - char *actual_path = curl_unescape(path); + char *actual_path = curl_unescape(path, 0); #if defined(WIN32) || defined(__EMX__) int i; @@ -134,7 +136,7 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) if(fd == -1) { failf(data, "Couldn't open file %s", path); - return URG_FILE_COULDNT_READ_FILE; + return CURLE_FILE_COULDNT_READ_FILE; } if( -1 != fstat(fd, &statbuf)) { /* we could stat it, then read out the size */ @@ -151,7 +153,7 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) if(expected_size != -1) pgrsSetDownloadSize(data, expected_size); - while (1) { + while (res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); if (0 <= nread) @@ -166,21 +168,19 @@ UrgError file(struct UrlData *data, char *path, long *bytecountp) file descriptor). */ if(nread != data->fwrite (buf, 1, nread, data->out)) { failf (data, "Failed writing output"); - return URG_WRITE_ERROR; + return CURLE_WRITE_ERROR; } now = tvnow(); - pgrsUpdate(data); -#if 0 - ProgressShow (data, bytecount, start, now, FALSE); -#endif + if(pgrsUpdate(data)) + res = CURLE_ABORTED_BY_CALLBACK; } now = tvnow(); -#if 0 - ProgressShow (data, bytecount, start, now, TRUE); -#endif - pgrsUpdate(data); + if(pgrsUpdate(data)) + res = CURLE_ABORTED_BY_CALLBACK; close(fd); - return URG_OK; + free(actual_path); + + return res; } -- cgit v1.2.1 From 1ef3600a0731fef8f59563a1e49981f1b64b9746 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 20 Jun 2000 15:31:26 +0000 Subject: haxx.nu => haxx.se --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 532a65fb3..3b6aec63d 100644 --- a/lib/file.c +++ b/lib/file.c @@ -24,9 +24,9 @@ * * ------------------------------------------------------------ * Main author: - * - Daniel Stenberg + * - Daniel Stenberg * - * http://curl.haxx.nu + * http://curl.haxx.se * * $Source$ * $Revision$ -- cgit v1.2.1 From d4731b70505d308064e85bfa1ea1f88904442af2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 23 Aug 2000 07:23:42 +0000 Subject: Albert Chin-A-Young's fixes --- lib/file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3b6aec63d..53e704f6b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -60,13 +60,17 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_NETINET_IN_H #include +#endif #include #include #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_NETDB_H #include +#endif #ifdef HAVE_ARPA_INET_H #include #endif -- cgit v1.2.1 From b6e18f2f665f16910c04cb52bdc7b90270ab7c9b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Aug 2000 14:26:33 +0000 Subject: #include "setup.h" moved first of all includes --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 53e704f6b..46827f0a2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -38,6 +38,8 @@ * ------------------------------------------------------------ ****************************************************************************/ +#include "setup.h" + /* -- WIN32 approved -- */ #include #include @@ -49,8 +51,6 @@ #include -#include "setup.h" - #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) #include #include -- cgit v1.2.1 From 460aa295e016a2e131cf79cc52a8e84ac0cacfda Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 Nov 2000 07:51:23 +0000 Subject: Chris Faherty fixed a free-twice problem --- lib/file.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 46827f0a2..26d31914c 100644 --- a/lib/file.c +++ b/lib/file.c @@ -184,7 +184,5 @@ CURLcode file(struct connectdata *conn) close(fd); - free(actual_path); - return res; } -- cgit v1.2.1 From fb962a281e97c517814a473763c3f9d3115b3964 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 22 Nov 2000 12:51:18 +0000 Subject: uses the new client_write() function --- lib/file.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 26d31914c..6121e1e57 100644 --- a/lib/file.c +++ b/lib/file.c @@ -170,10 +170,11 @@ CURLcode file(struct connectdata *conn) Windows systems if the target is stdout. Use -O or -o parameters to prevent CR/LF translation (this then goes to a binary mode file descriptor). */ - if(nread != data->fwrite (buf, 1, nread, data->out)) { - failf (data, "Failed writing output"); - return CURLE_WRITE_ERROR; - } + + res = client_write(data, CLIENTWRITE_BODY, buf, nread); + if(res) + return res; + now = tvnow(); if(pgrsUpdate(data)) res = CURLE_ABORTED_BY_CALLBACK; -- cgit v1.2.1 From 79a84d20f20ebc17bae21bac05a8296cd8e24779 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 27 Nov 2000 12:04:51 +0000 Subject: Added the memdebug include file --- lib/file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6121e1e57..233f02472 100644 --- a/lib/file.c +++ b/lib/file.c @@ -103,6 +103,10 @@ #define _MPRINTF_REPLACE /* use our functions only */ #include +/* The last #include file should be: */ +#ifdef MALLOCDEBUG +#include "memdebug.h" +#endif CURLcode file(struct connectdata *conn) { -- cgit v1.2.1 From 64761bc7868d8ef63aa90a7995ed81daa10f5877 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Nov 2000 08:17:12 +0000 Subject: removed #if 0 section --- lib/file.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 233f02472..997b6fff3 100644 --- a/lib/file.c +++ b/lib/file.c @@ -155,9 +155,6 @@ CURLcode file(struct connectdata *conn) this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors in Winsock */ -#if 0 - ProgressInit (data, expected_size); -#endif if(expected_size != -1) pgrsSetDownloadSize(data, expected_size); -- cgit v1.2.1 From 24dee483e9e925c2ab79dd582f70c9a55ab9ba4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 3 Jan 2001 09:29:33 +0000 Subject: dual-license fix --- lib/file.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 997b6fff3..33dc09f4e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,38 +5,21 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * The contents of this file are subject to the Mozilla Public License - * Version 1.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ + * Copyright (C) 2000, Daniel Stenberg, , et al. * - * Software distributed under the License is distributed on an "AS IS" - * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the - * License for the specific language governing rights and limitations - * under the License. + * In order to be useful for every potential user, curl and libcurl are + * dual-licensed under the MPL and the MIT/X-derivate licenses. * - * The Original Code is Curl. + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the MPL or the MIT/X-derivate + * licenses. You may pick one of these licenses. * - * The Initial Developer of the Original Code is Daniel Stenberg. + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. * - * Portions created by the Initial Developer are Copyright (C) 1999. - * All Rights Reserved. - * - * ------------------------------------------------------------ - * Main author: - * - Daniel Stenberg - * - * http://curl.haxx.se - * - * $Source$ - * $Revision$ - * $Date$ - * $Author$ - * $State$ - * $Locker$ - * - * ------------------------------------------------------------ - ****************************************************************************/ + * $Id$ + *****************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 4031104404c6ceed5e57134125dcdb6cac51c564 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Jan 2001 10:11:41 +0000 Subject: Internal symbols that aren't static are now prefixed with 'Curl_' --- lib/file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 33dc09f4e..12823812a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -106,7 +106,7 @@ CURLcode file(struct connectdata *conn) struct UrlData *data = conn->data; char *buf = data->buffer; int bytecount = 0; - struct timeval start = tvnow(); + struct timeval start = Curl_tvnow(); struct timeval now = start; int fd; char *actual_path = curl_unescape(path, 0); @@ -139,7 +139,7 @@ CURLcode file(struct connectdata *conn) it avoids problems with select() and recv() on file descriptors in Winsock */ if(expected_size != -1) - pgrsSetDownloadSize(data, expected_size); + Curl_pgrsSetDownloadSize(data, expected_size); while (res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); @@ -155,16 +155,16 @@ CURLcode file(struct connectdata *conn) to prevent CR/LF translation (this then goes to a binary mode file descriptor). */ - res = client_write(data, CLIENTWRITE_BODY, buf, nread); + res = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread); if(res) return res; - now = tvnow(); - if(pgrsUpdate(data)) + now = Curl_tvnow(); + if(Curl_pgrsUpdate(data)) res = CURLE_ABORTED_BY_CALLBACK; } - now = tvnow(); - if(pgrsUpdate(data)) + now = Curl_tvnow(); + if(Curl_pgrsUpdate(data)) res = CURLE_ABORTED_BY_CALLBACK; close(fd); -- cgit v1.2.1 From 84e94fda8ba36c77c80e012c52ad36a4a59de6a7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Mar 2001 13:39:01 +0000 Subject: remade FILE:// support to look more as the other protocols --- lib/file.c | 58 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 18 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 12823812a..f04b1e65e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -91,25 +91,19 @@ #include "memdebug.h" #endif -CURLcode file(struct connectdata *conn) +/* Emulate a connect-then-transfer protocol. We connect to the file here */ +CURLcode Curl_file_connect(struct connectdata *conn) { - /* This implementation ignores the host name in conformance with - RFC 1738. Only local files (reachable via the standard file system) - are supported. This means that files on remotely mounted directories - (via NFS, Samba, NT sharing) can be accessed through a file:// URL - */ - CURLcode res = CURLE_OK; - char *path = conn->path; - struct stat statbuf; - size_t expected_size=-1; - size_t nread; - struct UrlData *data = conn->data; - char *buf = data->buffer; - int bytecount = 0; - struct timeval start = Curl_tvnow(); - struct timeval now = start; + char *actual_path = curl_unescape(conn->path, 0); + struct FILE *file; int fd; - char *actual_path = curl_unescape(path, 0); + + file = (struct FILE *)malloc(sizeof(struct FILE)); + if(!file) + return CURLE_OUT_OF_MEMORY; + + memset(file, 0, sizeof(struct FILE)); + conn->proto.file = file; #if defined(WIN32) || defined(__EMX__) int i; @@ -126,9 +120,37 @@ CURLcode file(struct connectdata *conn) free(actual_path); if(fd == -1) { - failf(data, "Couldn't open file %s", path); + failf(conn->data, "Couldn't open file %s", conn->path); return CURLE_FILE_COULDNT_READ_FILE; } + file->fd = fd; + + return CURLE_OK; +} + +/* This is the do-phase, separated from the connect-phase above */ + +CURLcode Curl_file(struct connectdata *conn) +{ + /* This implementation ignores the host name in conformance with + RFC 1738. Only local files (reachable via the standard file system) + are supported. This means that files on remotely mounted directories + (via NFS, Samba, NT sharing) can be accessed through a file:// URL + */ + CURLcode res = CURLE_OK; + struct stat statbuf; + size_t expected_size=-1; + size_t nread; + struct UrlData *data = conn->data; + char *buf = data->buffer; + int bytecount = 0; + struct timeval start = Curl_tvnow(); + struct timeval now = start; + int fd; + + /* get the fd from the connection phase */ + fd = conn->proto.file->fd; + if( -1 != fstat(fd, &statbuf)) { /* we could stat it, then read out the size */ expected_size = statbuf.st_size; -- cgit v1.2.1 From 0a1e002ca48277401b565abf97eec04fb5866d3a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 14 Mar 2001 08:28:19 +0000 Subject: =?UTF-8?q?J=F6rn=20fixed=20it=20to=20compile=20on=20win32=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index f04b1e65e..516659662 100644 --- a/lib/file.c +++ b/lib/file.c @@ -97,6 +97,9 @@ CURLcode Curl_file_connect(struct connectdata *conn) char *actual_path = curl_unescape(conn->path, 0); struct FILE *file; int fd; +#if defined(WIN32) || defined(__EMX__) + int i; +#endif file = (struct FILE *)malloc(sizeof(struct FILE)); if(!file) @@ -106,8 +109,6 @@ CURLcode Curl_file_connect(struct connectdata *conn) conn->proto.file = file; #if defined(WIN32) || defined(__EMX__) - int i; - /* change path separators from '/' to '\\' for Windows and OS/2 */ for (i=0; actual_path[i] != '\0'; ++i) if (actual_path[i] == '/') -- cgit v1.2.1 From 3fd65fb7d83a8e3e6acd1a40c48b46088ebd536f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 18 Apr 2001 07:25:11 +0000 Subject: Remade resume stuff to keep data in the connectdata struct instead of the main handle struct to work with persistant connections --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 516659662..452980f54 100644 --- a/lib/file.c +++ b/lib/file.c @@ -183,11 +183,11 @@ CURLcode Curl_file(struct connectdata *conn) return res; now = Curl_tvnow(); - if(Curl_pgrsUpdate(data)) + if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; } now = Curl_tvnow(); - if(Curl_pgrsUpdate(data)) + if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; close(fd); -- cgit v1.2.1 From 1400561a5a52154ef0188865c059f874a65ee6f8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 6 Aug 2001 12:17:43 +0000 Subject: VMS #ifdefs added. several related to size_t problems that we must address globally anyway... check these as soon as the size_t fixes are in place --- lib/file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 452980f54..1ce341b29 100644 --- a/lib/file.c +++ b/lib/file.c @@ -152,6 +152,7 @@ CURLcode Curl_file(struct connectdata *conn) /* get the fd from the connection phase */ fd = conn->proto.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; @@ -161,16 +162,24 @@ CURLcode Curl_file(struct connectdata *conn) this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors in Winsock */ +#ifdef VMS + if((signed int)expected_size != -1) +#else if(expected_size != -1) +#endif Curl_pgrsSetDownloadSize(data, expected_size); while (res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); - if (0 <= nread) + if ( nread > 0) buf[nread] = 0; +#ifdef VMS + if ((signed int)nread <= 0) +#else if (nread <= 0) +#endif break; bytecount += nread; /* NOTE: The following call to fwrite does CR/LF translation on -- cgit v1.2.1 From e9e5197cea5de8618ef229ee04b9284cbf58ff00 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 14 Aug 2001 08:22:27 +0000 Subject: size_t => ssize_t, removed the special VMS fix for that purpose --- lib/file.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1ce341b29..c3e2ceba7 100644 --- a/lib/file.c +++ b/lib/file.c @@ -140,8 +140,8 @@ CURLcode Curl_file(struct connectdata *conn) */ CURLcode res = CURLE_OK; struct stat statbuf; - size_t expected_size=-1; - size_t nread; + ssize_t expected_size=-1; + ssize_t nread; struct UrlData *data = conn->data; char *buf = data->buffer; int bytecount = 0; @@ -162,11 +162,7 @@ CURLcode Curl_file(struct connectdata *conn) this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors in Winsock */ -#ifdef VMS - if((signed int)expected_size != -1) -#else if(expected_size != -1) -#endif Curl_pgrsSetDownloadSize(data, expected_size); while (res == CURLE_OK) { @@ -175,12 +171,9 @@ CURLcode Curl_file(struct connectdata *conn) if ( nread > 0) buf[nread] = 0; -#ifdef VMS - if ((signed int)nread <= 0) -#else if (nread <= 0) -#endif break; + bytecount += nread; /* NOTE: The following call to fwrite does CR/LF translation on Windows systems if the target is stdout. Use -O or -o parameters -- cgit v1.2.1 From 0ece1b5c34c049a3226f7dd793cf75e470c46e4d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 30 Aug 2001 22:48:34 +0000 Subject: Major rename and redesign of the internal "backbone" structs. Details will be posted in a minute to the libcurl list. --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index c3e2ceba7..2b95d55aa 100644 --- a/lib/file.c +++ b/lib/file.c @@ -142,8 +142,8 @@ CURLcode Curl_file(struct connectdata *conn) struct stat statbuf; ssize_t expected_size=-1; ssize_t nread; - struct UrlData *data = conn->data; - char *buf = data->buffer; + struct SessionHandle *data = conn->data; + char *buf = data->state.buffer; int bytecount = 0; struct timeval start = Curl_tvnow(); struct timeval now = start; -- cgit v1.2.1 From 6147879837a53d22c9be04e7a4fc315a297ba2b3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Fri, 7 Sep 2001 04:01:32 +0000 Subject: Added formatting sections for emacs and vim --- lib/file.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 2b95d55aa..1c9c6ba5f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -196,3 +196,11 @@ CURLcode Curl_file(struct connectdata *conn) return res; } + +/* + * local variables: + * eval: (load-file "../curl-mode.el") + * end: + * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker + * vim<600: et sw=2 ts=2 sts=2 tw=78 + */ -- cgit v1.2.1 From 8e91d5de8e4e17ce3d4936cc91171d09726e7bb3 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Thu, 11 Oct 2001 09:32:19 +0000 Subject: looks nicer and is better compatible with older vim versions --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1c9c6ba5f..2f2b1398d 100644 --- a/lib/file.c +++ b/lib/file.c @@ -201,6 +201,6 @@ CURLcode Curl_file(struct connectdata *conn) * local variables: * eval: (load-file "../curl-mode.el") * end: - * vim600: et sw=2 ts=2 sts=2 tw=78 fdm=marker - * vim<600: et sw=2 ts=2 sts=2 tw=78 + * vim600: fdm=marker + * vim: et sw=2 ts=2 sts=2 tw=78 */ -- cgit v1.2.1 From 974f314f5785156af6983675aeb28313cc8ba2ea Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 19 Mar 2002 07:54:55 +0000 Subject: copyright string (year) update --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 2f2b1398d..e84cd4ce2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2000, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * * In order to be useful for every potential user, curl and libcurl are * dual-licensed under the MPL and the MIT/X-derivate licenses. -- cgit v1.2.1 From 192606bc4b4f8ab45aff24b33f01b7af1e4d4704 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Apr 2002 23:54:43 +0000 Subject: use double where it is supposed to --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e84cd4ce2..4515d9d94 100644 --- a/lib/file.c +++ b/lib/file.c @@ -140,7 +140,7 @@ CURLcode Curl_file(struct connectdata *conn) */ CURLcode res = CURLE_OK; struct stat statbuf; - ssize_t expected_size=-1; + double expected_size=-1; ssize_t nread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; @@ -155,7 +155,7 @@ CURLcode Curl_file(struct connectdata *conn) /*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; + expected_size = (double)statbuf.st_size; } /* The following is a shortcut implementation of file reading -- cgit v1.2.1 From 08ef208fb78fb2eabc5cec08c23e74e251eac898 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 Jun 2002 11:13:01 +0000 Subject: added disable-[protocol] support, largely provided by Miklos Nemeth --- lib/file.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4515d9d94..b3ab757fd 100644 --- a/lib/file.c +++ b/lib/file.c @@ -23,6 +23,7 @@ #include "setup.h" +#ifndef CURL_DISABLE_FILE /* -- WIN32 approved -- */ #include #include @@ -204,3 +205,4 @@ CURLcode Curl_file(struct connectdata *conn) * vim600: fdm=marker * vim: et sw=2 ts=2 sts=2 tw=78 */ +#endif -- cgit v1.2.1 From ba4e69bebc8f7f32f3bc7faa1e13e7580754075b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Sep 2002 11:52:59 +0000 Subject: updated source code boilerplate/header --- lib/file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b3ab757fd..a49085609 100644 --- a/lib/file.c +++ b/lib/file.c @@ -1,4 +1,4 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | @@ -7,19 +7,19 @@ * * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. * - * In order to be useful for every potential user, curl and libcurl are - * dual-licensed under the MPL and the MIT/X-derivate licenses. - * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is - * furnished to do so, under the terms of the MPL or the MIT/X-derivate - * licenses. You may pick one of these licenses. + * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * * $Id$ - *****************************************************************************/ + ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From cbc0f65fa33eef98f0a25e8c20564fbb49ecd904 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 23 Sep 2002 12:46:23 +0000 Subject: Dolbneff A.V and Spiridonoff A.V made the file:// code work with resumes in the same style other code does. --- lib/file.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index a49085609..1f9b5d116 100644 --- a/lib/file.c +++ b/lib/file.c @@ -159,6 +159,16 @@ CURLcode Curl_file(struct connectdata *conn) expected_size = (double)statbuf.st_size; } + /* Added by Dolbneff A.V & Spiridonoff A.V */ + if (conn->resume_from <= expected_size) + expected_size -= conn->resume_from; + else + /* Is this error code suitable in such situation? */ + return CURLE_FTP_BAD_DOWNLOAD_RESUME; + + if (expected_size == 0) + return CURLE_OK; + /* The following is a shortcut implementation of file reading this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors @@ -166,6 +176,10 @@ CURLcode Curl_file(struct connectdata *conn) if(expected_size != -1) Curl_pgrsSetDownloadSize(data, expected_size); + if(conn->resume_from) + /* Added by Dolbneff A.V & Spiridonoff A.V */ + lseek(fd, conn->resume_from, SEEK_SET); + while (res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); -- cgit v1.2.1 From f26a338a54e04d0a6907f5d2479d8b0fa9daf297 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Jan 2003 21:08:12 +0000 Subject: copyright year update in the source header --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1f9b5d116..faa32c879 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2002, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From a7c72b7abf1213c471f3fd11e6b8e3a37d526f60 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 29 Jan 2003 10:14:20 +0000 Subject: removed the local variables for emacs and vim, use the new sample.emacs way for emacs, and vim users should provide a similar non-polluting style --- lib/file.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index faa32c879..307ccd89c 100644 --- a/lib/file.c +++ b/lib/file.c @@ -211,12 +211,4 @@ CURLcode Curl_file(struct connectdata *conn) return res; } - -/* - * local variables: - * eval: (load-file "../curl-mode.el") - * end: - * vim600: fdm=marker - * vim: et sw=2 ts=2 sts=2 tw=78 - */ #endif -- cgit v1.2.1 From db566c54ae2529aa7af4073cc9834688f7ef4cdf Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 26 Jun 2003 11:16:37 +0000 Subject: use CURLDEBUG instead of MALLOCDEBUG --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 307ccd89c..20b6d1592 100644 --- a/lib/file.c +++ b/lib/file.c @@ -88,7 +88,7 @@ #include /* The last #include file should be: */ -#ifdef MALLOCDEBUG +#ifdef CURLDEBUG #include "memdebug.h" #endif -- cgit v1.2.1 From f0278ca114b266bfc1edd399e463e89f653e1ec8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 25 Jul 2003 08:30:58 +0000 Subject: Removed #include , as pointed out by Henry Bland we don't need it. --- lib/file.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 20b6d1592..29bec9970 100644 --- a/lib/file.c +++ b/lib/file.c @@ -48,7 +48,6 @@ #include #endif #include -#include #ifdef HAVE_UNISTD_H #include #endif -- cgit v1.2.1 From 9273096a8ab7e31921550b9f7b08eb2b32dcc35e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 8 Aug 2003 17:12:04 +0000 Subject: David Byron's fix for file:// URLs with drive letters included. --- lib/file.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 29bec9970..f4cd5f2f8 100644 --- a/lib/file.c +++ b/lib/file.c @@ -94,11 +94,12 @@ /* Emulate a connect-then-transfer protocol. We connect to the file here */ CURLcode Curl_file_connect(struct connectdata *conn) { - char *actual_path = curl_unescape(conn->path, 0); + char *real_path = curl_unescape(conn->path, 0); struct FILE *file; int fd; #if defined(WIN32) || defined(__EMX__) int i; + char *actual_path; #endif file = (struct FILE *)malloc(sizeof(struct FILE)); @@ -109,6 +110,28 @@ CURLcode Curl_file_connect(struct connectdata *conn) conn->proto.file = file; #if defined(WIN32) || defined(__EMX__) + /* If the first character is a slash, and there's + something that looks like a drive at the beginning of + the path, skip the slash. If we remove the initial + slash in all cases, paths without drive letters end up + relative to the current directory which isn't how + browsers work. + + Some browsers accept | instead of : as the drive letter + separator, so we do too. + + On other platforms, we need the slash to indicate an + absolute pathname. On Windows, absolute paths start + with a drive letter. + */ + actual_path = real_path; + if (*actual_path == '/' && + (actual_path[2] == ':' || actual_path[2] == '|')) + { + actual_path[2] = ':'; + actual_path++; + } + /* change path separators from '/' to '\\' for Windows and OS/2 */ for (i=0; actual_path[i] != '\0'; ++i) if (actual_path[i] == '/') @@ -116,9 +139,9 @@ CURLcode Curl_file_connect(struct connectdata *conn) fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ #else - fd = open(actual_path, O_RDONLY); + fd = open(real_path, O_RDONLY); #endif - free(actual_path); + free(real_path); if(fd == -1) { failf(conn->data, "Couldn't open file %s", conn->path); -- cgit v1.2.1 From 514a8739b669fa473560559a5cae225634bcc2f5 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 8 Aug 2003 17:56:47 +0000 Subject: make sure the string is long enough --- lib/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index f4cd5f2f8..4e08c03bc 100644 --- a/lib/file.c +++ b/lib/file.c @@ -125,7 +125,8 @@ CURLcode Curl_file_connect(struct connectdata *conn) with a drive letter. */ actual_path = real_path; - if (*actual_path == '/' && + if ((actual_path[0] == '/') && + actual_path[1] && (actual_path[2] == ':' || actual_path[2] == '|')) { actual_path[2] = ':'; -- cgit v1.2.1 From 749f5387c19449209615b282ac738032f2a890e7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 14 Oct 2003 12:00:45 +0000 Subject: Gisle Vanem's IPv6-on-Windows patch applied! --- lib/file.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4e08c03bc..1baa46d51 100644 --- a/lib/file.c +++ b/lib/file.c @@ -36,7 +36,6 @@ #include #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) -#include #include #include #include -- cgit v1.2.1 From fb26b2bd98eb4fb29dc644fdcc74da1ec60c3708 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 30 Oct 2003 09:08:16 +0000 Subject: curl --head now reports info "headers" on file:// URLs as well --- lib/file.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1baa46d51..9f312320a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -163,7 +163,8 @@ CURLcode Curl_file(struct connectdata *conn) */ CURLcode res = CURLE_OK; struct stat statbuf; - double expected_size=-1; + unsigned long expected_size=0; + bool fstated=FALSE; ssize_t nread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; @@ -178,25 +179,59 @@ CURLcode Curl_file(struct connectdata *conn) /*VMS?? -- This only works reliable for STREAMLF files */ if( -1 != fstat(fd, &statbuf)) { /* we could stat it, then read out the size */ - expected_size = (double)statbuf.st_size; + expected_size = statbuf.st_size; + fstated = TRUE; + } + + /* If we have selected NOBODY and HEADER, it means that we only want file + information. Which for FILE can't be much more than the file size and + date. */ + if(data->set.no_body && data->set.include_header && fstated) { + CURLcode result; + sprintf(buf, "Content-Length: %lu\r\n", expected_size); + result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + if(result) + return result; + + sprintf(buf, "Accept-ranges: bytes\r\n"); + result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + if(result) + return result; + +#ifdef HAVE_STRFTIME + if(fstated) { + struct tm *tm; +#ifdef HAVE_LOCALTIME_R + struct tm buffer; + tm = (struct tm *)localtime_r((time_t *)&statbuf.st_mtime, &buffer); +#else + tm = localtime((time_t *)&statbuf.st_mtime); +#endif + /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ + strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", + tm); + result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + } +#endif + return result; } /* Added by Dolbneff A.V & Spiridonoff A.V */ - if (conn->resume_from <= expected_size) + if (conn->resume_from <= (long)expected_size) expected_size -= conn->resume_from; else /* Is this error code suitable in such situation? */ return CURLE_FTP_BAD_DOWNLOAD_RESUME; - if (expected_size == 0) + if (fstated && (expected_size == 0)) return CURLE_OK; /* The following is a shortcut implementation of file reading this is both more efficient than the former call to download() and it avoids problems with select() and recv() on file descriptors in Winsock */ - if(expected_size != -1) - Curl_pgrsSetDownloadSize(data, expected_size); + if(fstated) + Curl_pgrsSetDownloadSize(data, (double)expected_size); if(conn->resume_from) /* Added by Dolbneff A.V & Spiridonoff A.V */ -- cgit v1.2.1 From 693df0fa344176b6cfa90cefbc43bbcae8659f93 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 30 Oct 2003 09:13:04 +0000 Subject: silly me, I was meaning to do this change already as discussed on the libcurl list, we get the time in GMT and not localtime --- lib/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9f312320a..99310ccea 100644 --- a/lib/file.c +++ b/lib/file.c @@ -201,11 +201,11 @@ CURLcode Curl_file(struct connectdata *conn) #ifdef HAVE_STRFTIME if(fstated) { struct tm *tm; -#ifdef HAVE_LOCALTIME_R +#ifdef HAVE_GMTIME_R struct tm buffer; - tm = (struct tm *)localtime_r((time_t *)&statbuf.st_mtime, &buffer); + tm = (struct tm *)gmtime_r((time_t *)&statbuf.st_mtime, &buffer); #else - tm = localtime((time_t *)&statbuf.st_mtime); + tm = gmtime((time_t *)&statbuf.st_mtime); #endif /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", -- cgit v1.2.1 From b60e0fa97ed7ddc66d0ad6d00dfd78319bb6ad36 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Jan 2004 22:29:29 +0000 Subject: David J Meyer's large file support. --- lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 99310ccea..ca30582dd 100644 --- a/lib/file.c +++ b/lib/file.c @@ -163,12 +163,12 @@ CURLcode Curl_file(struct connectdata *conn) */ CURLcode res = CURLE_OK; struct stat statbuf; - unsigned long expected_size=0; + off_t expected_size=0; bool fstated=FALSE; ssize_t nread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; - int bytecount = 0; + off_t bytecount = 0; struct timeval start = Curl_tvnow(); struct timeval now = start; int fd; @@ -188,7 +188,7 @@ CURLcode Curl_file(struct connectdata *conn) date. */ if(data->set.no_body && data->set.include_header && fstated) { CURLcode result; - sprintf(buf, "Content-Length: %lu\r\n", expected_size); + sprintf(buf, "Content-Length: %Od\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; @@ -217,7 +217,7 @@ CURLcode Curl_file(struct connectdata *conn) } /* Added by Dolbneff A.V & Spiridonoff A.V */ - if (conn->resume_from <= (long)expected_size) + if (conn->resume_from <= expected_size) expected_size -= conn->resume_from; else /* Is this error code suitable in such situation? */ -- cgit v1.2.1 From 053f6c85efd0bf698f73343989474d672d0563a8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Jan 2004 09:19:33 +0000 Subject: updated year in the copyright string --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index ca30582dd..93b7977e2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2003, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms -- cgit v1.2.1 From b791e158f0e04a518dea19fdaf0bfbf71b343c64 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 22 Jan 2004 12:45:50 +0000 Subject: use curl_off_t instead of off_t! --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 93b7977e2..2bf544add 100644 --- a/lib/file.c +++ b/lib/file.c @@ -163,12 +163,12 @@ CURLcode Curl_file(struct connectdata *conn) */ CURLcode res = CURLE_OK; struct stat statbuf; - off_t expected_size=0; + curl_off_t expected_size=0; bool fstated=FALSE; ssize_t nread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; - off_t bytecount = 0; + curl_off_t bytecount = 0; struct timeval start = Curl_tvnow(); struct timeval now = start; int fd; -- cgit v1.2.1 From a259f66fa4b8663803b5604917457d32dee90540 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 22 Jan 2004 13:11:35 +0000 Subject: attempt to fix 64bit seeking for Windows, does it work? --- lib/file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 2bf544add..274f67550 100644 --- a/lib/file.c +++ b/lib/file.c @@ -152,6 +152,10 @@ CURLcode Curl_file_connect(struct connectdata *conn) return CURLE_OK; } +#if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4) +#define lseek(x,y,z) _lseeki64(x, y, z) +#endif + /* This is the do-phase, separated from the connect-phase above */ CURLcode Curl_file(struct connectdata *conn) @@ -234,7 +238,6 @@ CURLcode Curl_file(struct connectdata *conn) Curl_pgrsSetDownloadSize(data, (double)expected_size); if(conn->resume_from) - /* Added by Dolbneff A.V & Spiridonoff A.V */ lseek(fd, conn->resume_from, SEEK_SET); while (res == CURLE_OK) { -- cgit v1.2.1 From 4d17d6876e4b2f08380812c4ec113073b0a14639 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 29 Jan 2004 13:56:45 +0000 Subject: Dan Fandrich's cleanup patch to make pedantic compiler options cause less warnings. Minor edits by me. --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 274f67550..2eeb52760 100644 --- a/lib/file.c +++ b/lib/file.c @@ -81,6 +81,7 @@ #include "progress.h" #include "sendf.h" #include "escape.h" +#include "file.h" #define _MPRINTF_REPLACE /* use our functions only */ #include -- cgit v1.2.1 From 115e74a8adef7f8e509b083015fdbf8b453efb1d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 13 Feb 2004 07:03:03 +0000 Subject: I made the same fix here, that Tor already did in the ftp.c code. To make sure this doesn't get weird on 64bit archs. --- lib/file.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 2eeb52760..3bfc342d4 100644 --- a/lib/file.c +++ b/lib/file.c @@ -206,11 +206,12 @@ CURLcode Curl_file(struct connectdata *conn) #ifdef HAVE_STRFTIME if(fstated) { struct tm *tm; + time_t clock = (time_t)statbuf.st_mtime; #ifdef HAVE_GMTIME_R struct tm buffer; - tm = (struct tm *)gmtime_r((time_t *)&statbuf.st_mtime, &buffer); + tm = (struct tm *)gmtime_r(&clock, &buffer); #else - tm = gmtime((time_t *)&statbuf.st_mtime); + tm = gmtime(&clock); #endif /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", -- cgit v1.2.1 From 6a921197e2170759e9b7bb674eed3e6ace5f3a07 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 13 Feb 2004 12:13:30 +0000 Subject: the now and start variables were never really used --- lib/file.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3bfc342d4..9da985f87 100644 --- a/lib/file.c +++ b/lib/file.c @@ -174,8 +174,6 @@ CURLcode Curl_file(struct connectdata *conn) struct SessionHandle *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; - struct timeval start = Curl_tvnow(); - struct timeval now = start; int fd; /* get the fd from the connection phase */ @@ -261,11 +259,9 @@ CURLcode Curl_file(struct connectdata *conn) if(res) return res; - now = Curl_tvnow(); if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; } - now = Curl_tvnow(); if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; -- cgit v1.2.1 From cb72a80fe06d96c46e69a869cceb16b491fcb23b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 1 Mar 2004 16:28:00 +0000 Subject: Use CURL_FORMAT_OFF_T for printf()inf curl_off_t variables. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9da985f87..356cdaecc 100644 --- a/lib/file.c +++ b/lib/file.c @@ -191,7 +191,7 @@ CURLcode Curl_file(struct connectdata *conn) date. */ if(data->set.no_body && data->set.include_header && fstated) { CURLcode result; - sprintf(buf, "Content-Length: %Od\r\n", expected_size); + sprintf(buf, "Content-Length: " CURL_FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; -- cgit v1.2.1 From 7ab3b5b3bb4c02dc00621efe13b8d3b29b819250 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Mar 2004 07:25:39 +0000 Subject: use FORMAT_OFF_T instead of CURL_FORMAT_OFF_T to reduce the complexity of having to redef that name --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 356cdaecc..ca575c8d5 100644 --- a/lib/file.c +++ b/lib/file.c @@ -191,7 +191,7 @@ CURLcode Curl_file(struct connectdata *conn) date. */ if(data->set.no_body && data->set.include_header && fstated) { CURLcode result; - sprintf(buf, "Content-Length: " CURL_FORMAT_OFF_T "\r\n", expected_size); + sprintf(buf, "Content-Length: " FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; -- cgit v1.2.1 From 353f7641193ddf3f6a42d49d53ea994e4ea4388b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Mar 2004 09:31:18 +0000 Subject: Yet another curl_off_t printf format attempt, we now exclude the %-letter from FORMAT_OFF_T to allow additional options to get specified, like with '"%5" FORMAT_OFF_T'. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index ca575c8d5..dcf59d06e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -191,7 +191,7 @@ CURLcode Curl_file(struct connectdata *conn) date. */ if(data->set.no_body && data->set.include_header && fstated) { CURLcode result; - sprintf(buf, "Content-Length: " FORMAT_OFF_T "\r\n", expected_size); + sprintf(buf, "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; -- cgit v1.2.1 From e2f7030202bac42e7f08309ba71e370fba714623 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 3 Mar 2004 09:25:59 +0000 Subject: rename struct FILE to FILEPROTO, to prevent it from causing trouble with the plain old FILE typedef. --- lib/file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index dcf59d06e..e10fa8108 100644 --- a/lib/file.c +++ b/lib/file.c @@ -95,18 +95,17 @@ CURLcode Curl_file_connect(struct connectdata *conn) { char *real_path = curl_unescape(conn->path, 0); - struct FILE *file; + struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(__EMX__) int i; char *actual_path; #endif - file = (struct FILE *)malloc(sizeof(struct FILE)); + file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); if(!file) return CURLE_OUT_OF_MEMORY; - memset(file, 0, sizeof(struct FILE)); conn->proto.file = file; #if defined(WIN32) || defined(__EMX__) -- cgit v1.2.1 From 2b59e90c549a02670ec790a1d1fabf1e1d09706f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 4 Mar 2004 15:12:12 +0000 Subject: fix progress data to be updated properly for file: transfers, as reported by Jesse Noller --- lib/file.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e10fa8108..e411ac16d 100644 --- a/lib/file.c +++ b/lib/file.c @@ -174,6 +174,7 @@ CURLcode Curl_file(struct connectdata *conn) char *buf = data->state.buffer; curl_off_t bytecount = 0; int fd; + struct timeval now = Curl_tvnow(); /* get the fd from the connection phase */ fd = conn->proto.file->fd; @@ -239,6 +240,8 @@ CURLcode Curl_file(struct connectdata *conn) if(conn->resume_from) lseek(fd, conn->resume_from, SEEK_SET); + Curl_pgrsTime(data, TIMER_STARTTRANSFER); + while (res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); @@ -258,8 +261,12 @@ CURLcode Curl_file(struct connectdata *conn) if(res) return res; + Curl_pgrsSetDownloadCounter(data, (double)bytecount); + if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; + else + res = Curl_speedcheck (data, now); } if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; -- cgit v1.2.1 From 78e47fbb5c2e2aaebe54d52c30385feae8c78f18 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 4 Mar 2004 15:23:57 +0000 Subject: include the proper header file too --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e411ac16d..40ee5cab5 100644 --- a/lib/file.c +++ b/lib/file.c @@ -82,6 +82,7 @@ #include "sendf.h" #include "escape.h" #include "file.h" +#include "speedcheck.h" #define _MPRINTF_REPLACE /* use our functions only */ #include -- cgit v1.2.1 From 67172406507a8030a38c229a217970d81b9d1b1e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Mar 2004 09:40:16 +0000 Subject: more fixing to make the progress/getinfo stuff to work properly when doing file: transfers too --- lib/file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 40ee5cab5..e923ae255 100644 --- a/lib/file.c +++ b/lib/file.c @@ -83,6 +83,7 @@ #include "escape.h" #include "file.h" #include "speedcheck.h" +#include "getinfo.h" #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -177,10 +178,14 @@ CURLcode Curl_file(struct connectdata *conn) int fd; struct timeval now = Curl_tvnow(); + Curl_readwrite_init(conn); + Curl_initinfo(data); + Curl_pgrsStartNow(data); + /* get the fd from the connection phase */ fd = conn->proto.file->fd; -/*VMS?? -- This only works reliable for STREAMLF files */ + /* 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; -- cgit v1.2.1 From 3d3612e252cb769320518b202a3bbc0182d96f61 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Mar 2004 11:39:19 +0000 Subject: another include to prevent warnings --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e923ae255..31ab2c194 100644 --- a/lib/file.c +++ b/lib/file.c @@ -84,6 +84,7 @@ #include "file.h" #include "speedcheck.h" #include "getinfo.h" +#include "transfer.h" /* for Curl_readwrite_init() */ #define _MPRINTF_REPLACE /* use our functions only */ #include -- cgit v1.2.1 From 0d1fc73f2119e1f75f58b32cdc9f9d45fa71ac9c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 10 Mar 2004 16:20:33 +0000 Subject: Use more curl_off_t variables when doing the progress meter calculations and argument passing and try to convert to double only when providing data to the external world. --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 31ab2c194..72e835272 100644 --- a/lib/file.c +++ b/lib/file.c @@ -242,7 +242,7 @@ CURLcode Curl_file(struct connectdata *conn) it avoids problems with select() and recv() on file descriptors in Winsock */ if(fstated) - Curl_pgrsSetDownloadSize(data, (double)expected_size); + Curl_pgrsSetDownloadSize(data, expected_size); if(conn->resume_from) lseek(fd, conn->resume_from, SEEK_SET); @@ -268,7 +268,7 @@ CURLcode Curl_file(struct connectdata *conn) if(res) return res; - Curl_pgrsSetDownloadCounter(data, (double)bytecount); + Curl_pgrsSetDownloadCounter(data, bytecount); if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; -- cgit v1.2.1 From 8ed44e8dfbe2182696becc3ca8a9950888251503 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 6 Apr 2004 15:14:10 +0000 Subject: New authentication code added, particularly noticable when doing POST or PUT with Digest or NTLM. libcurl will now use HEAD to negotiate the authentication and when done perform the requested POST. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 72e835272..3977a73e5 100644 --- a/lib/file.c +++ b/lib/file.c @@ -196,7 +196,7 @@ CURLcode Curl_file(struct connectdata *conn) /* If we have selected NOBODY and HEADER, it means that we only want file information. Which for FILE can't be much more than the file size and date. */ - if(data->set.no_body && data->set.include_header && fstated) { + if(conn->bits.no_body && data->set.include_header && fstated) { CURLcode result; sprintf(buf, "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); -- cgit v1.2.1 From af641d20a7b113c94d70dc1af7fa4a570544c229 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 26 Apr 2004 07:11:39 +0000 Subject: added comments --- lib/file.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3977a73e5..004718cd4 100644 --- a/lib/file.c +++ b/lib/file.c @@ -94,7 +94,11 @@ #include "memdebug.h" #endif -/* Emulate a connect-then-transfer protocol. We connect to the file here */ +/* + * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to + * do protocol-specific actions at connect-time. We emulate a + * connect-then-transfer protocol and "connect" to the file here + */ CURLcode Curl_file_connect(struct connectdata *conn) { char *real_path = curl_unescape(conn->path, 0); @@ -159,8 +163,14 @@ CURLcode Curl_file_connect(struct connectdata *conn) #define lseek(x,y,z) _lseeki64(x, y, z) #endif -/* This is the do-phase, separated from the connect-phase above */ - +/* + * Curl_file() is the protocol-specific function for the do-phase, separated + * from the connect-phase above. Other protocols merely setup the transfer in + * the do-phase, to have it done in the main transfer loop but since some + * platforms we support don't allow select()ing etc on file handles (as + * opposed to sockets) we instead perform the whole do-operation in this + * function. + */ CURLcode Curl_file(struct connectdata *conn) { /* This implementation ignores the host name in conformance with -- cgit v1.2.1 From bbafb2eb27954c34967f91c705e74cc0c186970d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 11 May 2004 11:30:23 +0000 Subject: curl_global_init_mem() allows the memory functions to be replaced. memory.h is included everywhere for this. --- lib/file.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 004718cd4..0edd3d972 100644 --- a/lib/file.c +++ b/lib/file.c @@ -73,7 +73,6 @@ #include #endif - #endif #include "urldata.h" @@ -85,14 +84,13 @@ #include "speedcheck.h" #include "getinfo.h" #include "transfer.h" /* for Curl_readwrite_init() */ +#include "memory.h" #define _MPRINTF_REPLACE /* use our functions only */ #include /* The last #include file should be: */ -#ifdef CURLDEBUG #include "memdebug.h" -#endif /* * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to -- cgit v1.2.1 From 54cd2bee581ac5f544443d66c9951d1b88d7a583 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 13 May 2004 15:17:07 +0000 Subject: better bailing out in case of no memory --- lib/file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 0edd3d972..05a1fde58 100644 --- a/lib/file.c +++ b/lib/file.c @@ -107,9 +107,14 @@ CURLcode Curl_file_connect(struct connectdata *conn) char *actual_path; #endif + if(!real_path) + return CURLE_OUT_OF_MEMORY; + file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); - if(!file) + if(!file) { + free(real_path); return CURLE_OUT_OF_MEMORY; + } conn->proto.file = file; -- cgit v1.2.1 From fd802db39f77fa3985d20e461742bf24644065d6 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 25 May 2004 21:47:29 +0000 Subject: initial support for "uploading" to file:// URLs --- lib/file.c | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 14 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 05a1fde58..e36631426 100644 --- a/lib/file.c +++ b/lib/file.c @@ -1,8 +1,8 @@ /*************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. @@ -10,7 +10,7 @@ * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. - * + * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. @@ -83,7 +83,8 @@ #include "file.h" #include "speedcheck.h" #include "getinfo.h" -#include "transfer.h" /* for Curl_readwrite_init() */ +#include "transfer.h" +#include "url.h" #include "memory.h" #define _MPRINTF_REPLACE /* use our functions only */ @@ -148,13 +149,16 @@ CURLcode Curl_file_connect(struct connectdata *conn) actual_path[i] = '\\'; fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ + file->path = actual_path; #else fd = open(real_path, O_RDONLY); + file->path = real_path; #endif - free(real_path); + file->freepath = real_path; /* free this when done */ - if(fd == -1) { + if(!conn->data->set.upload && (fd == -1)) { failf(conn->data, "Couldn't open file %s", conn->path); + Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE); return CURLE_FILE_COULDNT_READ_FILE; } file->fd = fd; @@ -166,6 +170,83 @@ CURLcode Curl_file_connect(struct connectdata *conn) #define lseek(x,y,z) _lseeki64(x, y, z) #endif +CURLcode Curl_file_done(struct connectdata *conn, + CURLcode status) +{ + struct FILEPROTO *file = conn->proto.file; + (void)status; /* not used */ + Curl_safefree(file->path); + + return CURLE_OK; +} + +static CURLcode file_upload(struct connectdata *conn) +{ + struct FILEPROTO *file = conn->proto.file; + char *dir = strchr(file->path, '/'); + FILE *fp; + CURLcode res=CURLE_OK; + struct SessionHandle *data = conn->data; + char *buf = data->state.buffer; + size_t nread; + size_t nwrite; + curl_off_t bytecount = 0; + struct timeval now = Curl_tvnow(); + + /* + * Since FILE: doesn't do the full init, we need to provide some extra + * assignments here. + */ + conn->fread = data->set.fread; + conn->fread_in = data->set.in; + conn->upload_fromhere = buf; + + if(!dir) + return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ + + if(!dir[1]) + return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ + + fp = fopen(file->path, "wb"); + if(!fp) { + failf(data, "Can't open %s for writing", file->path); + return CURLE_WRITE_ERROR; + } + + if(-1 != data->set.infilesize) + /* known size of data to "upload" */ + Curl_pgrsSetUploadSize(data, data->set.infilesize); + + while (res == CURLE_OK) { + nread = Curl_fillreadbuffer(conn, BUFSIZE); + + if (nread <= 0) + break; + + /* write the data to the target */ + nwrite = fwrite(buf, 1, nread, fp); + if(nwrite != nread) { + res = CURLE_SEND_ERROR; + break; + } + + bytecount += nread; + + Curl_pgrsSetUploadCounter(data, bytecount); + + if(Curl_pgrsUpdate(conn)) + res = CURLE_ABORTED_BY_CALLBACK; + else + res = Curl_speedcheck(data, now); + } + if(!res && Curl_pgrsUpdate(conn)) + res = CURLE_ABORTED_BY_CALLBACK; + + fclose(fp); + + return res; +} + /* * Curl_file() is the protocol-specific function for the do-phase, separated * from the connect-phase above. Other protocols merely setup the transfer in @@ -176,7 +257,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) */ CURLcode Curl_file(struct connectdata *conn) { - /* This implementation ignores the host name in conformance with + /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) are supported. This means that files on remotely mounted directories (via NFS, Samba, NT sharing) can be accessed through a file:// URL @@ -196,6 +277,9 @@ CURLcode Curl_file(struct connectdata *conn) Curl_initinfo(data); Curl_pgrsStartNow(data); + if(data->set.upload) + return file_upload(conn); + /* get the fd from the connection phase */ fd = conn->proto.file->fd; @@ -272,10 +356,6 @@ CURLcode Curl_file(struct connectdata *conn) break; bytecount += nread; - /* NOTE: The following call to fwrite does CR/LF translation on - Windows systems if the target is stdout. Use -O or -o parameters - to prevent CR/LF translation (this then goes to a binary mode - file descriptor). */ res = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread); if(res) @@ -286,7 +366,7 @@ CURLcode Curl_file(struct connectdata *conn) if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; else - res = Curl_speedcheck (data, now); + res = Curl_speedcheck(data, now); } if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; -- cgit v1.2.1 From 3d00c86f4ca2439a2748fa61c591fb69b36c010d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Jun 2004 07:17:28 +0000 Subject: Steven Bazyl and Seshubabu Pasam pointed out a bug on win32 when freeing the path after a transfer. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e36631426..4a064a065 100644 --- a/lib/file.c +++ b/lib/file.c @@ -175,7 +175,7 @@ CURLcode Curl_file_done(struct connectdata *conn, { struct FILEPROTO *file = conn->proto.file; (void)status; /* not used */ - Curl_safefree(file->path); + Curl_safefree(file->freepath); return CURLE_OK; } -- cgit v1.2.1 From 8e287210577223b7d6dfb66034eca77c24a58b7f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 21 Jun 2004 14:07:38 +0000 Subject: The read callback can now return CURL_READFUNC_ABORT to stop a transfer. --- lib/file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4a064a065..8f47a19e6 100644 --- a/lib/file.c +++ b/lib/file.c @@ -218,7 +218,12 @@ static CURLcode file_upload(struct connectdata *conn) Curl_pgrsSetUploadSize(data, data->set.infilesize); while (res == CURLE_OK) { - nread = Curl_fillreadbuffer(conn, BUFSIZE); + int readcount; + res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount); + if(res) + return res; + + nread = (size_t)readcount; if (nread <= 0) break; -- cgit v1.2.1 From feb2dd283533f842c9b6e4cc2fcc7fd35638d5a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 11:54:11 +0000 Subject: Replaced all uses of sprintf() with the safer snprintf(). It is just a precaution to prevent mistakes to lead to buffer overflows. --- lib/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 8f47a19e6..7bbf8a340 100644 --- a/lib/file.c +++ b/lib/file.c @@ -300,13 +300,14 @@ CURLcode Curl_file(struct connectdata *conn) date. */ if(conn->bits.no_body && data->set.include_header && fstated) { CURLcode result; - sprintf(buf, "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); + snprintf(buf, sizeof(data->state.buffer), + "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); if(result) return result; - sprintf(buf, "Accept-ranges: bytes\r\n"); - result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + result = Curl_client_write(data, CLIENTWRITE_BOTH, + "Accept-ranges: bytes\r\n", 0); if(result) return result; -- cgit v1.2.1 From 387ec712e6806e85c2d0b0e4c2568f95d559eef7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 24 Jun 2004 15:06:25 +0000 Subject: fix warning --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 7bbf8a340..c8315ae46 100644 --- a/lib/file.c +++ b/lib/file.c @@ -307,7 +307,7 @@ CURLcode Curl_file(struct connectdata *conn) return result; result = Curl_client_write(data, CLIENTWRITE_BOTH, - "Accept-ranges: bytes\r\n", 0); + (char *)"Accept-ranges: bytes\r\n", 0); if(result) return result; -- cgit v1.2.1 From 2a6f9aa155cc9ecd1fdf09cd9ca4badbb4a30019 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 6 Jul 2004 15:16:05 +0000 Subject: Andres Garcia pointed out that we searched for a slash badly since it is converted and thus we must search for backslash on windows --- lib/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index c8315ae46..20cb918eb 100644 --- a/lib/file.c +++ b/lib/file.c @@ -180,10 +180,16 @@ CURLcode Curl_file_done(struct connectdata *conn, return CURLE_OK; } +#if defined(WIN32) || defined(__EMX__) +#define DIRSEP '\\' +#else +#define DIRSEP '/' +#endif + static CURLcode file_upload(struct connectdata *conn) { struct FILEPROTO *file = conn->proto.file; - char *dir = strchr(file->path, '/'); + char *dir = strchr(file->path, DIRSEP); FILE *fp; CURLcode res=CURLE_OK; struct SessionHandle *data = conn->data; -- cgit v1.2.1 From 06a5c70f4d0ebd31f267e6a18d5e8524871d89d4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 17 Aug 2004 12:00:39 +0000 Subject: Kjetil Jacobsen reported an open file leak in file:// transfers of empty files. --- lib/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 20cb918eb..57201d417 100644 --- a/lib/file.c +++ b/lib/file.c @@ -177,6 +177,9 @@ CURLcode Curl_file_done(struct connectdata *conn, (void)status; /* not used */ Curl_safefree(file->freepath); + if(file->fd != -1) + close(file->fd); + return CURLE_OK; } @@ -227,7 +230,7 @@ static CURLcode file_upload(struct connectdata *conn) int readcount; res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount); if(res) - return res; + break; nread = (size_t)readcount; @@ -383,8 +386,7 @@ CURLcode Curl_file(struct connectdata *conn) if(Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; - close(fd); - return res; } + #endif -- cgit v1.2.1 From 39af394a1c3ae1d8ac71ad263a7c524988702c2e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 6 Oct 2004 07:50:18 +0000 Subject: removed tabs and trailing whitespace from source --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 57201d417..6d6287d74 100644 --- a/lib/file.c +++ b/lib/file.c @@ -148,7 +148,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) if (actual_path[i] == '/') actual_path[i] = '\\'; - fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ + fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ file->path = actual_path; #else fd = open(real_path, O_RDONLY); -- cgit v1.2.1 From 24d47a6e07304cf0921f2d30734b3c64360773c3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Nov 2004 10:12:22 +0000 Subject: Paul Nolan fix to make libcurl build nicely on Windows CE --- lib/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6d6287d74..7831d2ef2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -30,8 +30,12 @@ #include #include #include +#ifdef HAVE_SYS_TYPES_H #include +#endif +#ifdef HAVE_SYS_STAT_H #include +#endif #include @@ -66,9 +70,6 @@ #include #endif -#ifdef HAVE_SYS_STAT_H -#include -#endif #ifdef HAVE_FCNTL_H #include #endif -- cgit v1.2.1 From 865e495188a07a1b1fd4b32b172730c8d5cd707b Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Tue, 9 Nov 2004 14:57:11 +0000 Subject: Handle drive-letter on MS-DOS. --- lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 7831d2ef2..de1e89c59 100644 --- a/lib/file.c +++ b/lib/file.c @@ -104,7 +104,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) char *real_path = curl_unescape(conn->path, 0); struct FILEPROTO *file; int fd; -#if defined(WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) int i; char *actual_path; #endif @@ -120,7 +120,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) conn->proto.file = file; -#if defined(WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) /* If the first character is a slash, and there's something that looks like a drive at the beginning of the path, skip the slash. If we remove the initial @@ -144,7 +144,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) actual_path++; } - /* change path separators from '/' to '\\' for Windows and OS/2 */ + /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */ for (i=0; actual_path[i] != '\0'; ++i) if (actual_path[i] == '/') actual_path[i] = '\\'; @@ -184,7 +184,7 @@ CURLcode Curl_file_done(struct connectdata *conn, return CURLE_OK; } -#if defined(WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) #define DIRSEP '\\' #else #define DIRSEP '/' -- cgit v1.2.1 From 1b8ac7c6b5c95a74ea49b2aa6d4b4650c401e95e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 11 Dec 2004 18:55:51 +0000 Subject: provide an error string when resuming fails - and use the proper error code, not the former one --- lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index de1e89c59..0f448934b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -340,12 +340,12 @@ CURLcode Curl_file(struct connectdata *conn) return result; } - /* Added by Dolbneff A.V & Spiridonoff A.V */ if (conn->resume_from <= expected_size) expected_size -= conn->resume_from; - else - /* Is this error code suitable in such situation? */ - return CURLE_FTP_BAD_DOWNLOAD_RESUME; + else { + failf(data, "failed to resume file:// transfer"); + return CURLE_BAD_DOWNLOAD_RESUME; + } if (fstated && (expected_size == 0)) return CURLE_OK; -- cgit v1.2.1 From 344c6a37250e4905ec60974bbec82842a5c96c9b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 Dec 2004 10:25:26 +0000 Subject: Gisle's fix for resuming large file:// files on windows - slightly edited by me. --- lib/file.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 0f448934b..6b2bbd161 100644 --- a/lib/file.c +++ b/lib/file.c @@ -169,6 +169,10 @@ CURLcode Curl_file_connect(struct connectdata *conn) #if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4) #define lseek(x,y,z) _lseeki64(x, y, z) +#define struct_stat struct _stati64 +#define fstat(fd,st) _fstati64(fd,st) +#else +#define struct_stat struct stat #endif CURLcode Curl_file_done(struct connectdata *conn, @@ -278,7 +282,9 @@ CURLcode Curl_file(struct connectdata *conn) (via NFS, Samba, NT sharing) can be accessed through a file:// URL */ CURLcode res = CURLE_OK; - struct stat statbuf; + 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; bool fstated=FALSE; ssize_t nread; -- cgit v1.2.1 From 4f5a6a33b46f9c389e6cfcd822c6fc874a3a9752 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 16 Dec 2004 18:09:27 +0000 Subject: moved the lseek() and stat() magic defines to setup.h and now take advantage of struct_stat in formdata.c as well, to support formpost uploads of large files on Windows too --- lib/file.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6b2bbd161..267a99ba0 100644 --- a/lib/file.c +++ b/lib/file.c @@ -167,14 +167,6 @@ CURLcode Curl_file_connect(struct connectdata *conn) return CURLE_OK; } -#if defined(WIN32) && (SIZEOF_CURL_OFF_T > 4) -#define lseek(x,y,z) _lseeki64(x, y, z) -#define struct_stat struct _stati64 -#define fstat(fd,st) _fstati64(fd,st) -#else -#define struct_stat struct stat -#endif - CURLcode Curl_file_done(struct connectdata *conn, CURLcode status) { -- cgit v1.2.1 From 6a2e21ec8cbaf7c719902e06953d9dbec629ad4f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Feb 2005 13:06:40 +0000 Subject: FTP code turned into state machine. Not completely yet, but a good start. The tag 'before_ftp_statemachine' was set just before this commit in case of future need. --- lib/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 267a99ba0..5bebf3287 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2004, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -266,7 +266,7 @@ static CURLcode file_upload(struct connectdata *conn) * opposed to sockets) we instead perform the whole do-operation in this * function. */ -CURLcode Curl_file(struct connectdata *conn) +CURLcode Curl_file(struct connectdata *conn, bool *done) { /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) @@ -286,6 +286,8 @@ CURLcode Curl_file(struct connectdata *conn) int fd; struct timeval now = Curl_tvnow(); + *done = TRUE; /* unconditionally */ + Curl_readwrite_init(conn); Curl_initinfo(data); Curl_pgrsStartNow(data); -- cgit v1.2.1 From e7cefd684b2d5e1f3710eb24babc0b9974095c97 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Feb 2005 00:03:49 +0000 Subject: Removed all uses of strftime() since it uses the localised version of the week day names and month names and servers don't like that. --- lib/file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 5bebf3287..c325a4673 100644 --- a/lib/file.c +++ b/lib/file.c @@ -87,6 +87,7 @@ #include "transfer.h" #include "url.h" #include "memory.h" +#include "parsedate.h" /* for the week day and month names */ #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -321,7 +322,6 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) if(result) return result; -#ifdef HAVE_STRFTIME if(fstated) { struct tm *tm; time_t clock = (time_t)statbuf.st_mtime; @@ -332,11 +332,17 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) tm = gmtime(&clock); #endif /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ - strftime(buf, BUFSIZE-1, "Last-Modified: %a, %d %b %Y %H:%M:%S GMT\r\n", - tm); + snprintf(buf, BUFSIZE-1, + "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", + Curl_wkday[tm->tm_wday?tm->tm_wday-1:6], + tm->tm_mday, + Curl_month[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); } -#endif return result; } -- cgit v1.2.1 From 6513303498d36b08d2ae815311248ed818cf668e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 1 Dec 2005 23:42:03 +0000 Subject: Jamie Newton pointed out that libcurl's file:// code would close() a zero file descriptor if given a non-existing file. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index c325a4673..dbfe81cfa 100644 --- a/lib/file.c +++ b/lib/file.c @@ -158,12 +158,12 @@ CURLcode Curl_file_connect(struct connectdata *conn) #endif file->freepath = real_path; /* free this when done */ + file->fd = fd; if(!conn->data->set.upload && (fd == -1)) { failf(conn->data, "Couldn't open file %s", conn->path); Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE); return CURLE_FILE_COULDNT_READ_FILE; } - file->fd = fd; return CURLE_OK; } -- cgit v1.2.1 From b11dec5dd5a4e727be964448b9c5d14cd0ace974 Mon Sep 17 00:00:00 2001 From: Marty Kuhrt Date: Fri, 30 Dec 2005 00:07:25 +0000 Subject: putting back into dist --- lib/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index dbfe81cfa..8926105e9 100644 --- a/lib/file.c +++ b/lib/file.c @@ -230,11 +230,11 @@ static CURLcode file_upload(struct connectdata *conn) if(res) break; - nread = (size_t)readcount; - - if (nread <= 0) + if (readcount <= 0) break; + nread = (size_t)readcount; + /* write the data to the target */ nwrite = fwrite(buf, 1, nread, fp); if(nwrite != nread) { -- cgit v1.2.1 From cc343427902adf265f8356862766ed269ace1d99 Mon Sep 17 00:00:00 2001 From: Marty Kuhrt Date: Fri, 30 Dec 2005 00:20:46 +0000 Subject: fix questionable compare compiler error (unsigned can't be < 0) --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 8926105e9..b62581763 100644 --- a/lib/file.c +++ b/lib/file.c @@ -230,7 +230,7 @@ static CURLcode file_upload(struct connectdata *conn) if(res) break; - if (readcount <= 0) + if (readcount <= 0) /* fix questionable compare error. curlvms */ break; nread = (size_t)readcount; -- cgit v1.2.1 From 5a4b43848ac21b3d831f00ce11136e20f820f0a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 7 Apr 2006 21:50:47 +0000 Subject: First commit of David McCreedy's EBCDIC and TPF changes. --- lib/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b62581763..d39b12d43 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -102,7 +102,7 @@ */ CURLcode Curl_file_connect(struct connectdata *conn) { - char *real_path = curl_unescape(conn->path, 0); + char *real_path = curl_easy_unescape(conn->data, conn->path, 0, NULL); struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) -- cgit v1.2.1 From e85e30546c89e17b6fb0cf383de25b7ed7f3bf3d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 4 May 2006 22:39:47 +0000 Subject: Roland Blom filed bug report #1481217 (http://curl.haxx.se/bug/view.cgi?id=1481217), with follow-ups by Michele Bini and David Byron. libcurl previously wrongly used GetLastError() on windows to get error details after socket-related function calls, when it really should use WSAGetLastError() instead. When changing to this, the former function Curl_ourerrno() is now instead called Curl_sockerrno() as it is necessary to only use it to get errno from socket-related functions as otherwise it won't work as intended on Windows. --- lib/file.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index d39b12d43..7415d8a78 100644 --- a/lib/file.c +++ b/lib/file.c @@ -37,8 +37,6 @@ #include #endif -#include - #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) #include #include -- cgit v1.2.1 From cfdcae4bc75fba04b9864cae18e0bbe66b8655b9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 19 Aug 2006 21:18:36 +0000 Subject: Based on a patch by Armel Asselin, the FTP code no longer re-issues the TYPE command on subsequent requests on a re-used connection unless it has to. --- lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 7415d8a78..7ac53f19b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -311,11 +311,11 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) CURLcode result; snprintf(buf, sizeof(data->state.buffer), "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); - result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0); if(result) return result; - result = Curl_client_write(data, CLIENTWRITE_BOTH, + result = Curl_client_write(conn, CLIENTWRITE_BOTH, (char *)"Accept-ranges: bytes\r\n", 0); if(result) return result; @@ -339,7 +339,7 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) tm->tm_hour, tm->tm_min, tm->tm_sec); - result = Curl_client_write(data, CLIENTWRITE_BOTH, buf, 0); + result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0); } return result; } @@ -377,7 +377,7 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) bytecount += nread; - res = Curl_client_write(data, CLIENTWRITE_BODY, buf, nread); + res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread); if(res) return res; -- cgit v1.2.1 From 59cf6fd4f058917839a407f5a206f5f1c1a004a6 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Tue, 29 Aug 2006 18:45:55 +0000 Subject: Watcom lacks . --- lib/file.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 7ac53f19b..83cf8c679 100644 --- a/lib/file.c +++ b/lib/file.c @@ -48,7 +48,9 @@ #ifdef HAVE_NETINET_IN_H #include #endif +#ifndef __WATCOMC__ #include +#endif #ifdef HAVE_UNISTD_H #include #endif -- cgit v1.2.1 From c7aae1030004da71c7c046fd6af259f91bbfa991 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Wed, 30 Aug 2006 16:17:06 +0000 Subject: Removed "#ifndef__WATCOMC__". Use "#ifdef HAVE_SYS_TIME_H" instead. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 83cf8c679..4fb5b1f5f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -48,7 +48,7 @@ #ifdef HAVE_NETINET_IN_H #include #endif -#ifndef __WATCOMC__ +#ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_UNISTD_H -- cgit v1.2.1 From 4f4277d9c73b876d0054474d1f696a555c5c9966 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Sun, 3 Sep 2006 13:52:07 +0000 Subject: Simplified #ifdef on WIN32; the statement " !defined(__GNUC__) || defined(__MINGW32__)" implies CygWin. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4fb5b1f5f..6643e8015 100644 --- a/lib/file.c +++ b/lib/file.c @@ -37,7 +37,7 @@ #include #endif -#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__) +#if defined(WIN32) && !defined(__CYGWIN__) #include #include #include -- cgit v1.2.1 From b7eeb6e67fca686f840eacd6b8394edb58b07482 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 7 Sep 2006 21:49:20 +0000 Subject: Major overhaul introducing http pipelining support and shared connection cache within the multi handle. --- lib/file.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6643e8015..1d4356b8f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -102,7 +102,7 @@ */ CURLcode Curl_file_connect(struct connectdata *conn) { - char *real_path = curl_easy_unescape(conn->data, conn->path, 0, NULL); + char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0, NULL); struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) @@ -119,7 +119,11 @@ CURLcode Curl_file_connect(struct connectdata *conn) return CURLE_OUT_OF_MEMORY; } - conn->proto.file = file; + if (conn->data->reqdata.proto.file) { + free(conn->data->reqdata.proto.file); + } + + conn->data->reqdata.proto.file = file; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) /* If the first character is a slash, and there's @@ -160,7 +164,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) file->fd = fd; if(!conn->data->set.upload && (fd == -1)) { - failf(conn->data, "Couldn't open file %s", conn->path); + failf(conn->data, "Couldn't open file %s", conn->data->reqdata.path); Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE); return CURLE_FILE_COULDNT_READ_FILE; } @@ -171,7 +175,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) CURLcode Curl_file_done(struct connectdata *conn, CURLcode status) { - struct FILEPROTO *file = conn->proto.file; + struct FILEPROTO *file = conn->data->reqdata.proto.file; (void)status; /* not used */ Curl_safefree(file->freepath); @@ -189,7 +193,7 @@ CURLcode Curl_file_done(struct connectdata *conn, static CURLcode file_upload(struct connectdata *conn) { - struct FILEPROTO *file = conn->proto.file; + struct FILEPROTO *file = conn->data->reqdata.proto.file; char *dir = strchr(file->path, DIRSEP); FILE *fp; CURLcode res=CURLE_OK; @@ -206,7 +210,7 @@ static CURLcode file_upload(struct connectdata *conn) */ conn->fread = data->set.fread; conn->fread_in = data->set.in; - conn->upload_fromhere = buf; + conn->data->reqdata.upload_fromhere = buf; if(!dir) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ @@ -297,7 +301,7 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) return file_upload(conn); /* get the fd from the connection phase */ - fd = conn->proto.file->fd; + fd = conn->data->reqdata.proto.file->fd; /* VMS: This only works reliable for STREAMLF files */ if( -1 != fstat(fd, &statbuf)) { @@ -346,8 +350,8 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) return result; } - if (conn->resume_from <= expected_size) - expected_size -= conn->resume_from; + if (data->reqdata.resume_from <= expected_size) + expected_size -= data->reqdata.resume_from; else { failf(data, "failed to resume file:// transfer"); return CURLE_BAD_DOWNLOAD_RESUME; @@ -363,8 +367,8 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) if(fstated) Curl_pgrsSetDownloadSize(data, expected_size); - if(conn->resume_from) - lseek(fd, conn->resume_from, SEEK_SET); + if(data->reqdata.resume_from) + lseek(fd, data->reqdata.resume_from, SEEK_SET); Curl_pgrsTime(data, TIMER_STARTTRANSFER); -- cgit v1.2.1 From e150150d9f1e0578c85af05de15ab6336066cec1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 11 Oct 2006 16:01:16 +0000 Subject: Remove redundant __CYGWIN__ symbol check --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1d4356b8f..e9ed5b7f0 100644 --- a/lib/file.c +++ b/lib/file.c @@ -37,7 +37,7 @@ #include #endif -#if defined(WIN32) && !defined(__CYGWIN__) +#ifdef WIN32 #include #include #include -- cgit v1.2.1 From a8996b9e5268f8ca33deca21e1375a8887c50d40 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 18 Oct 2006 14:47:58 +0000 Subject: use the return code from lseek() to detect problems and bail out if so --- lib/file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index e9ed5b7f0..602299d01 100644 --- a/lib/file.c +++ b/lib/file.c @@ -367,8 +367,11 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) if(fstated) Curl_pgrsSetDownloadSize(data, expected_size); - if(data->reqdata.resume_from) - lseek(fd, data->reqdata.resume_from, SEEK_SET); + if(data->reqdata.resume_from) { + if(data->reqdata.resume_from != + lseek(fd, data->reqdata.resume_from, SEEK_SET)) + return CURLE_BAD_DOWNLOAD_RESUME; + } Curl_pgrsTime(data, TIMER_STARTTRANSFER); -- cgit v1.2.1 From 385e612fa5b7663fc2bc815677b8c27bec2f0fe4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 16 Jan 2007 22:22:10 +0000 Subject: - Armel Asselin improved libcurl to behave a lot better when an easy handle doing an FTP transfer is removed from a multi handle before completion. The fix also fixed the "alive counter" to be correct on "premature removal" for all protocols. --- lib/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 602299d01..b247a7736 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2006, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -165,7 +165,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) file->fd = fd; if(!conn->data->set.upload && (fd == -1)) { failf(conn->data, "Couldn't open file %s", conn->data->reqdata.path); - Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE); + Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } @@ -173,10 +173,11 @@ CURLcode Curl_file_connect(struct connectdata *conn) } CURLcode Curl_file_done(struct connectdata *conn, - CURLcode status) + CURLcode status, bool premature) { struct FILEPROTO *file = conn->data->reqdata.proto.file; (void)status; /* not used */ + (void)premature; /* not used */ Curl_safefree(file->freepath); if(file->fd != -1) -- cgit v1.2.1 From c514a2a89aa1c1e06b70405eedb4e1f70b27fd10 Mon Sep 17 00:00:00 2001 From: Gisle Vanem Date: Mon, 26 Feb 2007 04:24:26 +0000 Subject: Removed inclusion of and in .c-files since they're already included through "setup.h". --- lib/file.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b247a7736..3fc1663d1 100644 --- a/lib/file.c +++ b/lib/file.c @@ -30,12 +30,6 @@ #include #include #include -#ifdef HAVE_SYS_TYPES_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif #ifdef WIN32 #include -- cgit v1.2.1 From 713c9f8602caf53db2159b3db7d863f15174e987 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 May 2007 08:59:44 +0000 Subject: Feng Tu made (lib)curl support "upload" resuming work for file:// URLs. --- lib/file.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3fc1663d1..3c37f6084 100644 --- a/lib/file.c +++ b/lib/file.c @@ -198,6 +198,8 @@ static CURLcode file_upload(struct connectdata *conn) size_t nwrite; curl_off_t bytecount = 0; struct timeval now = Curl_tvnow(); + struct_stat file_stat; + char* buf2; /* * Since FILE: doesn't do the full init, we need to provide some extra @@ -213,7 +215,11 @@ static CURLcode file_upload(struct connectdata *conn) if(!dir[1]) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ - fp = fopen(file->path, "wb"); + if(data->reqdata.resume_from) + fp = fopen( file->path, "ab" ); + else + fp = fopen(file->path, "wb"); + if(!fp) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; @@ -223,6 +229,17 @@ static CURLcode file_upload(struct connectdata *conn) /* known size of data to "upload" */ Curl_pgrsSetUploadSize(data, data->set.infilesize); + /* treat the negative resume offset value as the case of "-" */ + if(data->reqdata.resume_from < 0){ + if(stat(file->path, &file_stat)){ + fclose(fp); + failf(data, "Can't get the size of %s", file->path); + return CURLE_WRITE_ERROR; + } + else + data->reqdata.resume_from = (curl_off_t)file_stat.st_size; + } + while (res == CURLE_OK) { int readcount; res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount); @@ -234,8 +251,24 @@ static CURLcode file_upload(struct connectdata *conn) nread = (size_t)readcount; + /*skip bytes before resume point*/ + if(data->reqdata.resume_from) { + if( nread <= data->reqdata.resume_from ) { + data->reqdata.resume_from -= nread; + nread = 0; + buf2 = buf; + } + else { + buf2 = buf + data->reqdata.resume_from; + nread -= data->reqdata.resume_from; + data->reqdata.resume_from = 0; + } + } + else + buf2 = buf; + /* write the data to the target */ - nwrite = fwrite(buf, 1, nread, fp); + nwrite = fwrite(buf2, 1, nread, fp); if(nwrite != nread) { res = CURLE_SEND_ERROR; break; -- cgit v1.2.1 From 38b490a310aa6c10581ac67e1be594ce1fa79f6f Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 7 Jun 2007 22:24:53 +0000 Subject: Fixed a compiler warning on uClibc. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3c37f6084..96f53f779 100644 --- a/lib/file.c +++ b/lib/file.c @@ -253,7 +253,7 @@ static CURLcode file_upload(struct connectdata *conn) /*skip bytes before resume point*/ if(data->reqdata.resume_from) { - if( nread <= data->reqdata.resume_from ) { + if( (curl_off_t)nread <= data->reqdata.resume_from ) { data->reqdata.resume_from -= nread; nread = 0; buf2 = buf; -- cgit v1.2.1 From 4cd7f85410ae9590fa4dd274a9c77604b3b8d4fc Mon Sep 17 00:00:00 2001 From: James Housley Date: Wed, 27 Jun 2007 20:15:48 +0000 Subject: Add two new options for the SFTP/SCP/FILE protocols: CURLOPT_NEW_FILE_PERMS and CURLOPT_NEW_DIRECTORY_PERMS. These control the premissions for files and directories created on the remote server. CURLOPT_NEW_FILE_PERMS defaults to 0644 and CURLOPT_NEW_DIRECTORY_PERMS defaults to 0755 --- lib/file.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 96f53f779..cec98986b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -217,8 +217,23 @@ static CURLcode file_upload(struct connectdata *conn) if(data->reqdata.resume_from) fp = fopen( file->path, "ab" ); - else + else { + int fd; + +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) + fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, + conn->data->set.new_file_perms); +#else /* !(WIN32 || MSDOS || __EMX__) */ + fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, + conn->data->set.new_file_perms); +#endif /* !(WIN32 || MSDOS || __EMX__) */ + if (fd < 0) { + failf(data, "Can't open %s for writing", file->path); + return CURLE_WRITE_ERROR; + } + close(fd); fp = fopen(file->path, "wb"); + } if(!fp) { failf(data, "Can't open %s for writing", file->path); -- cgit v1.2.1 From aed0cc6f2a9a7fdaae08ad6700687f7200b4ebaa Mon Sep 17 00:00:00 2001 From: James Housley Date: Thu, 28 Jun 2007 11:11:29 +0000 Subject: Using fdopen() is a more correct way to implement the CURLOPT_NEW_FILE_PREMS file.c, but the debug interface was missing. This adds the routines needed to make the memory debuging work for fdopen(). --- lib/file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index cec98986b..4cab1f1b9 100644 --- a/lib/file.c +++ b/lib/file.c @@ -231,8 +231,7 @@ static CURLcode file_upload(struct connectdata *conn) failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; } - close(fd); - fp = fopen(file->path, "wb"); + fp = fdopen(fd, "wb"); } if(!fp) { -- cgit v1.2.1 From 5ecd56d9646c2adcc70c0369fb6196f62ecc62f4 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 23 Jul 2007 18:51:22 +0000 Subject: Implemented only the parts of Patrick Monnerat's OS/400 patch that renamed some few internal identifiers to avoid conflicts, which could be useful on other platforms. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4cab1f1b9..8562cc21b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -205,7 +205,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->fread = data->set.fread; + conn->fread_func = data->set.fread_func; conn->fread_in = data->set.in; conn->data->reqdata.upload_fromhere = buf; -- cgit v1.2.1 From 91fd2c3bcdc9f0d336c6d7404279db03ea4eaca9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 22 Aug 2007 22:48:41 +0000 Subject: Bug report #1779751 (http://curl.haxx.se/bug/view.cgi?id=1779751) pointed out that doing first a file:// upload and then an FTP upload crashed libcurl or at best caused furious valgrind complaints. Fixed now by making sure we free and clear the file-specific struct properly when done with it. --- lib/file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 8562cc21b..1abc838ea 100644 --- a/lib/file.c +++ b/lib/file.c @@ -96,7 +96,8 @@ */ CURLcode Curl_file_connect(struct connectdata *conn) { - char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0, NULL); + char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0, + NULL); struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) @@ -113,9 +114,8 @@ CURLcode Curl_file_connect(struct connectdata *conn) return CURLE_OUT_OF_MEMORY; } - if (conn->data->reqdata.proto.file) { + if (conn->data->reqdata.proto.file) free(conn->data->reqdata.proto.file); - } conn->data->reqdata.proto.file = file; @@ -177,6 +177,9 @@ CURLcode Curl_file_done(struct connectdata *conn, if(file->fd != -1) close(file->fd); + free(file); + conn->data->reqdata.proto.file= NULL; /* clear it! */ + return CURLE_OK; } -- cgit v1.2.1 From 1b66c1da6c6cf6e33bedbc01c93f5d4c48de4e55 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 29 Aug 2007 05:36:53 +0000 Subject: Added lots of consts --- lib/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1abc838ea..0478d3ebd 100644 --- a/lib/file.c +++ b/lib/file.c @@ -192,7 +192,7 @@ CURLcode Curl_file_done(struct connectdata *conn, static CURLcode file_upload(struct connectdata *conn) { struct FILEPROTO *file = conn->data->reqdata.proto.file; - char *dir = strchr(file->path, DIRSEP); + const char *dir = strchr(file->path, DIRSEP); FILE *fp; CURLcode res=CURLE_OK; struct SessionHandle *data = conn->data; @@ -202,7 +202,7 @@ static CURLcode file_upload(struct connectdata *conn) curl_off_t bytecount = 0; struct timeval now = Curl_tvnow(); struct_stat file_stat; - char* buf2; + const char* buf2; /* * Since FILE: doesn't do the full init, we need to provide some extra @@ -372,11 +372,11 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) return result; if(fstated) { - struct tm *tm; + const struct tm *tm; time_t clock = (time_t)statbuf.st_mtime; #ifdef HAVE_GMTIME_R struct tm buffer; - tm = (struct tm *)gmtime_r(&clock, &buffer); + tm = (const struct tm *)gmtime_r(&clock, &buffer); #else tm = gmtime(&clock); #endif -- cgit v1.2.1 From 16b95fc77316fdd3866f7de4ebb5d14bd136ac11 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 27 Sep 2007 01:45:22 +0000 Subject: Enabled a few more gcc warnings with --enable-debug. Renamed a few variables to avoid shadowing global declarations. --- lib/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 0478d3ebd..88d6bf26a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -373,12 +373,12 @@ CURLcode Curl_file(struct connectdata *conn, bool *done) if(fstated) { const struct tm *tm; - time_t clock = (time_t)statbuf.st_mtime; + time_t filetime = (time_t)statbuf.st_mtime; #ifdef HAVE_GMTIME_R struct tm buffer; - tm = (const struct tm *)gmtime_r(&clock, &buffer); + tm = (const struct tm *)gmtime_r(&filetime, &buffer); #else - tm = gmtime(&clock); + tm = gmtime(&filetime); #endif /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ snprintf(buf, BUFSIZE-1, -- cgit v1.2.1 From 07b6e7363d910ad4828376d568a2f19fd8d64661 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Fri, 12 Oct 2007 13:36:37 +0000 Subject: Added per-protocol callback static tables, replacing callback ptr storage in the connectdata structure by a single handler table ptr. --- lib/file.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 88d6bf26a..dcee427ee 100644 --- a/lib/file.c +++ b/lib/file.c @@ -89,6 +89,33 @@ /* The last #include file should be: */ #include "memdebug.h" + +/* + * Forward declarations. + */ + +static CURLcode Curl_file(struct connectdata *, bool *done); + +/* + * FILE scheme handler. + */ + +const struct Curl_handler Curl_handler_file = { + "FILE", /* scheme */ + NULL, /* setup_connection */ + Curl_file, /* do_it */ + Curl_file_done, /* done */ + NULL, /* do_more */ + NULL, /* connect_it */ + NULL, /* connecting */ + NULL, /* doing */ + NULL, /* proto_getsock */ + NULL, /* doing_getsock */ + NULL, /* disconnect */ + 0, /* defport */ + PROT_FILE /* protocol */ +}; + /* * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to * do protocol-specific actions at connect-time. We emulate a @@ -316,7 +343,7 @@ static CURLcode file_upload(struct connectdata *conn) * opposed to sockets) we instead perform the whole do-operation in this * function. */ -CURLcode Curl_file(struct connectdata *conn, bool *done) +static CURLcode Curl_file(struct connectdata *conn, bool *done) { /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) -- cgit v1.2.1 From 61ffcd781599ac9a9f85b92f4be10588f2015721 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Sat, 13 Oct 2007 00:47:53 +0000 Subject: Made a few more functions static with the protocol handler table in place. --- lib/file.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index dcee427ee..d8a3420c0 100644 --- a/lib/file.c +++ b/lib/file.c @@ -95,6 +95,8 @@ */ static CURLcode Curl_file(struct connectdata *, bool *done); +static CURLcode Curl_file_done(struct connectdata *conn, + CURLcode status, bool premature); /* * FILE scheme handler. @@ -193,8 +195,8 @@ CURLcode Curl_file_connect(struct connectdata *conn) return CURLE_OK; } -CURLcode Curl_file_done(struct connectdata *conn, - CURLcode status, bool premature) +static CURLcode Curl_file_done(struct connectdata *conn, + CURLcode status, bool premature) { struct FILEPROTO *file = conn->data->reqdata.proto.file; (void)status; /* not used */ -- cgit v1.2.1 From 92433e596b7fbfa5c75926705dcfef0080ebf012 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 17 Oct 2007 16:58:32 +0000 Subject: We use this ZERO_NULL to avoid picky compiler warnings, when assigning a NULL pointer to a function pointer var. --- lib/file.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index d8a3420c0..6d4ae9892 100644 --- a/lib/file.c +++ b/lib/file.c @@ -104,16 +104,16 @@ static CURLcode Curl_file_done(struct connectdata *conn, const struct Curl_handler Curl_handler_file = { "FILE", /* scheme */ - NULL, /* setup_connection */ + ZERO_NULL, /* setup_connection */ Curl_file, /* do_it */ Curl_file_done, /* done */ - NULL, /* do_more */ - NULL, /* connect_it */ - NULL, /* connecting */ - NULL, /* doing */ - NULL, /* proto_getsock */ - NULL, /* doing_getsock */ - NULL, /* disconnect */ + ZERO_NULL, /* do_more */ + ZERO_NULL, /* connect_it */ + ZERO_NULL, /* connecting */ + ZERO_NULL, /* doing */ + ZERO_NULL, /* proto_getsock */ + ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* disconnect */ 0, /* defport */ PROT_FILE /* protocol */ }; -- cgit v1.2.1 From 5b358603bd8897dcd38795c1ae971a8f917e97df Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 22 Oct 2007 15:05:35 +0000 Subject: Michal Marek forwarded the bug report https://bugzilla.novell.com/show_bug.cgi?id=332917 about a HTTP redirect to FTP that caused memory havoc. His work together with my efforts created two fixes: #1 - FTP::file was moved to struct ftp_conn, because is has to be dealt with at connection cleanup, at which time the struct HandleData could be used by another connection. Also, the unused char *urlpath member is removed from struct FTP. #2 - provide a Curl_reset_reqproto() function that frees data->reqdata.proto.* on connection setup if needed (that is if the SessionHandle was used by a different connection). --- lib/file.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6d4ae9892..bce92bd2a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -125,8 +125,8 @@ const struct Curl_handler Curl_handler_file = { */ CURLcode Curl_file_connect(struct connectdata *conn) { - char *real_path = curl_easy_unescape(conn->data, conn->data->reqdata.path, 0, - NULL); + struct SessionHandle *data = conn->data; + char *real_path = curl_easy_unescape(data, data->reqdata.path, 0, NULL); struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) @@ -137,16 +137,18 @@ CURLcode Curl_file_connect(struct connectdata *conn) if(!real_path) return CURLE_OUT_OF_MEMORY; - file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); - if(!file) { - free(real_path); - return CURLE_OUT_OF_MEMORY; - } - - if (conn->data->reqdata.proto.file) - free(conn->data->reqdata.proto.file); + /* If there already is a protocol-specific struct allocated for this + sessionhandle, deal with it */ + Curl_reset_reqproto(conn); - conn->data->reqdata.proto.file = file; + if (!data->reqdata.proto.file) { + file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); + if(!file) { + free(real_path); + return CURLE_OUT_OF_MEMORY; + } + data->reqdata.proto.file = file; + } #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) /* If the first character is a slash, and there's @@ -186,8 +188,8 @@ CURLcode Curl_file_connect(struct connectdata *conn) file->freepath = real_path; /* free this when done */ file->fd = fd; - if(!conn->data->set.upload && (fd == -1)) { - failf(conn->data, "Couldn't open file %s", conn->data->reqdata.path); + if(!data->set.upload && (fd == -1)) { + failf(data, "Couldn't open file %s", data->reqdata.path); Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } -- cgit v1.2.1 From b9a305983fad324a722f8865a4f4d22535ab6c84 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 23 Oct 2007 15:16:46 +0000 Subject: File is not a protocol that can deal with "persistancy" --- lib/file.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index bce92bd2a..0bc0e4942 100644 --- a/lib/file.c +++ b/lib/file.c @@ -149,6 +149,16 @@ CURLcode Curl_file_connect(struct connectdata *conn) } data->reqdata.proto.file = file; } + else { + /* file is not a protocol that can deal with "persistancy" */ + file = data->reqdata.proto.file; + Curl_safefree(file->freepath); + if(file->fd != -1) + close(file->fd); + file->path = NULL; + file->freepath = NULL; + file->fd = -1; + } #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) /* If the first character is a slash, and there's -- cgit v1.2.1 From 59b05ac383f45ac3fe2e9fba899b440def9da2bd Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 30 Oct 2007 23:00:40 +0000 Subject: Fixed an OOM problem with file: URLs Moved Curl_file_connect into the protocol handler struct. --- lib/file.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 0bc0e4942..f344404db 100644 --- a/lib/file.c +++ b/lib/file.c @@ -97,6 +97,7 @@ static CURLcode Curl_file(struct connectdata *, bool *done); static CURLcode Curl_file_done(struct connectdata *conn, CURLcode status, bool premature); +static CURLcode Curl_file_connect(struct connectdata *conn, bool *done); /* * FILE scheme handler. @@ -108,7 +109,7 @@ const struct Curl_handler Curl_handler_file = { Curl_file, /* do_it */ Curl_file_done, /* done */ ZERO_NULL, /* do_more */ - ZERO_NULL, /* connect_it */ + Curl_file_connect, /* connect_it */ ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_getsock */ @@ -123,7 +124,7 @@ const struct Curl_handler Curl_handler_file = { * do protocol-specific actions at connect-time. We emulate a * connect-then-transfer protocol and "connect" to the file here */ -CURLcode Curl_file_connect(struct connectdata *conn) +static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) { struct SessionHandle *data = conn->data; char *real_path = curl_easy_unescape(data, data->reqdata.path, 0, NULL); @@ -203,6 +204,7 @@ CURLcode Curl_file_connect(struct connectdata *conn) Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } + *done = TRUE; return CURLE_OK; } @@ -218,9 +220,6 @@ static CURLcode Curl_file_done(struct connectdata *conn, if(file->fd != -1) close(file->fd); - free(file); - conn->data->reqdata.proto.file= NULL; /* clear it! */ - return CURLE_OK; } -- cgit v1.2.1 From cbd1a77ec24e397d05f20c6de106625676343c9d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Nov 2007 09:21:35 +0000 Subject: if () => if() while () => while() and some other minor re-indentings --- lib/file.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index f344404db..3b68eb229 100644 --- a/lib/file.c +++ b/lib/file.c @@ -142,7 +142,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) sessionhandle, deal with it */ Curl_reset_reqproto(conn); - if (!data->reqdata.proto.file) { + if(!data->reqdata.proto.file) { file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); if(!file) { free(real_path); @@ -177,7 +177,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) with a drive letter. */ actual_path = real_path; - if ((actual_path[0] == '/') && + if((actual_path[0] == '/') && actual_path[1] && (actual_path[2] == ':' || actual_path[2] == '|')) { @@ -187,7 +187,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */ for (i=0; actual_path[i] != '\0'; ++i) - if (actual_path[i] == '/') + if(actual_path[i] == '/') actual_path[i] = '\\'; fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ @@ -270,7 +270,7 @@ static CURLcode file_upload(struct connectdata *conn) fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, conn->data->set.new_file_perms); #endif /* !(WIN32 || MSDOS || __EMX__) */ - if (fd < 0) { + if(fd < 0) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; } @@ -297,13 +297,13 @@ static CURLcode file_upload(struct connectdata *conn) data->reqdata.resume_from = (curl_off_t)file_stat.st_size; } - while (res == CURLE_OK) { + while(res == CURLE_OK) { int readcount; res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount); if(res) break; - if (readcount <= 0) /* fix questionable compare error. curlvms */ + if(readcount <= 0) /* fix questionable compare error. curlvms */ break; nread = (size_t)readcount; @@ -435,14 +435,14 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) return result; } - if (data->reqdata.resume_from <= expected_size) + if(data->reqdata.resume_from <= expected_size) expected_size -= data->reqdata.resume_from; else { failf(data, "failed to resume file:// transfer"); return CURLE_BAD_DOWNLOAD_RESUME; } - if (fstated && (expected_size == 0)) + if(fstated && (expected_size == 0)) return CURLE_OK; /* The following is a shortcut implementation of file reading @@ -460,13 +460,13 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) Curl_pgrsTime(data, TIMER_STARTTRANSFER); - while (res == CURLE_OK) { + while(res == CURLE_OK) { nread = read(fd, buf, BUFSIZE-1); - if ( nread > 0) + if( nread > 0) buf[nread] = 0; - if (nread <= 0) + if(nread <= 0) break; bytecount += nread; -- cgit v1.2.1 From 50feea3eef87f1c07b954ad3020fdb836c7f279f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 15 Nov 2007 21:45:45 +0000 Subject: Rearranged code and changed Curl_readwrite_init() and Curl_pre_readwrite() into do_init() and do_complete() which now are called first and last in the DO function. It simplified the flow in multi.c and the functions got more sensible names! --- lib/file.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3b68eb229..1461de224 100644 --- a/lib/file.c +++ b/lib/file.c @@ -378,7 +378,6 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) *done = TRUE; /* unconditionally */ - Curl_readwrite_init(conn); Curl_initinfo(data); Curl_pgrsStartNow(data); -- cgit v1.2.1 From 13648f8ccda6f99674ac407640474634e856804c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 24 Nov 2007 23:16:55 +0000 Subject: struct HandleData is now called struct SingleRequest, and is only for data that is inited at the start of the DO action. I removed the Curl_transfer_keeper struct completely, and I had to move out a few struct members (that had to be set before DO or used after DONE) to the UrlState struct. The SingleRequest struct is accessed with SessionHandle->req. One of the biggest reasons for doing this was the bunch of duplicate struct members in HandleData and Curl_transfer_keeper since it was really messy to keep track of two variables with the same name and basically the same purpose! --- lib/file.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1461de224..6a8e1de49 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,7 +127,7 @@ const struct Curl_handler Curl_handler_file = { static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) { struct SessionHandle *data = conn->data; - char *real_path = curl_easy_unescape(data, data->reqdata.path, 0, NULL); + char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL); struct FILEPROTO *file; int fd; #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) @@ -142,17 +142,17 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) sessionhandle, deal with it */ Curl_reset_reqproto(conn); - if(!data->reqdata.proto.file) { + if(!data->state.proto.file) { file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); if(!file) { free(real_path); return CURLE_OUT_OF_MEMORY; } - data->reqdata.proto.file = file; + data->state.proto.file = file; } else { /* file is not a protocol that can deal with "persistancy" */ - file = data->reqdata.proto.file; + file = data->state.proto.file; Curl_safefree(file->freepath); if(file->fd != -1) close(file->fd); @@ -200,7 +200,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) file->fd = fd; if(!data->set.upload && (fd == -1)) { - failf(data, "Couldn't open file %s", data->reqdata.path); + failf(data, "Couldn't open file %s", data->state.path); Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } @@ -212,7 +212,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) static CURLcode Curl_file_done(struct connectdata *conn, CURLcode status, bool premature) { - struct FILEPROTO *file = conn->data->reqdata.proto.file; + struct FILEPROTO *file = conn->data->state.proto.file; (void)status; /* not used */ (void)premature; /* not used */ Curl_safefree(file->freepath); @@ -231,7 +231,7 @@ static CURLcode Curl_file_done(struct connectdata *conn, static CURLcode file_upload(struct connectdata *conn) { - struct FILEPROTO *file = conn->data->reqdata.proto.file; + struct FILEPROTO *file = conn->data->state.proto.file; const char *dir = strchr(file->path, DIRSEP); FILE *fp; CURLcode res=CURLE_OK; @@ -250,7 +250,7 @@ static CURLcode file_upload(struct connectdata *conn) */ conn->fread_func = data->set.fread_func; conn->fread_in = data->set.in; - conn->data->reqdata.upload_fromhere = buf; + conn->data->req.upload_fromhere = buf; if(!dir) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ @@ -258,7 +258,7 @@ static CURLcode file_upload(struct connectdata *conn) if(!dir[1]) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ - if(data->reqdata.resume_from) + if(data->state.resume_from) fp = fopen( file->path, "ab" ); else { int fd; @@ -287,14 +287,14 @@ static CURLcode file_upload(struct connectdata *conn) Curl_pgrsSetUploadSize(data, data->set.infilesize); /* treat the negative resume offset value as the case of "-" */ - if(data->reqdata.resume_from < 0){ + if(data->state.resume_from < 0){ if(stat(file->path, &file_stat)){ fclose(fp); failf(data, "Can't get the size of %s", file->path); return CURLE_WRITE_ERROR; } else - data->reqdata.resume_from = (curl_off_t)file_stat.st_size; + data->state.resume_from = (curl_off_t)file_stat.st_size; } while(res == CURLE_OK) { @@ -309,16 +309,16 @@ static CURLcode file_upload(struct connectdata *conn) nread = (size_t)readcount; /*skip bytes before resume point*/ - if(data->reqdata.resume_from) { - if( (curl_off_t)nread <= data->reqdata.resume_from ) { - data->reqdata.resume_from -= nread; + if(data->state.resume_from) { + if( (curl_off_t)nread <= data->state.resume_from ) { + data->state.resume_from -= nread; nread = 0; buf2 = buf; } else { - buf2 = buf + data->reqdata.resume_from; - nread -= data->reqdata.resume_from; - data->reqdata.resume_from = 0; + buf2 = buf + data->state.resume_from; + nread -= data->state.resume_from; + data->state.resume_from = 0; } } else @@ -385,7 +385,7 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) return file_upload(conn); /* get the fd from the connection phase */ - fd = conn->data->reqdata.proto.file->fd; + fd = conn->data->state.proto.file->fd; /* VMS: This only works reliable for STREAMLF files */ if( -1 != fstat(fd, &statbuf)) { @@ -434,8 +434,8 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) return result; } - if(data->reqdata.resume_from <= expected_size) - expected_size -= data->reqdata.resume_from; + if(data->state.resume_from <= expected_size) + expected_size -= data->state.resume_from; else { failf(data, "failed to resume file:// transfer"); return CURLE_BAD_DOWNLOAD_RESUME; @@ -451,9 +451,9 @@ static CURLcode Curl_file(struct connectdata *conn, bool *done) if(fstated) Curl_pgrsSetDownloadSize(data, expected_size); - if(data->reqdata.resume_from) { - if(data->reqdata.resume_from != - lseek(fd, data->reqdata.resume_from, SEEK_SET)) + if(data->state.resume_from) { + if(data->state.resume_from != + lseek(fd, data->state.resume_from, SEEK_SET)) return CURLE_BAD_DOWNLOAD_RESUME; } -- cgit v1.2.1 From 662bee71930fc30ef3fe43077bf696def44c5c7b Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sat, 8 Dec 2007 22:50:55 +0000 Subject: All static functions that were previously name Curl_* something no longer use that prefix as we use that prefix only for library-wide internal global symbols. --- lib/file.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6a8e1de49..858226416 100644 --- a/lib/file.c +++ b/lib/file.c @@ -94,10 +94,10 @@ * Forward declarations. */ -static CURLcode Curl_file(struct connectdata *, bool *done); -static CURLcode Curl_file_done(struct connectdata *conn, - CURLcode status, bool premature); -static CURLcode Curl_file_connect(struct connectdata *conn, bool *done); +static CURLcode file_do(struct connectdata *, bool *done); +static CURLcode file_done(struct connectdata *conn, + CURLcode status, bool premature); +static CURLcode file_connect(struct connectdata *conn, bool *done); /* * FILE scheme handler. @@ -106,10 +106,10 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done); const struct Curl_handler Curl_handler_file = { "FILE", /* scheme */ ZERO_NULL, /* setup_connection */ - Curl_file, /* do_it */ - Curl_file_done, /* done */ + file_do, /* do_it */ + file_done, /* done */ ZERO_NULL, /* do_more */ - Curl_file_connect, /* connect_it */ + file_connect, /* connect_it */ ZERO_NULL, /* connecting */ ZERO_NULL, /* doing */ ZERO_NULL, /* proto_getsock */ @@ -120,11 +120,11 @@ const struct Curl_handler Curl_handler_file = { }; /* - * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to + * file_connect() gets called from Curl_protocol_connect() to allow us to * do protocol-specific actions at connect-time. We emulate a * connect-then-transfer protocol and "connect" to the file here */ -static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) +static CURLcode file_connect(struct connectdata *conn, bool *done) { struct SessionHandle *data = conn->data; char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL); @@ -201,7 +201,7 @@ static CURLcode Curl_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.path); - Curl_file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); + file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); return CURLE_FILE_COULDNT_READ_FILE; } *done = TRUE; @@ -209,7 +209,7 @@ static CURLcode Curl_file_connect(struct connectdata *conn, bool *done) return CURLE_OK; } -static CURLcode Curl_file_done(struct connectdata *conn, +static CURLcode file_done(struct connectdata *conn, CURLcode status, bool premature) { struct FILEPROTO *file = conn->data->state.proto.file; @@ -349,14 +349,14 @@ static CURLcode file_upload(struct connectdata *conn) } /* - * Curl_file() is the protocol-specific function for the do-phase, separated + * file_do() is the protocol-specific function for the do-phase, separated * from the connect-phase above. Other protocols merely setup the transfer in * the do-phase, to have it done in the main transfer loop but since some * platforms we support don't allow select()ing etc on file handles (as * opposed to sockets) we instead perform the whole do-operation in this * function. */ -static CURLcode Curl_file(struct connectdata *conn, bool *done) +static CURLcode file_do(struct connectdata *conn, bool *done) { /* This implementation ignores the host name in conformance with RFC 1738. Only local files (reachable via the standard file system) -- cgit v1.2.1 From 08adf679691006a8fc45fca07c7a10e6a458283e Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Jan 2008 14:20:41 +0000 Subject: Daniel Egger made CURLOPT_RANGE work on file:// URLs the very same way it already worked for FTP:// URLs --- lib/file.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 5 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 858226416..cbc9f4ce8 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2007, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -70,6 +70,7 @@ #endif +#include "strtoofft.h" #include "urldata.h" #include #include "progress.h" @@ -119,6 +120,61 @@ const struct Curl_handler Curl_handler_file = { PROT_FILE /* protocol */ }; + + /* + Check if this is a range download, and if so, set the internal variables + properly. This code is copied from the FTP implementation and might as + well be factored out. + */ +static CURLcode file_range(struct connectdata *conn) +{ + curl_off_t from, to; + curl_off_t totalsize=-1; + char *ptr; + char *ptr2; + struct SessionHandle *data = conn->data; + + if(data->state.use_range && data->state.range) { + from=curlx_strtoofft(data->state.range, &ptr, 0); + while(ptr && *ptr && (isspace((int)*ptr) || (*ptr=='-'))) + ptr++; + to=curlx_strtoofft(ptr, &ptr2, 0); + if(ptr == ptr2) { + /* we didn't get any digit */ + to=-1; + } + if((-1 == to) && (from>=0)) { + /* X - */ + data->state.resume_from = from; + DEBUGF(infof(data, "RANGE %" FORMAT_OFF_T " to end of file\n", + from)); + } + else if(from < 0) { + /* -Y */ + totalsize = -from; + data->req.maxdownload = -from; + data->state.resume_from = from; + DEBUGF(infof(data, "RANGE the last %" FORMAT_OFF_T " bytes\n", + totalsize)); + } + else { + /* X-Y */ + totalsize = to-from; + data->req.maxdownload = totalsize+1; /* include last byte */ + data->state.resume_from = from; + DEBUGF(infof(data, "RANGE from %" FORMAT_OFF_T + " getting %" FORMAT_OFF_T " bytes\n", + from, data->req.maxdownload)); + } + DEBUGF(infof(data, "range-download from %" FORMAT_OFF_T + " to %" FORMAT_OFF_T ", totally %" FORMAT_OFF_T " bytes\n", + from, to, data->req.maxdownload)); + } + else + data->req.maxdownload = -1; + return CURLE_OK; +} + /* * file_connect() gets called from Curl_protocol_connect() to allow us to * do protocol-specific actions at connect-time. We emulate a @@ -287,8 +343,8 @@ static CURLcode file_upload(struct connectdata *conn) Curl_pgrsSetUploadSize(data, data->set.infilesize); /* treat the negative resume offset value as the case of "-" */ - if(data->state.resume_from < 0){ - if(stat(file->path, &file_stat)){ + if(data->state.resume_from < 0) { + if(stat(file->path, &file_stat)) { fclose(fp); failf(data, "Can't get the size of %s", file->path); return CURLE_WRITE_ERROR; @@ -434,6 +490,20 @@ static CURLcode file_do(struct connectdata *conn, bool *done) return result; } + /* Check whether file range has been specified */ + file_range(conn); + + /* Adjust the start offset in case we want to get the N last bytes + * of the stream iff the filesize could be determined */ + if(data->state.resume_from < 0) { + if(!fstated) { + failf(data, "Can't get the size of file."); + return CURLE_READ_ERROR; + } + else + data->state.resume_from += (curl_off_t)statbuf.st_size; + } + if(data->state.resume_from <= expected_size) expected_size -= data->state.resume_from; else { @@ -441,6 +511,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done) return CURLE_BAD_DOWNLOAD_RESUME; } + /* A high water mark has been specified so we obey... */ + if (data->req.maxdownload > 0) + expected_size = data->req.maxdownload; + if(fstated && (expected_size == 0)) return CURLE_OK; @@ -460,15 +534,20 @@ static CURLcode file_do(struct connectdata *conn, bool *done) Curl_pgrsTime(data, TIMER_STARTTRANSFER); while(res == CURLE_OK) { - nread = read(fd, buf, BUFSIZE-1); + /* Don't fill a whole buffer if we want less than all data */ + if (expected_size < BUFSIZE-1) + nread = read(fd, buf, expected_size); + else + nread = read(fd, buf, BUFSIZE-1); if( nread > 0) buf[nread] = 0; - if(nread <= 0) + if (nread <= 0 || expected_size == 0) break; bytecount += nread; + expected_size -= nread; res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread); if(res) -- cgit v1.2.1 From a0420904678c3f084790a19ce8cc8cbce76cb353 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 11 Jan 2008 16:49:35 +0000 Subject: fix compiler warning --- lib/file.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index cbc9f4ce8..bfc2b015e 100644 --- a/lib/file.c +++ b/lib/file.c @@ -373,7 +373,7 @@ static CURLcode file_upload(struct connectdata *conn) } else { buf2 = buf + data->state.resume_from; - nread -= data->state.resume_from; + nread -= (size_t)data->state.resume_from; data->state.resume_from = 0; } } @@ -426,6 +426,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) curl_off_t expected_size=0; bool fstated=FALSE; ssize_t nread; + size_t bytestoread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; @@ -535,10 +536,8 @@ static CURLcode file_do(struct connectdata *conn, bool *done) while(res == CURLE_OK) { /* Don't fill a whole buffer if we want less than all data */ - if (expected_size < BUFSIZE-1) - nread = read(fd, buf, expected_size); - else - nread = read(fd, buf, BUFSIZE-1); + bytestoread = (expected_size < BUFSIZE-1)?(size_t)expected_size:BUFSIZE-1; + nread = read(fd, buf, bytestoread); if( nread > 0) buf[nread] = 0; -- cgit v1.2.1 From b620e62f0f4e90f4d1338117c67580a6f5f37377 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 31 Jan 2008 12:04:33 +0000 Subject: - Dmitry Kurochkin moved several struct fields from the connectdata struct to the SingleRequest one to make pipelining better. It is a bit tricky to keep them in the right place, to keep things related to the actual request or to the actual connection in the right place. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index bfc2b015e..1e8374693 100644 --- a/lib/file.c +++ b/lib/file.c @@ -454,7 +454,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) /* If we have selected NOBODY and HEADER, it means that we only want file information. Which for FILE can't be much more than the file size and date. */ - if(conn->bits.no_body && data->set.include_header && fstated) { + if(data->set.opt_no_body && data->set.include_header && fstated) { CURLcode result; snprintf(buf, sizeof(data->state.buffer), "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); -- cgit v1.2.1 From 09777a4fc2ed0f2b09447eb89fb8cd4b99278944 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Thu, 17 Apr 2008 00:45:33 +0000 Subject: Some trivial changes --- lib/file.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1e8374693..c79c635ec 100644 --- a/lib/file.c +++ b/lib/file.c @@ -68,7 +68,7 @@ #include #endif -#endif +#endif /* WIN32 */ #include "strtoofft.h" #include "urldata.h" @@ -90,6 +90,9 @@ /* The last #include file should be: */ #include "memdebug.h" +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#define MSDOS_FILESYSTEM 1 +#endif /* * Forward declarations. @@ -186,7 +189,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL); struct FILEPROTO *file; int fd; -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#ifdef MSDOS_FILESYSTEM int i; char *actual_path; #endif @@ -217,7 +220,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) file->fd = -1; } -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#ifdef MSDOS_FILESYSTEM /* If the first character is a slash, and there's something that looks like a drive at the beginning of the path, skip the slash. If we remove the initial @@ -279,7 +282,7 @@ static CURLcode file_done(struct connectdata *conn, return CURLE_OK; } -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#ifdef MSDOS_FILESYSTEM #define DIRSEP '\\' #else #define DIRSEP '/' @@ -319,13 +322,13 @@ static CURLcode file_upload(struct connectdata *conn) else { int fd; -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#ifdef MSDOS_FILESYSTEM fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, conn->data->set.new_file_perms); -#else /* !(WIN32 || MSDOS || __EMX__) */ +#else fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, conn->data->set.new_file_perms); -#endif /* !(WIN32 || MSDOS || __EMX__) */ +#endif if(fd < 0) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; -- cgit v1.2.1 From 1960eebc2d021ecf5ffc3f6d4e935d54aa592c72 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Tue, 22 Apr 2008 22:53:53 +0000 Subject: Added support for running on Symbian OS. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index c79c635ec..33f9c10fd 100644 --- a/lib/file.c +++ b/lib/file.c @@ -90,7 +90,7 @@ /* The last #include file should be: */ #include "memdebug.h" -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || defined(__SYMBIAN32__) #define MSDOS_FILESYSTEM 1 #endif -- cgit v1.2.1 From 791ad1210e467bf5704970fe89bf82fdf6d63386 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 21 May 2008 21:36:42 +0000 Subject: Renamed MSDOS_FILESYSTEM to avoid conflict with MIT GSS --- lib/file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 33f9c10fd..08d26c54a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -91,7 +91,7 @@ #include "memdebug.h" #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || defined(__SYMBIAN32__) -#define MSDOS_FILESYSTEM 1 +#define DOS_FILESYSTEM 1 #endif /* @@ -189,7 +189,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL); struct FILEPROTO *file; int fd; -#ifdef MSDOS_FILESYSTEM +#ifdef DOS_FILESYSTEM int i; char *actual_path; #endif @@ -220,7 +220,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) file->fd = -1; } -#ifdef MSDOS_FILESYSTEM +#ifdef DOS_FILESYSTEM /* If the first character is a slash, and there's something that looks like a drive at the beginning of the path, skip the slash. If we remove the initial @@ -282,7 +282,7 @@ static CURLcode file_done(struct connectdata *conn, return CURLE_OK; } -#ifdef MSDOS_FILESYSTEM +#ifdef DOS_FILESYSTEM #define DIRSEP '\\' #else #define DIRSEP '/' @@ -322,7 +322,7 @@ static CURLcode file_upload(struct connectdata *conn) else { int fd; -#ifdef MSDOS_FILESYSTEM +#ifdef DOS_FILESYSTEM fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, conn->data->set.new_file_perms); #else -- cgit v1.2.1 From 66fb9ca5f6de6eb74c2c3ade7ee651a299247749 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 15 Aug 2008 02:58:15 +0000 Subject: For congruency sake with the naming of other CURL_XXXXXX_CURL_OFF_T macros, the names of the curl_off_t formatting string directives now become CURL_FORMAT_CURL_OFF_T and CURL_FORMAT_CURL_OFF_TU. CURL_FMT_OFF_T -> CURL_FORMAT_CURL_OFF_T CURL_FMT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU Remove the use of an internal name for the curl_off_t formatting string directives and use the common one available from the inside and outside of the library. FORMAT_OFF_T -> CURL_FORMAT_CURL_OFF_T FORMAT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU --- lib/file.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 08d26c54a..ced1a6ca8 100644 --- a/lib/file.c +++ b/lib/file.c @@ -149,7 +149,7 @@ static CURLcode file_range(struct connectdata *conn) if((-1 == to) && (from>=0)) { /* X - */ data->state.resume_from = from; - DEBUGF(infof(data, "RANGE %" FORMAT_OFF_T " to end of file\n", + DEBUGF(infof(data, "RANGE %" CURL_FORMAT_CURL_OFF_T " to end of file\n", from)); } else if(from < 0) { @@ -157,7 +157,7 @@ static CURLcode file_range(struct connectdata *conn) totalsize = -from; data->req.maxdownload = -from; data->state.resume_from = from; - DEBUGF(infof(data, "RANGE the last %" FORMAT_OFF_T " bytes\n", + DEBUGF(infof(data, "RANGE the last %" CURL_FORMAT_CURL_OFF_T " bytes\n", totalsize)); } else { @@ -165,12 +165,13 @@ static CURLcode file_range(struct connectdata *conn) totalsize = to-from; data->req.maxdownload = totalsize+1; /* include last byte */ data->state.resume_from = from; - DEBUGF(infof(data, "RANGE from %" FORMAT_OFF_T - " getting %" FORMAT_OFF_T " bytes\n", + DEBUGF(infof(data, "RANGE from %" CURL_FORMAT_CURL_OFF_T + " getting %" CURL_FORMAT_CURL_OFF_T " bytes\n", from, data->req.maxdownload)); } - DEBUGF(infof(data, "range-download from %" FORMAT_OFF_T - " to %" FORMAT_OFF_T ", totally %" FORMAT_OFF_T " bytes\n", + DEBUGF(infof(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)); } else @@ -460,7 +461,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) if(data->set.opt_no_body && data->set.include_header && fstated) { CURLcode result; snprintf(buf, sizeof(data->state.buffer), - "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); + "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size); result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0); if(result) return result; -- cgit v1.2.1 From ad638da2c29a61babb50fdced0333393416a199a Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 16 Aug 2008 01:33:59 +0000 Subject: Library internal only C preprocessor macros FORMAT_OFF_T and FORMAT_OFF_TU remain in use as internal curl_off_t print formatting strings for the internal *printf functions which still cannot handle print formatting string directives such as "I64d", "I64u", and others available on MSVC, MinGW, Intel's ICC, and other DOS/Windows compilers. This reverts previous commit part which did: FORMAT_OFF_T -> CURL_FORMAT_CURL_OFF_T FORMAT_OFF_TU -> CURL_FORMAT_CURL_OFF_TU --- lib/file.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index ced1a6ca8..08d26c54a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -149,7 +149,7 @@ static CURLcode file_range(struct connectdata *conn) if((-1 == to) && (from>=0)) { /* X - */ data->state.resume_from = from; - DEBUGF(infof(data, "RANGE %" CURL_FORMAT_CURL_OFF_T " to end of file\n", + DEBUGF(infof(data, "RANGE %" FORMAT_OFF_T " to end of file\n", from)); } else if(from < 0) { @@ -157,7 +157,7 @@ static CURLcode file_range(struct connectdata *conn) totalsize = -from; data->req.maxdownload = -from; data->state.resume_from = from; - DEBUGF(infof(data, "RANGE the last %" CURL_FORMAT_CURL_OFF_T " bytes\n", + DEBUGF(infof(data, "RANGE the last %" FORMAT_OFF_T " bytes\n", totalsize)); } else { @@ -165,13 +165,12 @@ static CURLcode file_range(struct connectdata *conn) totalsize = to-from; data->req.maxdownload = totalsize+1; /* include last byte */ data->state.resume_from = from; - DEBUGF(infof(data, "RANGE from %" CURL_FORMAT_CURL_OFF_T - " getting %" CURL_FORMAT_CURL_OFF_T " bytes\n", + DEBUGF(infof(data, "RANGE from %" FORMAT_OFF_T + " getting %" FORMAT_OFF_T " bytes\n", from, data->req.maxdownload)); } - DEBUGF(infof(data, "range-download from %" CURL_FORMAT_CURL_OFF_T - " to %" CURL_FORMAT_CURL_OFF_T - ", totally %" CURL_FORMAT_CURL_OFF_T " bytes\n", + DEBUGF(infof(data, "range-download from %" FORMAT_OFF_T + " to %" FORMAT_OFF_T ", totally %" FORMAT_OFF_T " bytes\n", from, to, data->req.maxdownload)); } else @@ -461,7 +460,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) if(data->set.opt_no_body && data->set.include_header && fstated) { CURLcode result; snprintf(buf, sizeof(data->state.buffer), - "Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", expected_size); + "Content-Length: %" FORMAT_OFF_T "\r\n", expected_size); result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0); if(result) return result; -- cgit v1.2.1 From a622fd90b4c563a4fced20c5b88cb57537e809b0 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 04:47:14 +0000 Subject: remove unnecessary typecasting of calloc() --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 08d26c54a..6dd63b6a2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -202,7 +202,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) Curl_reset_reqproto(conn); if(!data->state.proto.file) { - file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1); + file = calloc(sizeof(struct FILEPROTO), 1); if(!file) { free(real_path); return CURLE_OUT_OF_MEMORY; -- cgit v1.2.1 From 6cea51585fc82f3abc540abfc2068517fb804128 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 10 Sep 2008 20:05:45 +0000 Subject: Checked in some code improvements and minor fixes that I discovered in the FreeBSD ports system. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6dd63b6a2..5e652001b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -347,7 +347,7 @@ static CURLcode file_upload(struct connectdata *conn) /* treat the negative resume offset value as the case of "-" */ if(data->state.resume_from < 0) { - if(stat(file->path, &file_stat)) { + if(fstat(fileno(fp), &file_stat)) { fclose(fp); failf(data, "Can't get the size of %s", file->path); return CURLE_WRITE_ERROR; -- cgit v1.2.1 From 2bcd13aaee0476a6b3e63cb600bad2dd0ca593f2 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 12 Sep 2008 03:24:27 +0000 Subject: ANSI C compatibility fix --- lib/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 5e652001b..9b9ef2be3 100644 --- a/lib/file.c +++ b/lib/file.c @@ -333,7 +333,8 @@ static CURLcode file_upload(struct connectdata *conn) failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; } - fp = fdopen(fd, "wb"); + close(fd); + fp = fopen(file->path, "wb"); } if(!fp) { -- cgit v1.2.1 From 8f467b4288b69e0cd2355cdb8d4dd8356950e447 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 29 Sep 2008 21:44:50 +0000 Subject: Removed unneeded includes of signal.h and setjmp.h --- lib/file.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9b9ef2be3..de5d52b32 100644 --- a/lib/file.c +++ b/lib/file.c @@ -58,7 +58,6 @@ #include #endif #include -#include #ifdef HAVE_SYS_PARAM_H #include -- cgit v1.2.1 From 5ca2a8318d0df95d24180b72040b21a21d9ba5ef Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 4 Nov 2008 09:57:36 +0000 Subject: CURLINFO_FILETIME now works for file:// transfers as well --- lib/file.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index de5d52b32..b0af2fcd9 100644 --- a/lib/file.c +++ b/lib/file.c @@ -451,6 +451,8 @@ static CURLcode file_do(struct connectdata *conn, bool *done) if( -1 != fstat(fd, &statbuf)) { /* we could stat it, then read out the size */ expected_size = statbuf.st_size; + /* and store the modification time */ + data->info.filetime = (long)statbuf.st_mtime; fstated = TRUE; } -- cgit v1.2.1 From ea8fbb5233b24745177871a7e1e9105a137f94f9 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 14 Nov 2008 23:17:32 +0000 Subject: Added some #ifdefs around header files and change the EAGAIN test to fix compilation on Cell (reported by Jeff Curley). --- lib/file.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b0af2fcd9..d1302ab81 100644 --- a/lib/file.c +++ b/lib/file.c @@ -57,7 +57,9 @@ #ifdef HAVE_NET_IF_H #include #endif +#ifdef HAVE_SYS_IOCTL_H #include +#endif #ifdef HAVE_SYS_PARAM_H #include -- cgit v1.2.1 From 07416b61e3c403ea56370858a618f877dcaee57d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 19 Dec 2008 21:14:52 +0000 Subject: - Using the libssh2 0.19 function libssh2_session_block_directions(), libcurl now has an improved ability to do right when the multi interface (both "regular" and multi_socket) is used for SCP and SFTP transfers. This should result in (much) less busy-loop situations and thus less CPU usage with no speed loss. --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index d1302ab81..fb8b46a48 100644 --- a/lib/file.c +++ b/lib/file.c @@ -119,6 +119,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* doing */ ZERO_NULL, /* proto_getsock */ ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* perform_getsock */ ZERO_NULL, /* disconnect */ 0, /* defport */ PROT_FILE /* protocol */ -- cgit v1.2.1 From 71f3877f3a2e76b4c32f625438c36cd739884c06 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 3 Feb 2009 22:28:41 +0000 Subject: - Hidemoto Nakada provided a small fix that makes it possible to get the CURLINFO_CONTENT_LENGTH_DOWNLOAD size from file:// "transfers" with CURLOPT_NOBODY set true. --- lib/file.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index fb8b46a48..9aae1e4df 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -496,6 +496,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done) tm->tm_sec); result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0); } + /* if we fstat()ed the file, set the file size to make it available post- + transfer */ + if(fstated) + Curl_pgrsSetDownloadSize(data, expected_size); return result; } -- cgit v1.2.1 From 33a3753c3f41d546ebf3350685eb7201d25783f4 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 21 Apr 2009 11:46:16 +0000 Subject: libcurl's memory.h renamed to curl_memory.h --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9aae1e4df..7e55bd6db 100644 --- a/lib/file.c +++ b/lib/file.c @@ -82,7 +82,7 @@ #include "getinfo.h" #include "transfer.h" #include "url.h" -#include "memory.h" +#include "curl_memory.h" #include "parsedate.h" /* for the week day and month names */ #define _MPRINTF_REPLACE /* use our functions only */ -- cgit v1.2.1 From 00883822be245d2660a569e6bde38892b9433aa2 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 4 Jun 2009 19:11:11 +0000 Subject: allow building libcurl for VxWorks --- lib/file.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 7e55bd6db..3d1d2bbcb 100644 --- a/lib/file.c +++ b/lib/file.c @@ -95,6 +95,12 @@ #define DOS_FILESYSTEM 1 #endif +#ifdef OPEN_NEEDS_ARG3 +# define open_readonly(p,f) open((p),(f),(0)) +#else +# define open_readonly(p,f) open((p),(f)) +#endif + /* * Forward declarations. */ @@ -251,10 +257,10 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) if(actual_path[i] == '/') actual_path[i] = '\\'; - fd = open(actual_path, O_RDONLY | O_BINARY); /* no CR/LF translation! */ + fd = open_readonly(actual_path, O_RDONLY|O_BINARY); /* no CR/LF translation */ file->path = actual_path; #else - fd = open(real_path, O_RDONLY); + fd = open_readonly(real_path, O_RDONLY); file->path = real_path; #endif file->freepath = real_path; /* free this when done */ -- cgit v1.2.1 From 59939313f8452a9d817c178425c2ba3b91798ea9 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Wed, 18 Nov 2009 10:33:54 +0000 Subject: Make usage of calloc()'s arguments consistent with rest of code base --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 3d1d2bbcb..b4dc17d93 100644 --- a/lib/file.c +++ b/lib/file.c @@ -210,7 +210,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) Curl_reset_reqproto(conn); if(!data->state.proto.file) { - file = calloc(sizeof(struct FILEPROTO), 1); + file = calloc(1, sizeof(struct FILEPROTO)); if(!file) { free(real_path); return CURLE_OUT_OF_MEMORY; -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- lib/file.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index b4dc17d93..6c14ee8e6 100644 --- a/lib/file.c +++ b/lib/file.c @@ -18,7 +18,6 @@ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * - * $Id$ ***************************************************************************/ #include "setup.h" -- cgit v1.2.1 From 01fc53e027efc9c9217be0b773c7a49f97291add Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Apr 2010 22:52:49 +0200 Subject: file_range: Value stored to 'totalsize' is never read --- lib/file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6c14ee8e6..f96f8f51a 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2009, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -161,11 +161,10 @@ static CURLcode file_range(struct connectdata *conn) } else if(from < 0) { /* -Y */ - totalsize = -from; data->req.maxdownload = -from; data->state.resume_from = from; DEBUGF(infof(data, "RANGE the last %" FORMAT_OFF_T " bytes\n", - totalsize)); + -from)); } else { /* X-Y */ -- cgit v1.2.1 From 5d43c75c6696f991bc29dd6ee3bf35ca06101a69 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 16 Apr 2010 23:18:43 +0200 Subject: file_range: remove unnecessary check for NULL pointer --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index f96f8f51a..91176aa11 100644 --- a/lib/file.c +++ b/lib/file.c @@ -146,7 +146,7 @@ static CURLcode file_range(struct connectdata *conn) if(data->state.use_range && data->state.range) { from=curlx_strtoofft(data->state.range, &ptr, 0); - while(ptr && *ptr && (isspace((int)*ptr) || (*ptr=='-'))) + while(*ptr && (isspace((int)*ptr) || (*ptr=='-'))) ptr++; to=curlx_strtoofft(ptr, &ptr2, 0); if(ptr == ptr2) { -- cgit v1.2.1 From c2ba8ca81f8d753a9ac3fdd94a1fb3ea53b64f84 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 26 Nov 2010 13:59:01 +0100 Subject: s/isspace/ISSPACE --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 91176aa11..8e4ee075f 100644 --- a/lib/file.c +++ b/lib/file.c @@ -146,7 +146,7 @@ static CURLcode file_range(struct connectdata *conn) if(data->state.use_range && data->state.range) { from=curlx_strtoofft(data->state.range, &ptr, 0); - while(*ptr && (isspace((int)*ptr) || (*ptr=='-'))) + while(*ptr && (ISSPACE(*ptr) || (*ptr=='-'))) ptr++; to=curlx_strtoofft(ptr, &ptr2, 0); if(ptr == ptr2) { -- cgit v1.2.1 From b89122a2bf1663f16d0977977c83320470c6d438 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 29 Jan 2011 22:41:07 -0500 Subject: file: add support for CURLOPT_TIMECONDITION --- lib/file.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 8e4ee075f..aaeed7075 100644 --- a/lib/file.c +++ b/lib/file.c @@ -463,6 +463,13 @@ static CURLcode file_do(struct connectdata *conn, bool *done) fstated = TRUE; } + if(fstated && !data->state.range && data->set.timecondition) { + if(!Curl_meets_timecondition(data, data->info.filetime)) { + *done = TRUE; + return CURLE_OK; + } + } + /* If we have selected NOBODY and HEADER, it means that we only want file information. Which for FILE can't be much more than the file size and date. */ -- cgit v1.2.1 From 54d9f060b4b0a8fb5fa006813e4db1ca5c1a07e8 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 7 Feb 2011 15:00:48 +0100 Subject: Curl_gmtime: added a portable gmtime Instead of polluting many places with #ifdefs, we create a single place for this function, and also check return code properly so that a NULL pointer returned won't cause problems. --- lib/file.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index aaeed7075..a627a8129 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -487,14 +487,13 @@ static CURLcode file_do(struct connectdata *conn, bool *done) return result; if(fstated) { - const struct tm *tm; time_t filetime = (time_t)statbuf.st_mtime; -#ifdef HAVE_GMTIME_R struct tm buffer; - tm = (const struct tm *)gmtime_r(&filetime, &buffer); -#else - tm = gmtime(&filetime); -#endif + const struct tm *tm = &buffer; + result = Curl_gmtime(filetime, &buffer); + if(result) + return result; + /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */ snprintf(buf, BUFSIZE-1, "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n", -- cgit v1.2.1 From 8511b6436c4e1c6303cc0cb9b41677628289f41a Mon Sep 17 00:00:00 2001 From: Stefan Krause Date: Wed, 23 Feb 2011 19:58:43 +0100 Subject: transfer: avoid insane conversion of time_t --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index a627a8129..d4e941f75 100644 --- a/lib/file.c +++ b/lib/file.c @@ -464,7 +464,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) } if(fstated && !data->state.range && data->set.timecondition) { - if(!Curl_meets_timecondition(data, data->info.filetime)) { + if(!Curl_meets_timecondition(data, (time_t)data->info.filetime)) { *done = TRUE; return CURLE_OK; } -- cgit v1.2.1 From 8831000bc07de463d277975a3ddfb6a31dcf14b4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 14 Mar 2011 22:22:22 +0100 Subject: protocol handler: added flags field The protocol handler struct got a 'flags' field for special information and characteristics of the given protocol. This now enables us to move away central protocol information such as CLOSEACTION and DUALCHANNEL from single defines in a central place, out to each protocol's definition. It also made us stop abusing the protocol field for other info than the protocol, and we could start cleaning up other protocol-specific things by adding flags bits to set in the handler struct. The "protocol" field connectdata struct was removed as well and the code now refers directly to the conn->handler->protocol field instead. To make things work properly, the code now always store a conn->given pointer that points out the original handler struct so that the code can learn details from the original protocol even if conn->handler is modified along the way - for example when switching to go over a HTTP proxy. --- lib/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index d4e941f75..52c175f10 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,7 +127,8 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* perform_getsock */ ZERO_NULL, /* disconnect */ 0, /* defport */ - PROT_FILE /* protocol */ + PROT_FILE, /* protocol */ + PROTOPT_BANPROXY /* flags */ }; -- cgit v1.2.1 From 13b64d75589647f8d151e035bd2c5d340a1c37ee Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 14 Mar 2011 22:52:14 +0100 Subject: protocols: use CURLPROTO_ internally The PROT_* set of internal defines for the protocols is no longer used. We now use the same bits internally as we have defined in the public header using the CURLPROTO_ prefix. This is for simplicity and because the PROT_* prefix was already used duplicated internally for a set of KRB4 values. The PROTOPT_* defines were moved up to just below the struct definition within which they are used. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 52c175f10..ad671233c 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,7 +127,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* perform_getsock */ ZERO_NULL, /* disconnect */ 0, /* defport */ - PROT_FILE, /* protocol */ + CURLPROTO_FILE, /* protocol */ PROTOPT_BANPROXY /* flags */ }; -- cgit v1.2.1 From b903186fa0189ff241d756d25d07fdfe9885ae49 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 20 Apr 2011 15:17:42 +0200 Subject: source cleanup: unify look, style and indent levels By the use of a the new lib/checksrc.pl script that checks that our basic source style rules are followed. --- lib/file.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index ad671233c..1fee92bb2 100644 --- a/lib/file.c +++ b/lib/file.c @@ -90,7 +90,8 @@ /* The last #include file should be: */ #include "memdebug.h" -#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || defined(__SYMBIAN32__) +#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || \ + defined(__SYMBIAN32__) #define DOS_FILESYSTEM 1 #endif @@ -245,18 +246,17 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) actual_path = real_path; if((actual_path[0] == '/') && actual_path[1] && - (actual_path[2] == ':' || actual_path[2] == '|')) - { + (actual_path[2] == ':' || actual_path[2] == '|')) { actual_path[2] = ':'; actual_path++; } /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */ - for (i=0; actual_path[i] != '\0'; ++i) + for(i=0; actual_path[i] != '\0'; ++i) if(actual_path[i] == '/') actual_path[i] = '\\'; - fd = open_readonly(actual_path, O_RDONLY|O_BINARY); /* no CR/LF translation */ + fd = open_readonly(actual_path, O_RDONLY|O_BINARY); file->path = actual_path; #else fd = open_readonly(real_path, O_RDONLY); @@ -536,7 +536,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) } /* A high water mark has been specified so we obey... */ - if (data->req.maxdownload > 0) + if(data->req.maxdownload > 0) expected_size = data->req.maxdownload; if(fstated && (expected_size == 0)) @@ -565,7 +565,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) if( nread > 0) buf[nread] = 0; - if (nread <= 0 || expected_size == 0) + if(nread <= 0 || expected_size == 0) break; bytecount += nread; -- cgit v1.2.1 From 889d1e973fb718a77c5000141d724ce03863af23 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 22 Apr 2011 23:01:30 +0200 Subject: whitespace cleanup: no space first in conditionals "if(a)" is our style, not "if( a )" --- lib/file.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1fee92bb2..a3d80fbd7 100644 --- a/lib/file.c +++ b/lib/file.c @@ -377,7 +377,7 @@ static CURLcode file_upload(struct connectdata *conn) /*skip bytes before resume point*/ if(data->state.resume_from) { - if( (curl_off_t)nread <= data->state.resume_from ) { + if((curl_off_t)nread <= data->state.resume_from ) { data->state.resume_from -= nread; nread = 0; buf2 = buf; @@ -456,7 +456,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) fd = conn->data->state.proto.file->fd; /* VMS: This only works reliable for STREAMLF files */ - if( -1 != fstat(fd, &statbuf)) { + if(-1 != fstat(fd, &statbuf)) { /* we could stat it, then read out the size */ expected_size = statbuf.st_size; /* and store the modification time */ @@ -562,7 +562,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) bytestoread = (expected_size < BUFSIZE-1)?(size_t)expected_size:BUFSIZE-1; nread = read(fd, buf, bytestoread); - if( nread > 0) + if(nread > 0) buf[nread] = 0; if(nread <= 0 || expected_size == 0) -- cgit v1.2.1 From 51075a6777576a0676a77a49c250a8aba7ea3097 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 5 May 2011 15:14:19 +0200 Subject: remove FILE protocol-specific checks Also, convert the BANPROXY flag into NONETWORK for the protocols (file:// only atm) that don't work over networks. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index a3d80fbd7..6fe4c4979 100644 --- a/lib/file.c +++ b/lib/file.c @@ -129,7 +129,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* disconnect */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ - PROTOPT_BANPROXY /* flags */ + PROTOPT_NONETWORK /* flags */ }; -- cgit v1.2.1 From f0612f166a5fa51d09498baa19a327c5cf36941f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 5 May 2011 16:27:03 +0200 Subject: RTSP: convert protocol-specific checks to generic Add a 'readwrite' function to the protocol handler struct and use that for the extra readwrite functionality RTSP needs. --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 6fe4c4979..4f3ea1bb4 100644 --- a/lib/file.c +++ b/lib/file.c @@ -127,6 +127,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* doing_getsock */ ZERO_NULL, /* perform_getsock */ ZERO_NULL, /* disconnect */ + ZERO_NULL, /* readwrite */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ PROTOPT_NONETWORK /* flags */ -- cgit v1.2.1 From 0337b871975ab515c513d2c5d596feb9a489494d Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 25 Jul 2011 04:08:08 +0200 Subject: time.h and sys/time.h inclusion conditionally done in setup_once.h --- lib/file.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4f3ea1bb4..8df6f37fe 100644 --- a/lib/file.c +++ b/lib/file.c @@ -31,7 +31,6 @@ #include #ifdef WIN32 -#include #include #include #else @@ -41,9 +40,6 @@ #ifdef HAVE_NETINET_IN_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include -#endif #ifdef HAVE_UNISTD_H #include #endif -- cgit v1.2.1 From 983f3d70f9610a35f279b656a3322087e272f2a6 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 25 Jul 2011 05:30:14 +0200 Subject: WIN32 io.h and fcntl.h inclusion done in setup_once.h --- lib/file.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 8df6f37fe..c29b0c9f8 100644 --- a/lib/file.c +++ b/lib/file.c @@ -30,10 +30,6 @@ #include #include -#ifdef WIN32 -#include -#include -#else #ifdef HAVE_SYS_SOCKET_H #include #endif @@ -64,8 +60,6 @@ #include #endif -#endif /* WIN32 */ - #include "strtoofft.h" #include "urldata.h" #include -- cgit v1.2.1 From f1586cb4775681810afd8e6626e7842d459f3b85 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 26 Jul 2011 17:23:27 +0200 Subject: stdio.h, stdlib.h, string.h, stdarg.h and ctype.h inclusion done in setup_once.h --- lib/file.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index c29b0c9f8..610a3495b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -23,12 +23,6 @@ #include "setup.h" #ifndef CURL_DISABLE_FILE -/* -- WIN32 approved -- */ -#include -#include -#include -#include -#include #ifdef HAVE_SYS_SOCKET_H #include -- cgit v1.2.1 From 8af94de50ad7ae043dafd298d5458d5a424527a8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 14 Oct 2011 18:23:16 +0200 Subject: file.c: fix compiler warning --- lib/file.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 610a3495b..9475d0c56 100644 --- a/lib/file.c +++ b/lib/file.c @@ -67,6 +67,7 @@ #include "url.h" #include "curl_memory.h" #include "parsedate.h" /* for the week day and month names */ +#include "warnless.h" #define _MPRINTF_REPLACE /* use our functions only */ #include @@ -422,7 +423,6 @@ static CURLcode file_do(struct connectdata *conn, bool *done) curl_off_t expected_size=0; bool fstated=FALSE; ssize_t nread; - size_t bytestoread; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; curl_off_t bytecount = 0; @@ -544,7 +544,10 @@ static CURLcode file_do(struct connectdata *conn, bool *done) while(res == CURLE_OK) { /* Don't fill a whole buffer if we want less than all data */ - bytestoread = (expected_size < BUFSIZE-1)?(size_t)expected_size:BUFSIZE-1; + size_t bytestoread = + (expected_size < CURL_OFF_T_C(BUFSIZE) - CURL_OFF_T_C(1)) ? + curlx_sotouz(expected_size) : BUFSIZE - 1; + nread = read(fd, buf, bytestoread); if(nread > 0) -- cgit v1.2.1 From 95d23d1ceb7ed34ed32206cf418d625fa8e7d0d1 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 21 Oct 2011 16:40:02 +0200 Subject: file.c: OOM handling fix file_disconnect() free's resources for multi API --- lib/file.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9475d0c56..d4ca3e5ef 100644 --- a/lib/file.c +++ b/lib/file.c @@ -94,6 +94,9 @@ static CURLcode file_do(struct connectdata *, bool *done); static CURLcode file_done(struct connectdata *conn, CURLcode status, bool premature); static CURLcode file_connect(struct connectdata *conn, bool *done); +static CURLcode file_disconnect(struct connectdata *conn, + bool dead_connection); + /* * FILE scheme handler. @@ -111,7 +114,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* proto_getsock */ ZERO_NULL, /* doing_getsock */ ZERO_NULL, /* perform_getsock */ - ZERO_NULL, /* disconnect */ + file_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ @@ -207,10 +210,9 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) /* file is not a protocol that can deal with "persistancy" */ file = data->state.proto.file; Curl_safefree(file->freepath); + file->path = NULL; if(file->fd != -1) close(file->fd); - file->path = NULL; - file->freepath = NULL; file->fd = -1; } @@ -267,10 +269,31 @@ static CURLcode file_done(struct connectdata *conn, struct FILEPROTO *file = conn->data->state.proto.file; (void)status; /* not used */ (void)premature; /* not used */ - Curl_safefree(file->freepath); - if(file->fd != -1) - close(file->fd); + if(file) { + Curl_safefree(file->freepath); + file->path = NULL; + if(file->fd != -1) + close(file->fd); + file->fd = -1; + } + + return CURLE_OK; +} + +static CURLcode file_disconnect(struct connectdata *conn, + bool dead_connection) +{ + struct FILEPROTO *file = conn->data->state.proto.file; + (void)dead_connection; /* not used */ + + if(file) { + Curl_safefree(file->freepath); + file->path = NULL; + if(file->fd != -1) + close(file->fd); + file->fd = -1; + } return CURLE_OK; } -- cgit v1.2.1 From d7934b8bd49114cbb54f7401742f7fb088e2f796 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 21 Oct 2011 23:36:54 +0200 Subject: curl_multi_fdset: correct fdset with FTP PORT use After a PORT has been issued, and the multi handle would switch to the CURLM_STATE_DO_MORE state (which is unique for FTP), libcurl would return the wrong fdset to wait for when curl_multi_fdset() is called. The code would blindly assume that it was waiting for a connect of the second connection, while that isn't true immediately after the PORT command. Also, the function multi.c:domore_getsock() was highly FTP-centric and therefore ugly to keep in protocol-agnostic code. I solved this problem by introducing a new function pointer in the Curl_handler struct called domore_getsock() which is only called during the DOMORE state for protocols that set that pointer. The new ftp.c:ftp_domore_getsock() function now returns fdset info about the control connection's command/response handling while such a state is in use, and goes over to waiting for a writable second connection first once the commands are done. The original problem could be seen by running test 525 and checking the time stamps in the FTP server log. I can verify that this fix at least fixes this problem. Bug: http://curl.haxx.se/mail/lib-2011-10/0250.html Reported by: Gokhan Sengun --- lib/file.c | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index d4ca3e5ef..00d5fc09b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -113,6 +113,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* doing */ ZERO_NULL, /* proto_getsock */ ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* domore_getsock */ ZERO_NULL, /* perform_getsock */ file_disconnect, /* disconnect */ ZERO_NULL, /* readwrite */ -- cgit v1.2.1 From 6fa6567b92621de2d5f5958fa6f29b00384b9174 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 3 Nov 2011 21:56:51 +0100 Subject: url.c and file.c: fix OOM triggered segfault --- lib/file.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 00d5fc09b..9421c445b 100644 --- a/lib/file.c +++ b/lib/file.c @@ -184,7 +184,7 @@ static CURLcode file_range(struct connectdata *conn) static CURLcode file_connect(struct connectdata *conn, bool *done) { struct SessionHandle *data = conn->data; - char *real_path = curl_easy_unescape(data, data->state.path, 0, NULL); + char *real_path; struct FILEPROTO *file; int fd; #ifdef DOS_FILESYSTEM @@ -192,13 +192,14 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) char *actual_path; #endif - if(!real_path) - return CURLE_OUT_OF_MEMORY; - /* If there already is a protocol-specific struct allocated for this sessionhandle, deal with it */ Curl_reset_reqproto(conn); + real_path = curl_easy_unescape(data, data->state.path, 0, NULL); + if(!real_path) + return CURLE_OUT_OF_MEMORY; + if(!data->state.proto.file) { file = calloc(1, sizeof(struct FILEPROTO)); if(!file) { -- cgit v1.2.1 From 2c905fd1f8200349667dc990a17daf37214700bf Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Thu, 24 Nov 2011 23:28:54 +0100 Subject: query-part: ignore the URI part for given protocols By setting PROTOPT_NOURLQUERY in the protocol handler struct, the protocol will get the "query part" of the URL cut off before the data is handled by the protocol-specific code. This makes libcurl adhere to RFC3986 section 2.2. Test 1220 is added to verify a file:// URL with query-part. --- lib/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 9421c445b..4447c73f6 100644 --- a/lib/file.c +++ b/lib/file.c @@ -119,7 +119,7 @@ const struct Curl_handler Curl_handler_file = { ZERO_NULL, /* readwrite */ 0, /* defport */ CURLPROTO_FILE, /* protocol */ - PROTOPT_NONETWORK /* flags */ + PROTOPT_NONETWORK | PROTOPT_NOURLQUERY /* flags */ }; -- cgit v1.2.1 From 1f8518c5d9aaa369dae85620973f9b5c1add3277 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Mon, 30 Jul 2012 14:20:07 +0200 Subject: file: use fdopen() for uploaded files if available It eliminates noisy events when using inotify and fixes a TOCTOU issue. Bug: https://bugzilla.redhat.com/844385 --- lib/file.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 4447c73f6..1025022f0 100644 --- a/lib/file.c +++ b/lib/file.c @@ -351,8 +351,12 @@ static CURLcode file_upload(struct connectdata *conn) failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; } +#ifdef HAVE_FDOPEN + fp = fdopen(fd, "wb"); +#else close(fd); fp = fopen(file->path, "wb"); +#endif } if(!fp) { -- cgit v1.2.1 From 38ed72cd3733e0d809c4b7023151d3f06e7274ef Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 8 Oct 2012 11:49:47 +0200 Subject: FILE: Make upload-writes unbuffered by not using FILE streams --- lib/file.c | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index 1025022f0..ebb08664d 100644 --- a/lib/file.c +++ b/lib/file.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -310,7 +310,8 @@ static CURLcode file_upload(struct connectdata *conn) { struct FILEPROTO *file = conn->data->state.proto.file; const char *dir = strchr(file->path, DIRSEP); - FILE *fp; + int fd; + int mode; CURLcode res=CURLE_OK; struct SessionHandle *data = conn->data; char *buf = data->state.buffer; @@ -333,33 +334,21 @@ static CURLcode file_upload(struct connectdata *conn) return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ if(!dir[1]) - return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ - - if(data->state.resume_from) - fp = fopen( file->path, "ab" ); - else { - int fd; + return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */ -#ifdef DOS_FILESYSTEM - fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, - conn->data->set.new_file_perms); -#else - fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC, - conn->data->set.new_file_perms); -#endif - if(fd < 0) { - failf(data, "Can't open %s for writing", file->path); - return CURLE_WRITE_ERROR; - } -#ifdef HAVE_FDOPEN - fp = fdopen(fd, "wb"); +#ifdef O_BINARY +#define MODE_DEFAULT O_WRONLY|O_CREAT|O_BINARY #else - close(fd); - fp = fopen(file->path, "wb"); +#define MODE_DEFAULT O_WRONLY|O_CREAT #endif - } - if(!fp) { + if(data->state.resume_from) + mode = MODE_DEFAULT|O_APPEND; + else + mode = MODE_DEFAULT|O_TRUNC; + + fd = open(file->path, mode, conn->data->set.new_file_perms); + if(fd < 0) { failf(data, "Can't open %s for writing", file->path); return CURLE_WRITE_ERROR; } @@ -370,8 +359,8 @@ static CURLcode file_upload(struct connectdata *conn) /* treat the negative resume offset value as the case of "-" */ if(data->state.resume_from < 0) { - if(fstat(fileno(fp), &file_stat)) { - fclose(fp); + if(fstat(fd, &file_stat)) { + close(fd); failf(data, "Can't get the size of %s", file->path); return CURLE_WRITE_ERROR; } @@ -407,7 +396,7 @@ static CURLcode file_upload(struct connectdata *conn) buf2 = buf; /* write the data to the target */ - nwrite = fwrite(buf2, 1, nread, fp); + nwrite = write(fd, buf2, nread); if(nwrite != nread) { res = CURLE_SEND_ERROR; break; @@ -425,7 +414,7 @@ static CURLcode file_upload(struct connectdata *conn) if(!res && Curl_pgrsUpdate(conn)) res = CURLE_ABORTED_BY_CALLBACK; - fclose(fp); + close(fd); return res; } -- cgit v1.2.1