aboutsummaryrefslogtreecommitdiff
path: root/src/tool_formparse.c
diff options
context:
space:
mode:
authorPatrick Monnerat <patrick@monnerat.net>2017-09-03 14:45:43 +0100
committerPatrick Monnerat <patrick@monnerat.net>2017-09-03 14:45:43 +0100
commit1a3f4c19919b09ff0fd0ba228b06a217d85d4265 (patch)
tree12c70f11b95ded1acfac5b28eeb7499d0ec99e59 /src/tool_formparse.c
parent045b076ae8362006f6977a80e6a5e3ef0eb903eb (diff)
mime: remove support "-" stdin pseudo-file name in curl_mime_filedata().
This feature is badly supported in Windows: as a replacement, a caller has to use curl_mime_data_cb() with fread, fseek and possibly fclose callbacks to process opened files. The cli tool and documentation are updated accordingly. The feature is however kept internally for form API compatibility, with the known caveats it always had. As a side effect, stdin size is not determined by the cli tool even if possible and this results in a chunked transfer encoding. Test 173 is updated accordingly.
Diffstat (limited to 'src/tool_formparse.c')
-rw-r--r--src/tool_formparse.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/tool_formparse.c b/src/tool_formparse.c
index cf19c0508..fc5162eed 100644
--- a/src/tool_formparse.c
+++ b/src/tool_formparse.c
@@ -347,6 +347,21 @@ static int get_param_part(struct OperationConfig *config, char **str,
return sep & 0xFF;
}
+/* Check if file is "-". If so, use a callback to read OUR stdin (to
+ * workaround Windows DLL file handle caveat).
+ * Else use curl_mime_filedata(). */
+static CURLcode file_or_stdin(curl_mimepart *part, const char *file)
+{
+ CURLcode ret = CURLE_OK;
+
+ if(strcmp(file, "-"))
+ return curl_mime_filedata(part, file);
+
+ return curl_mime_data_cb(part, -1, (curl_read_callback) fread,
+ (curl_seek_callback) fseek, NULL, stdin);
+}
+
+
/***************************************************************************
*
* formparse()
@@ -547,9 +562,9 @@ int formparse(struct OperationConfig *config,
}
/* Setup file in part. */
- res = curl_mime_filedata(part, data);
+ res = file_or_stdin(part, data);
if(res) {
- warnf(config->global, "curl_mime_filedata failed!\n");
+ warnf(config->global, "setting file %s failed!\n", data);
if(res != CURLE_READ_ERROR) {
if(subparts != *mimecurrent)
curl_mime_free(subparts);
@@ -619,9 +634,9 @@ int formparse(struct OperationConfig *config,
}
/* Setup file in part. */
- res = curl_mime_filedata(part, data);
+ res = file_or_stdin(part, data);
if(res) {
- warnf(config->global, "curl_mime_filedata failed!\n");
+ warnf(config->global, "setting file %s failed!\n", data);
if(res != CURLE_READ_ERROR) {
Curl_safefree(contents);
return 22;