aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2012-06-07 21:57:53 +0200
committerYang Tse <yangsita@gmail.com>2012-06-07 21:57:53 +0200
commit7352ac408b6a7b4a1474f52d845fbba70c9644ae (patch)
tree4f4855363470dd2c88c9a53d7079e52298f448f2
parentc41d959ee6d0a22fa6a7272bd32bf04fec839caf (diff)
Fixes allowing HTTP test cases 1338, 1339, 1368 and 1369 to succeed
-rw-r--r--src/tool_cb_hdr.c22
-rw-r--r--src/tool_cb_wrt.c4
-rw-r--r--src/tool_operate.c2
-rw-r--r--src/tool_sdecls.h4
-rw-r--r--tests/data/DISABLED5
5 files changed, 27 insertions, 10 deletions
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c
index 738cd5dfc..ddc4c6638 100644
--- a/src/tool_cb_hdr.c
+++ b/src/tool_cb_hdr.c
@@ -71,8 +71,25 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
fwrite(ptr, size, nmemb, heads->stream);
}
- if((urlnode->flags & GETOUT_USEREMOTE) && outs->config->content_disposition
- && (cb > 20) && checkprefix("Content-disposition:", str)) {
+ /*
+ ** This callback callback MIGHT set the filename upon appropriate
+ ** conditions and server specifying filename in Content-Disposition.
+ */
+
+ if(!outs->config->content_disposition)
+ return cb;
+
+ if(!urlnode)
+ return failure;
+
+ if(!checkprefix("http://", urlnode->url) &&
+ !checkprefix("https://", urlnode->url))
+ return cb;
+
+ if(!(urlnode->flags & GETOUT_USEREMOTE))
+ return cb;
+
+ if((cb > 20) && checkprefix("Content-disposition:", str)) {
const char *p = str + 20;
/* look for the 'filename=' parameter
@@ -102,6 +119,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
if(filename) {
outs->filename = filename;
outs->alloc_filename = TRUE;
+ outs->is_cd_filename = TRUE;
outs->s_isreg = TRUE;
outs->fopened = FALSE;
outs->stream = NULL;
diff --git a/src/tool_cb_wrt.c b/src/tool_cb_wrt.c
index fa47dd3f3..d6688110a 100644
--- a/src/tool_cb_wrt.c
+++ b/src/tool_cb_wrt.c
@@ -86,7 +86,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
/* standard stream */
if(!outs->stream || outs->s_isreg || outs->fopened)
check_fails = TRUE;
- if(outs->alloc_filename || outs->init)
+ if(outs->alloc_filename || outs->is_cd_filename || outs->init)
check_fails = TRUE;
}
if(check_fails) {
@@ -104,7 +104,7 @@ size_t tool_write_cb(void *buffer, size_t sz, size_t nmemb, void *userdata)
return failure;
}
- if(config->content_disposition) {
+ if(outs->is_cd_filename) {
/* don't overwrite existing files */
file = fopen(outs->filename, "rb");
if(file) {
diff --git a/src/tool_operate.c b/src/tool_operate.c
index 75bb5b34d..7c70fd2da 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -1309,7 +1309,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
for(;;) {
res = curl_easy_perform(curl);
- if(config->content_disposition && outs.stream && !config->mute &&
+ if(outs.is_cd_filename && outs.stream && !config->mute &&
outs.filename)
printf("curl: Saved to filename '%s'\n", outs.filename);
diff --git a/src/tool_sdecls.h b/src/tool_sdecls.h
index 7b1297588..da6253604 100644
--- a/src/tool_sdecls.h
+++ b/src/tool_sdecls.h
@@ -34,6 +34,9 @@
* 'alloc_filename' member is TRUE when string pointed by 'filename' has been
* dynamically allocated and 'belongs' to this OutStruct, otherwise FALSE.
*
+ * 'is_cd_filename' member is TRUE when string pointed by 'filename' has been
+ * set using a server-specified Content-Disposition filename, otherwise FALSE.
+ *
* 's_isreg' member is TRUE when output goes to a regular file, this also
* implies that output is 'seekable' and 'appendable' and also that member
* 'filename' points to file name's string. For any standard stream member
@@ -57,6 +60,7 @@
struct OutStruct {
char *filename;
bool alloc_filename;
+ bool is_cd_filename;
bool s_isreg;
bool fopened;
FILE *stream;
diff --git a/tests/data/DISABLED b/tests/data/DISABLED
index 60c10b094..369fec178 100644
--- a/tests/data/DISABLED
+++ b/tests/data/DISABLED
@@ -22,16 +22,11 @@
1361
1362
#
-1338
-1339
-#
1370
1371
1385
1393
#
-1368
-1369
1379
1380
1381