aboutsummaryrefslogtreecommitdiff
path: root/src/tool_getparam.c
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-04-26 22:59:52 +0900
committerDaniel Stenberg <daniel@haxx.se>2012-05-26 23:07:42 +0200
commitb5fdbe848bc3d088445817aa890d3f2f74ac5b02 (patch)
treec74203901cba4d4b9916fad127bdfe6778622ee6 /src/tool_getparam.c
parentefb8471a69e0b5b9fe2296954b4917e294392372 (diff)
Support Metalink.
This change adds experimental Metalink support to curl. To enable Metalink support, run configure with --with-libmetalink. To feed Metalink file to curl, use --metalink option like this: $ curl -O --metalink foo.metalink We use libmetalink to parse Metalink files.
Diffstat (limited to 'src/tool_getparam.c')
-rw-r--r--src/tool_getparam.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
index 5a24cc8a9..d102dc9f1 100644
--- a/src/tool_getparam.c
+++ b/src/tool_getparam.c
@@ -44,6 +44,10 @@
#include "tool_parsecfg.h"
#include "tool_version.h"
+#ifdef HAVE_LIBMETALINK
+# include "tool_metalink.h"
+#endif /* HAVE_LIBMETALINK */
+
#include "memdebug.h" /* keep this as LAST include */
#ifdef MSDOS
@@ -170,6 +174,9 @@ static const struct LongShort aliases[]= {
{"$G", "delegation", TRUE},
{"$H", "mail-auth", TRUE},
{"$I", "post303", FALSE},
+#ifdef HAVE_LIBMETALINK
+ {"$J", "metalink", TRUE},
+#endif /* HAVE_LIBMETALINK */
{"0", "http1.0", FALSE},
{"1", "tlsv1", FALSE},
{"2", "sslv2", FALSE},
@@ -819,6 +826,72 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
case 'H': /* --mail-auth */
GetStr(&config->mail_auth, nextarg);
break;
+#ifdef HAVE_LIBMETALINK
+ case 'J': /* --metalink */
+ {
+ metalink_error_t r;
+ metalink_t* metalink;
+ metalink_file_t **files;
+ struct metalink *ml;
+
+ r = metalink_parse_file(nextarg, &metalink);
+
+ if(r != 0) {
+ fprintf(stderr, "ERROR: code=%d\n", r);
+ exit(EXIT_FAILURE);
+ }
+ ml = new_metalink(metalink);
+
+ if(config->metalink_list) {
+ config->metalink_last->next = ml;
+ config->metalink_last = ml;
+ }
+ else {
+ config->metalink_list = config->metalink_last = ml;
+ }
+
+ for(files = metalink->files; *files; ++files) {
+ struct getout *url;
+ /* Skip an entry which has no resource. */
+ if(!(*files)->resources[0]) continue;
+ if(config->url_get ||
+ ((config->url_get = config->url_list) != NULL)) {
+ /* there's a node here, if it already is filled-in continue to
+ find an "empty" node */
+ while(config->url_get && (config->url_get->flags & GETOUT_URL))
+ config->url_get = config->url_get->next;
+ }
+
+ /* now there might or might not be an available node to fill in! */
+
+ if(config->url_get)
+ /* existing node */
+ url = config->url_get;
+ else
+ /* there was no free node, create one! */
+ url=new_getout(config);
+
+ if(url) {
+ struct metalinkfile *mlfile;
+ /* Set name as url */
+ GetStr(&url->url, (*files)->name);
+
+ /* set flag metalink here */
+ url->flags |= GETOUT_URL | GETOUT_METALINK;
+ mlfile = new_metalinkfile(*files);
+
+ if(config->metalinkfile_list) {
+ config->metalinkfile_last->next = mlfile;
+ config->metalinkfile_last = mlfile;
+ }
+ else {
+ config->metalinkfile_list = config->metalinkfile_last = mlfile;
+ }
+ }
+ }
+ break;
+ }
+#endif /* HAVE_LIBMETALINK */
}
break;
case '#': /* --progress-bar */