aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-05-26 22:51:03 +0900
committerDaniel Stenberg <daniel@haxx.se>2012-05-26 23:12:09 +0200
commit1bfd750f3f9e173ce5a6735756106cf6a1804960 (patch)
tree35251f9f29750ebef094ccf30b413eaa1a1ca918 /src
parent7bdb9fba952ea24390b903478aedb5e1615ae2d4 (diff)
Reduced #ifdef HAVE_METALINK
Diffstat (limited to 'src')
-rw-r--r--src/Makefile-metalink.inc1
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.inc6
-rw-r--r--src/tool_cfgable.h5
-rw-r--r--src/tool_getparam.c5
-rw-r--r--src/tool_metalink.c126
-rw-r--r--src/tool_metalink.h2
-rw-r--r--src/tool_operate.c23
8 files changed, 73 insertions, 98 deletions
diff --git a/src/Makefile-metalink.inc b/src/Makefile-metalink.inc
deleted file mode 100644
index b6eb4d2e4..000000000
--- a/src/Makefile-metalink.inc
+++ /dev/null
@@ -1 +0,0 @@
-curl_SOURCES += tool_metalink.c tool_metalink.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 90c9716b6..6e8ce38a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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@
diff --git a/src/Makefile.inc b/src/Makefile.inc
index e070b3a66..3265ea9d8 100644
--- a/src/Makefile.inc
+++ b/src/Makefile.inc
@@ -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)
diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h
index 72f6cef30..2183c04df 100644
--- a/src/tool_cfgable.h
+++ b/src/tool_cfgable.h
@@ -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);
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index a07c67176..c8dc7ae14 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -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 */
diff --git a/src/tool_metalink.c b/src/tool_metalink.c
index 461dbf148..6e18b4247 100644
--- a/src/tool_metalink.c
+++ b/src/tool_metalink.c
@@ -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;
+}
diff --git a/src/tool_metalink.h b/src/tool_metalink.h
index bffa0deea..e3c66fc23 100644
--- a/src/tool_metalink.h
+++ b/src/tool_metalink.h
@@ -23,8 +23,6 @@
***************************************************************************/
#include "tool_setup.h"
-#include <metalink/metalink_parser.h>
-
struct Configurable;
#if defined(USE_OPENSSL) || defined(USE_GNUTLS)
diff --git a/src/tool_operate.c b/src/tool_operate.c
index c0b66946c..75bb5b34d 100644
--- a/src/tool_operate.c
+++ b/src/tool_operate.c
@@ -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 */