diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-10-01 06:36:11 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-10-01 06:36:11 +0000 |
commit | 8e87223195bba350f7fab9575a3ea3de85a49166 (patch) | |
tree | 17277913163f4bb1b99a70d88ebc1a25f8415f47 | |
parent | be1cece69b2bc7b73c07166ec5e164fabdac1c95 (diff) |
- Based on Fedor Karpelevitch's formpost path basename patch, file parts in
formposts no longer include the path part. If you _really_ want them, you
must provide your preferred full file name with CURLFORM_FILENAME.
Added detection for libgen.h and basename() to configure. My custom
basename() replacement function for systems without it, might be a bit too
naive...
Updated 6 test cases to make them work with the stripped paths.
-rw-r--r-- | CHANGES | 11 | ||||
-rw-r--r-- | TODO-RELEASE | 2 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | lib/formdata.c | 79 | ||||
-rw-r--r-- | tests/data/test166 | 4 | ||||
-rw-r--r-- | tests/data/test304 | 4 | ||||
-rw-r--r-- | tests/data/test39 | 4 | ||||
-rw-r--r-- | tests/data/test44 | 4 | ||||
-rw-r--r-- | tests/data/test71 | 4 | ||||
-rw-r--r-- | tests/data/test9 | 4 |
10 files changed, 103 insertions, 15 deletions
@@ -6,6 +6,17 @@ Changelog +Daniel (1 October 2004) +- Based on Fedor Karpelevitch's formpost path basename patch, file parts in + formposts no longer include the path part. If you _really_ want them, you + must provide your preferred full file name with CURLFORM_FILENAME. + + Added detection for libgen.h and basename() to configure. My custom + basename() replacement function for systems without it, might be a bit too + naive... + + Updated 6 test cases to make them work with the stripped paths. + Daniel (30 September 2004) - Larry Campbell added CURLINFO_OS_ERRNO to curl_easy_getinfo() that allows an app to retrieve the errno variable after a (connect) failure. It will make diff --git a/TODO-RELEASE b/TODO-RELEASE index af7ec5481..11c7d3319 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -5,7 +5,7 @@ To get fixed in 7.12.2 (planned release: mid October 2004) 40 - fixed -41 - Fedor Karpelevitch's formpost path basename patch +41 - fixed 42 - Bertrand Demiddelaer's CURLOPT_VERBOSE may read free()ed data patch diff --git a/configure.ac b/configure.ac index ef7fc52f1..c94cbcfa7 100644 --- a/configure.ac +++ b/configure.ac @@ -1115,6 +1115,7 @@ AC_CHECK_HEADERS( utime.h \ sys/utime.h \ sys/poll.h \ + libgen.h \ setjmp.h, dnl to do if not found [], @@ -1197,6 +1198,7 @@ AC_CHECK_FUNCS( strtoll \ dlopen \ utime \ sigsetjmp \ + basename \ poll, dnl if found [], diff --git a/lib/formdata.c b/lib/formdata.c index 9c7fc8be2..798303d3a 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -113,6 +113,9 @@ Content-Disposition: form-data; name="FILECONTENT" #include <stdarg.h> #include <time.h> #include <sys/stat.h> +#ifdef HAVE_LIBGEN_H +#include <libgen.h> +#endif #include "formdata.h" #include "strequal.h" #include "memory.h" @@ -903,6 +906,67 @@ void curl_formfree(struct curl_httppost *form) } while((form=next)); /* continue */ } +#ifndef HAVE_BASENAME +/* + (Quote from The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 + Edition) + + The basename() function shall take the pathname pointed to by path and + return a pointer to the final component of the pathname, deleting any + trailing '/' characters. + + If the string pointed to by path consists entirely of the '/' character, + basename() shall return a pointer to the string "/". If the string pointed + to by path is exactly "//", it is implementation-defined whether '/' or "//" + is returned. + + If path is a null pointer or points to an empty string, basename() shall + return a pointer to the string ".". + + The basename() function may modify the string pointed to by path, and may + return a pointer to static storage that may then be overwritten by a + subsequent call to basename(). + + The basename() function need not be reentrant. A function that is not + required to be reentrant is not required to be thread-safe. + +*/ +char *basename(char *path) +{ + /* Ignore all the details above for now and make a quick and simple + implementaion here */ + char *s1; + char *s2; + + s1=strrchr(path, '/'); + s2=strrchr(path, '\\'); + + if(s1 && s2) { + path = (s1 > s2? s1 : s2)+1; + } + else { + path = (s1 ? s1 : s2)+1; + } + + return path; +} +#endif + +static char *strippath(char *fullfile) +{ + char *filename; + char *base; + filename = strdup(fullfile); /* duplicate since basename() may ruin the + buffer it works on */ + if(!filename) + return NULL; + base = strdup(basename(filename)); + + free(filename); /* free temporary buffer */ + + return base; /* returns an allocated string! */ +} + /* * Curl_getFormData() converts a linked list of "meta data" into a complete * (possibly huge) multipart formdata. The input list is in 'post', while the @@ -998,22 +1062,33 @@ CURLcode Curl_getFormData(struct FormData **finalform, if(post->more) { /* if multiple-file */ + char *filebasename= + (!file->showfilename)?strippath(file->contents):NULL; + result = AddFormDataf(&form, &size, "\r\n--%s\r\nContent-Disposition: " "attachment; filename=\"%s\"", fileboundary, (file->showfilename?file->showfilename: - file->contents)); + filebasename)); + if (filebasename) + free(filebasename); if (result) break; } else if((post->flags & HTTPPOST_FILENAME) || (post->flags & HTTPPOST_BUFFER)) { + char *filebasename= + (!post->showfilename)?strippath(post->contents):NULL; + result = AddFormDataf(&form, &size, "; filename=\"%s\"", (post->showfilename?post->showfilename: - post->contents)); + filebasename)); + if (filebasename) + free(filebasename); + if (result) break; } diff --git a/tests/data/test166 b/tests/data/test166 index 07a0675ef..9a9704b0e 100644 --- a/tests/data/test166 +++ b/tests/data/test166 @@ -37,12 +37,12 @@ User-Agent: curl/7.12.0-CVS (i686-pc-linux-gnu) libcurl/7.12.0-CVS OpenSSL/0.9.6 Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
-Content-Length: 227
+Content-Length: 223
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------b0b3d6d23991
------------------------------b0b3d6d23991
-Content-Disposition: form-data; name="name"; filename="log/fie ld 166"
+Content-Disposition: form-data; name="name"; filename="fie ld 166"
Content-Type: application/octet-stream
data inside the file diff --git a/tests/data/test304 b/tests/data/test304 index 75751c2c0..8aaff245f 100644 --- a/tests/data/test304 +++ b/tests/data/test304 @@ -38,7 +38,7 @@ User-Agent: curl/7.10.4 (i686-pc-linux-gnu) libcurl/7.10.4 OpenSSL/0.9.7a ipv6 z Host: 127.0.0.1:%HTTPSPORT
Pragma: no-cache
Accept: */*
-Content-Length: 1390
+Content-Length: 1386
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------c3b2ef7f0bb8
@@ -51,7 +51,7 @@ Content-Disposition: form-data; name="tool" curl
------------------------------c3b2ef7f0bb8
-Content-Disposition: form-data; name="file"; filename="log/test304.txt"
+Content-Disposition: form-data; name="file"; filename="test304.txt"
Content-Type: text/plain
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa diff --git a/tests/data/test39 b/tests/data/test39 index 96b4661a2..15f9e9358 100644 --- a/tests/data/test39 +++ b/tests/data/test39 @@ -41,7 +41,7 @@ User-Agent: curl/7.10.4 (i686-pc-linux-gnu) libcurl/7.10.4 OpenSSL/0.9.7a ipv6 z Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
-Content-Length: 598
+Content-Length: 594
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------24e78000bd32
@@ -63,7 +63,7 @@ bar foo ------------------------------24e78000bd32
-Content-Disposition: form-data; name="file2"; filename="log/test39.txt"
+Content-Disposition: form-data; name="file2"; filename="test39.txt"
Content-Type: text/plain
foo bar diff --git a/tests/data/test44 b/tests/data/test44 index dfd50250d..e858786da 100644 --- a/tests/data/test44 +++ b/tests/data/test44 @@ -40,7 +40,7 @@ User-Agent: curl/7.10.4 (i686-pc-linux-gnu) libcurl/7.10.4 OpenSSL/0.9.7a ipv6 z Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
-Content-Length: 412
+Content-Length: 408
Content-Type: multipart/form-data; boundary=----------------------------7c633d5c27ce
------------------------------7c633d5c27ce
@@ -52,7 +52,7 @@ Content-Disposition: form-data; name="tool" curl
------------------------------7c633d5c27ce
-Content-Disposition: form-data; name="file"; filename="log/test44.txt"
+Content-Disposition: form-data; name="file"; filename="test44.txt"
Content-Type: text/plain
foo- diff --git a/tests/data/test71 b/tests/data/test71 index 5619d5e88..e18917b95 100644 --- a/tests/data/test71 +++ b/tests/data/test71 @@ -45,7 +45,7 @@ User-Agent: curl/7.10.4 (i686-pc-linux-gnu) libcurl/7.10.4 OpenSSL/0.9.7a ipv6 z Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
-Content-Length: 412
+Content-Length: 408
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
@@ -58,7 +58,7 @@ Content-Disposition: form-data; name="tool" curl
------------------------------9ef8d6205763
-Content-Disposition: form-data; name="file"; filename="log/test71.txt"
+Content-Disposition: form-data; name="file"; filename="test71.txt"
Content-Type: text/plain
foo- diff --git a/tests/data/test9 b/tests/data/test9 index f94b24174..370137065 100644 --- a/tests/data/test9 +++ b/tests/data/test9 @@ -40,7 +40,7 @@ User-Agent: curl/7.10.4 (i686-pc-linux-gnu) libcurl/7.10.4 OpenSSL/0.9.7a ipv6 z Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
-Content-Length: 411
+Content-Length: 407
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
@@ -53,7 +53,7 @@ Content-Disposition: form-data; name="tool" curl
------------------------------9ef8d6205763
-Content-Disposition: form-data; name="file"; filename="log/test9.txt"
+Content-Disposition: form-data; name="file"; filename="test9.txt"
Content-Type: text/plain
foo- |