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
40 - fixed
-41 - Fedor Karpelevitch's formpost path basename patch
+41 - fixed
42 - Bertrand Demiddelaer's CURLOPT_VERBOSE may read free()ed data patch
utime.h \
sys/utime.h \
sys/poll.h \
+ libgen.h \
setjmp.h,
dnl to do if not found
[],
dlopen \
utime \
sigsetjmp \
+ basename \
poll,
dnl if found
[],
#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"
} 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
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;
}
Host: 127.0.0.1:%HTTPPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 227\r
+Content-Length: 223\r
Expect: 100-continue\r
Content-Type: multipart/form-data; boundary=----------------------------b0b3d6d23991\r
\r
------------------------------b0b3d6d23991\r
-Content-Disposition: form-data; name="name"; filename="log/fie ld 166"\r
+Content-Disposition: form-data; name="name"; filename="fie ld 166"\r
Content-Type: application/octet-stream\r
\r
data inside the file
Host: 127.0.0.1:%HTTPSPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 1390\r
+Content-Length: 1386\r
Expect: 100-continue\r
Content-Type: multipart/form-data; boundary=----------------------------c3b2ef7f0bb8\r
\r
\r
curl\r
------------------------------c3b2ef7f0bb8\r
-Content-Disposition: form-data; name="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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Host: 127.0.0.1:%HTTPPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 598\r
+Content-Length: 594\r
Expect: 100-continue\r
Content-Type: multipart/form-data; boundary=----------------------------24e78000bd32\r
\r
foo
\r
------------------------------24e78000bd32\r
-Content-Disposition: form-data; name="file2"; filename="log/test39.txt"\r
+Content-Disposition: form-data; name="file2"; filename="test39.txt"\r
Content-Type: text/plain\r
\r
foo bar
Host: 127.0.0.1:%HTTPPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 412\r
+Content-Length: 408\r
Content-Type: multipart/form-data; boundary=----------------------------7c633d5c27ce\r
\r
------------------------------7c633d5c27ce\r
\r
curl\r
------------------------------7c633d5c27ce\r
-Content-Disposition: form-data; name="file"; filename="log/test44.txt"\r
+Content-Disposition: form-data; name="file"; filename="test44.txt"\r
Content-Type: text/plain\r
\r
foo-
Host: 127.0.0.1:%HTTPPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 412\r
+Content-Length: 408\r
Expect: 100-continue\r
Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763\r
\r
\r
curl\r
------------------------------9ef8d6205763\r
-Content-Disposition: form-data; name="file"; filename="log/test71.txt"\r
+Content-Disposition: form-data; name="file"; filename="test71.txt"\r
Content-Type: text/plain\r
\r
foo-
Host: 127.0.0.1:%HTTPPORT\r
Pragma: no-cache\r
Accept: */*\r
-Content-Length: 411\r
+Content-Length: 407\r
Expect: 100-continue\r
Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763\r
\r
\r
curl\r
------------------------------9ef8d6205763\r
-Content-Disposition: form-data; name="file"; filename="log/test9.txt"\r
+Content-Disposition: form-data; name="file"; filename="test9.txt"\r
Content-Type: text/plain\r
\r
foo-