1
0
mirror of https://github.com/moparisthebest/curl synced 2025-02-28 17:31:46 -05:00

Reduced #ifdef HAVE_METALINK

This commit is contained in:
Tatsuhiro Tsujikawa 2012-05-26 22:51:03 +09:00 committed by Daniel Stenberg
parent 7bdb9fba95
commit 1bfd750f3f
8 changed files with 73 additions and 98 deletions

View File

@ -1 +0,0 @@
curl_SOURCES += tool_metalink.c tool_metalink.h

View File

@ -50,9 +50,6 @@ AM_CPPFLAGS = -DCURL_STATICLIB
endif
include Makefile.inc
if HAVE_LIBMETALINK
include Makefile-metalink.inc
endif # HAVE_LIBMETALINK
# This might hold -Werror
CFLAGS += @CURL_CFLAG_EXTRAS@ @LIBMETALINK_CFLAGS@

View File

@ -50,7 +50,8 @@ CURL_CFILES = hugehelp.c \
tool_vms.c \
tool_writeenv.c \
tool_writeout.c \
tool_xattr.c
tool_xattr.c \
tool_metalink.c
CURL_HFILES = hugehelp.h \
tool_binmode.h \
@ -91,7 +92,8 @@ CURL_HFILES = hugehelp.h \
tool_vms.h \
tool_writeenv.h \
tool_writeout.h \
tool_xattr.h
tool_xattr.h \
tool_metalink.h
curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)

View File

@ -25,9 +25,7 @@
#include "tool_sdecls.h"
#ifdef HAVE_LIBMETALINK
#include "tool_metalink.h"
#endif /* HAVE_LIBMETALINK */
struct Configurable {
CURL *easy; /* once we have one, we keep it here */
@ -202,10 +200,9 @@ struct Configurable {
bool xattr; /* store metadata in extended attributes */
long gssapi_delegation;
bool ssl_allow_beast; /* allow this SSL vulnerability */
#ifdef HAVE_LIBMETALINK
metalinkfile *metalinkfile_list; /* point to the first node */
metalinkfile *metalinkfile_last; /* point to the last/current node */
#endif /* HAVE_LIBMETALINK */
}; /* struct Configurable */
void free_config_fields(struct Configurable *config);

View File

@ -43,10 +43,7 @@
#include "tool_paramhlp.h"
#include "tool_parsecfg.h"
#include "tool_version.h"
#ifdef HAVE_LIBMETALINK
# include "tool_metalink.h"
#endif /* HAVE_LIBMETALINK */
#include "tool_metalink.h"
#include "memdebug.h" /* keep this as LAST include */

View File

@ -31,6 +31,8 @@
# include <fcntl.h>
#endif
#include <metalink/metalink_parser.h>
#include "rawstr.h"
#include "tool_metalink.h"
@ -412,6 +414,8 @@ int metalink_check_hash(struct Configurable *config,
#endif /* METALINK_HASH_CHECK */
#ifdef HAVE_LIBMETALINK
static metalink_checksum *new_metalink_checksum(const char *hash_name,
const char *hash_value)
{
@ -423,16 +427,6 @@ static metalink_checksum *new_metalink_checksum(const char *hash_name,
return chksum;
}
static void delete_metalink_checksum(metalink_checksum *chksum)
{
if(chksum == NULL) {
return;
}
Curl_safefree(chksum->hash_value);
Curl_safefree(chksum->hash_name);
Curl_safefree(chksum);
}
static metalink_resource *new_metalink_resource(const char *url)
{
metalink_resource *res;
@ -442,15 +436,6 @@ static metalink_resource *new_metalink_resource(const char *url)
return res;
}
static void delete_metalink_resource(metalink_resource *res)
{
if(res == NULL) {
return;
}
Curl_safefree(res->url);
Curl_safefree(res);
}
static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo)
{
metalinkfile *f;
@ -488,47 +473,6 @@ static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo)
return f;
}
static void delete_metalinkfile(metalinkfile *mlfile)
{
metalink_checksum *mc;
metalink_resource *res;
if(mlfile == NULL) {
return;
}
Curl_safefree(mlfile->filename);
for(mc = mlfile->checksum; mc;) {
metalink_checksum *next;
next = mc->next;
delete_metalink_checksum(mc);
mc = next;
}
for(res = mlfile->resource; res;) {
metalink_resource *next;
next = res->next;
delete_metalink_resource(res);
res = next;
}
Curl_safefree(mlfile);
}
int count_next_metalink_resource(metalinkfile *mlfile)
{
int count = 0;
metalink_resource *res;
for(res = mlfile->resource; res; res = res->next, ++count);
return count;
}
void clean_metalink(struct Configurable *config)
{
while(config->metalinkfile_list) {
metalinkfile *mlfile = config->metalinkfile_list;
config->metalinkfile_list = config->metalinkfile_list->next;
delete_metalinkfile(mlfile);
}
config->metalinkfile_last = 0;
}
int parse_metalink(struct Configurable *config, const char *infile)
{
metalink_error_t r;
@ -592,6 +536,8 @@ int parse_metalink(struct Configurable *config, const char *infile)
return 0;
}
#endif /* HAVE_LIBMETALINK */
/*
* Returns nonzero if content_type includes mediatype.
*/
@ -612,3 +558,63 @@ int check_metalink_content_type(const char *content_type)
{
return check_content_type(content_type, "application/metalink+xml");
}
int count_next_metalink_resource(metalinkfile *mlfile)
{
int count = 0;
metalink_resource *res;
for(res = mlfile->resource; res; res = res->next, ++count);
return count;
}
static void delete_metalink_checksum(metalink_checksum *chksum)
{
if(chksum == NULL) {
return;
}
Curl_safefree(chksum->hash_value);
Curl_safefree(chksum->hash_name);
Curl_safefree(chksum);
}
static void delete_metalink_resource(metalink_resource *res)
{
if(res == NULL) {
return;
}
Curl_safefree(res->url);
Curl_safefree(res);
}
static void delete_metalinkfile(metalinkfile *mlfile)
{
metalink_checksum *mc;
metalink_resource *res;
if(mlfile == NULL) {
return;
}
Curl_safefree(mlfile->filename);
for(mc = mlfile->checksum; mc;) {
metalink_checksum *next;
next = mc->next;
delete_metalink_checksum(mc);
mc = next;
}
for(res = mlfile->resource; res;) {
metalink_resource *next;
next = res->next;
delete_metalink_resource(res);
res = next;
}
Curl_safefree(mlfile);
}
void clean_metalink(struct Configurable *config)
{
while(config->metalinkfile_list) {
metalinkfile *mlfile = config->metalinkfile_list;
config->metalinkfile_list = config->metalinkfile_list->next;
delete_metalinkfile(mlfile);
}
config->metalinkfile_last = 0;
}

View File

@ -23,8 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
#include <metalink/metalink_parser.h>
struct Configurable;
#if defined(USE_OPENSSL) || defined(USE_GNUTLS)

View File

@ -129,9 +129,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
struct OutStruct heads;
#ifdef HAVE_LIBMETALINK
metalinkfile *mlfile_last = NULL;
#endif /* HAVE_LIBMETALINK */
CURL *curl = NULL;
char *httpgetfields = NULL;
@ -406,18 +404,14 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
int infilenum;
URLGlob *inglob;
int metalink = 0; /* nonzero for metalink download. Put outside of
HAVE_LIBMETALINK to reduce #ifdef */
#ifdef HAVE_LIBMETALINK
int metalink = 0; /* nonzero for metalink download. */
metalinkfile *mlfile;
metalink_resource *mlres;
#endif /* HAVE_LIBMETALINK */
outfiles = NULL;
infilenum = 1;
inglob = NULL;
#ifdef HAVE_LIBMETALINK
if(urlnode->flags & GETOUT_METALINK) {
metalink = 1;
if(mlfile_last == NULL) {
@ -431,7 +425,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
mlfile = NULL;
mlres = NULL;
}
#endif /* HAVE_LIBMETALINK */
/* urlnode->url is the full URL (it might be NULL) */
@ -501,14 +494,12 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
break;
}
#ifdef HAVE_LIBMETALINK
if(metalink) {
/* For Metalink download, we don't use glob. Instead we use
the number of resources as urlnum. */
urlnum = count_next_metalink_resource(mlfile);
}
else
#endif /* HAVE_LIBMETALINK */
if(!config->globoff) {
/* Unless explicitly shut off, we expand '{...}' and '[...]'
expressions and return total number of URLs in pattern set */
@ -540,9 +531,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
long retry_sleep;
char *this_url;
HeaderData hdrdata;
#ifdef HAVE_LIBMETALINK
int metalink_next_res = 0;
#endif /* HAVE_LIBMETALINK */
outfile = NULL;
infdopen = FALSE;
@ -554,7 +543,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
outs.stream = stdout;
outs.config = config;
#ifdef HAVE_LIBMETALINK
if(metalink) {
/* For Metalink download, use name in Metalink file as
filename. */
@ -570,7 +558,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
}
}
else {
#endif /* HAVE_LIBMETALINK */
if(urls) {
res = glob_next_url(&this_url, urls);
if(res)
@ -595,9 +582,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
goto show_error;
}
}
#ifdef HAVE_LIBMETALINK
}
#endif /* HAVE_LIBMETALINK */
if((urlnode->flags&GETOUT_USEREMOTE) ||
(outfile && !curlx_strequal("-", outfile)) ) {
@ -1443,7 +1428,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
continue; /* curl_easy_perform loop */
}
} /* if retry_numretries */
#ifdef HAVE_LIBMETALINK
else if(metalink) {
/* Metalink: Decide to try the next resource or
not. Basically, we want to try the next resource if
@ -1466,7 +1450,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
else
metalink_next_res = 1;
}
#endif /* HAVE_LIBMETALINK */
/* In all ordinary cases, just break out of loop here */
break; /* curl_easy_perform loop */
@ -1620,7 +1603,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
infd = STDIN_FILENO;
}
#ifdef HAVE_LIBMETALINK
if(metalink) {
/* Should exit if error is fatal. */
if(is_fatal_error(res)) {
@ -1636,7 +1618,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
break;
}
else
#endif /* HAVE_LIBMETALINK */
if(urlnum > 1) {
/* when url globbing, exit loop upon critical error */
if(is_fatal_error(res))
@ -1736,10 +1717,8 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
if(config->errors_fopened && config->errors)
fclose(config->errors);
#ifdef HAVE_LIBMETALINK
/* Release metalink related resources here */
clean_metalink(config);
#endif /* HAVE_LIBMETALINK */
main_free(); /* cleanup */