Fixes allowing 26 more test cases in 1334 to 1393 range to succeed

This commit is contained in:
Yang Tse 2012-06-09 05:42:39 +02:00
parent c29d1f4e3a
commit a884ffe430
4 changed files with 56 additions and 66 deletions

View File

@ -41,10 +41,9 @@ static char *parse_filename(const char *ptr, size_t len);
size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata) size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
{ {
HeaderData *hdrdata = userdata; struct HdrCbData *hdrcbdata = userdata;
struct getout *urlnode = hdrdata->urlnode; struct OutStruct *outs = hdrcbdata->outs;
struct OutStruct *outs = hdrdata->outs; struct OutStruct *heads = hdrcbdata->heads;
struct OutStruct *heads = hdrdata->heads;
const char *str = ptr; const char *str = ptr;
const size_t cb = size * nmemb; const size_t cb = size * nmemb;
const char *end = (char*)ptr + cb; const char *end = (char*)ptr + cb;
@ -57,39 +56,35 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
*/ */
size_t failure = (size * nmemb) ? 0 : 1; size_t failure = (size * nmemb) ? 0 : 1;
if(!outs->config) if(!heads->config)
return failure; return failure;
#ifdef DEBUGBUILD #ifdef DEBUGBUILD
if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) { if(size * nmemb > (size_t)CURL_MAX_HTTP_HEADER) {
warnf(outs->config, "Header data exceeds single call write limit!\n"); warnf(heads->config, "Header data exceeds single call write limit!\n");
return failure; return failure;
} }
#endif #endif
/* --dump-header option */
if(outs->config->headerfile) { /*
fwrite(ptr, size, nmemb, heads->stream); * Write header data when curl option --dump-header (-D) is given.
*/
if(heads->config->headerfile && heads->stream) {
size_t rc = fwrite(ptr, size, nmemb, heads->stream);
if(rc != cb)
return rc;
} }
/* /*
** This callback callback MIGHT set the filename upon appropriate * This callback sets the filename where output shall be written when
** conditions and server specifying filename in Content-Disposition. * curl options --remote-name (-O) and --remote-header-name (-J) have
*/ * been simultaneously given and additionally server returns an HTTP
* Content-Disposition header specifying a filename property.
*/
if(!outs->config->content_disposition) if(hdrcbdata->honor_cd_filename &&
return cb; (cb > 20) && checkprefix("Content-disposition:", str)) {
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; const char *p = str + 20;
/* look for the 'filename=' parameter /* look for the 'filename=' parameter
@ -123,6 +118,7 @@ size_t tool_header_cb(void *ptr, size_t size, size_t nmemb, void *userdata)
outs->s_isreg = TRUE; outs->s_isreg = TRUE;
outs->fopened = FALSE; outs->fopened = FALSE;
outs->stream = NULL; outs->stream = NULL;
hdrcbdata->honor_cd_filename = FALSE;
break; break;
} }
else else

View File

@ -23,15 +23,26 @@
***************************************************************************/ ***************************************************************************/
#include "tool_setup.h" #include "tool_setup.h"
/* Structure to pass as userdata in tool_header_cb */ /*
typedef struct { * curl operates using a single HdrCbData struct variable, a
/* getout object pointer currently processing */ * pointer to this is passed as userdata pointer to tool_header_cb.
struct getout *urlnode; *
/* output stream */ * 'outs' member is a pointer to the OutStruct variable used to keep
* track of information relative to curl's output writing.
*
* 'heads' member is a pointer to the OutStruct variable used to keep
* track of information relative to header response writing.
*
* 'honor_cd_filename' member is TRUE when tool_header_cb is allowed
* to honor Content-Disposition filename property and accordingly
* set 'outs' filename, otherwise FALSE;
*/
struct HdrCbData {
struct OutStruct *outs; struct OutStruct *outs;
/* header output stream */
struct OutStruct *heads; struct OutStruct *heads;
} HeaderData; bool honor_cd_filename;
};
/* /*
** callback for CURLOPT_HEADERFUNCTION ** callback for CURLOPT_HEADERFUNCTION

View File

@ -128,6 +128,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
struct ProgressData progressbar; struct ProgressData progressbar;
struct getout *urlnode; struct getout *urlnode;
struct HdrCbData hdrcbdata;
struct OutStruct heads; struct OutStruct heads;
metalinkfile *mlfile_last = NULL; metalinkfile *mlfile_last = NULL;
@ -141,6 +142,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
errorbuffer[0] = '\0'; errorbuffer[0] = '\0';
/* default headers output stream is stdout */ /* default headers output stream is stdout */
memset(&hdrcbdata, 0, sizeof(struct HdrCbData));
memset(&heads, 0, sizeof(struct OutStruct)); memset(&heads, 0, sizeof(struct OutStruct));
heads.stream = stdout; heads.stream = stdout;
heads.config = config; heads.config = config;
@ -531,7 +533,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
long retry_sleep_default; long retry_sleep_default;
long retry_sleep; long retry_sleep;
char *this_url; char *this_url;
HeaderData hdrdata;
int metalink_next_res = 0; int metalink_next_res = 0;
outfile = NULL; outfile = NULL;
@ -1256,12 +1257,19 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
if(config->proto_redir_present) if(config->proto_redir_present)
my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir); my_setopt_flags(curl, CURLOPT_REDIR_PROTOCOLS, config->proto_redir);
hdrdata.urlnode = urlnode; if(config->content_disposition
hdrdata.outs = &outs; && (urlnode->flags & GETOUT_USEREMOTE)
hdrdata.heads = &heads; && (checkprefix("http://", this_url) ||
checkprefix("https://", this_url)))
hdrcbdata.honor_cd_filename = TRUE;
else
hdrcbdata.honor_cd_filename = FALSE;
hdrcbdata.outs = &outs;
hdrcbdata.heads = &heads;
my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb); my_setopt(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
my_setopt(curl, CURLOPT_HEADERDATA, &hdrdata); my_setopt(curl, CURLOPT_HEADERDATA, &hdrcbdata);
if(config->resolve) if(config->resolve)
/* new in 7.21.3 */ /* new in 7.21.3 */
@ -1590,6 +1598,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
if(outs.alloc_filename) if(outs.alloc_filename)
Curl_safefree(outs.filename); Curl_safefree(outs.filename);
memset(&outs, 0, sizeof(struct OutStruct)); memset(&outs, 0, sizeof(struct OutStruct));
hdrcbdata.outs = NULL;
/* Free loop-local allocated memory and close loop-local opened fd */ /* Free loop-local allocated memory and close loop-local opened fd */
@ -1696,6 +1705,8 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
easysrc_cleanup(); easysrc_cleanup();
#endif #endif
hdrcbdata.heads = NULL;
/* Close function-local opened file descriptors */ /* Close function-local opened file descriptors */
if(heads.fopened && heads.stream) if(heads.fopened && heads.stream)

View File

@ -9,34 +9,6 @@
1355 1355
1363 1363
# #
1349
1350
1351
1352
1353
1354
1357
1358
1359
1360
1361
1362
#
1370
1371
1385 1385
1393 1393
# #
1379
1380
1381
1382
1383
1384
1387
1388
1389
1390
1391
1392
#