Commit a0d7a26e authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa Committed by Daniel Stenberg
Browse files

metalink: show help message even if disabled

Print message if --metalink is used while metalink support is not
enabled. Migrated Metalink support in tool_operate.c and removed
operatemetalink().
parent bb1ce6cc
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -826,9 +826,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
      case 'H': /* --mail-auth */
        GetStr(&config->mail_auth, nextarg);
        break;
#ifdef HAVE_LIBMETALINK
      case 'J': /* --metalink */
        {
#ifdef HAVE_LIBMETALINK
          metalink_error_t r;
          metalink_t* metalink;
          metalink_file_t **files;
@@ -889,9 +889,12 @@ ParameterError getparameter(char *flag, /* f or -long-flag */
              }
            }
          }
#else
          warnf(config, "--metalink option is ignored because the binary is "
                "built without the Metalink support.\n");
#endif
          break;
        }
#endif /* HAVE_LIBMETALINK */
      }
      break;
    case '#': /* --progress-bar */
+6 −930

File changed.

Preview size limit exceeded, changes collapsed.

+4 −7
Original line number Diff line number Diff line
@@ -41,13 +41,10 @@ struct metalinkfile *new_metalinkfile(metalink_file_t *metalinkfile);

struct metalink *new_metalink(metalink_t *metalink);

int operatemetalink(CURL *curl,
                    struct getout *urlnode,
                    long retry_sleep_default,
                    struct OutStruct outs,
                    struct OutStruct heads,
                    char *outfiles,
                    struct Configurable *config);
/*
 * Counts the resource in the metalinkfile.
 */
int count_next_metalink_resource(struct metalinkfile *mlfile);

void clean_metalink(struct Configurable *config);

+82 −35
Original line number Diff line number Diff line
@@ -406,11 +406,26 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
    char *outfiles;
    int infilenum;
    URLGlob *inglob;
    int metalink; /* nonzero for metalink download */
    struct metalinkfile *mlfile;
    metalink_resource_t **mlres;

    outfiles = NULL;
    infilenum = 1;
    inglob = NULL;

    if(urlnode->flags & GETOUT_METALINK) {
      metalink = 1;
      mlfile = config->metalinkfile_last;
      mlres = mlfile->file->resources;
      config->metalinkfile_last = config->metalinkfile_last->next;
    }
    else {
      metalink = 0;
      mlfile = NULL;
      mlres = NULL;
    }

    /* urlnode->url is the full URL (it might be NULL) */

    if(!urlnode->url) {
@@ -444,24 +459,6 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
      }
    }

    /* process metalink download in the separate function */
    if(urlnode->flags & GETOUT_METALINK) {
      struct OutStruct outs;
      long retry_sleep_default;
      struct getout *nextnode;

      retry_sleep_default = (config->retry_delay) ?
        config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */
      /* default output stream is stdout */
      memset(&outs, 0, sizeof(struct OutStruct));
      outs.stream = stdout;
      outs.config = config;
      operatemetalink(curl, urlnode, retry_sleep_default, outs, heads,
                      outfiles, config);
      /* move on to the next URL */
      continue;
    }

    /* Here's the loop for uploading multiple files within the same
       single globbed string. If no upload, we enter the loop once anyway. */
    for(up = 0 ; up < infilenum; up++) {
@@ -497,7 +494,12 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
          break;
      }

      if(!config->globoff) {
      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 if(!config->globoff) {
        /* Unless explicitly shut off, we expand '{...}' and '[...]'
           expressions and return total number of URLs in pattern set */
        res = glob_url(&urls, urlnode->url, &urlnum,
@@ -528,17 +530,32 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
        long retry_sleep;
        char *this_url;
        HeaderData hdrdata;
        int metalink_next_res;

        outfile = NULL;
        infdopen = FALSE;
        infd = STDIN_FILENO;
        uploadfilesize = -1; /* -1 means unknown */
        metalink_next_res = 0;

        /* default output stream is stdout */
        memset(&outs, 0, sizeof(struct OutStruct));
        outs.stream = stdout;
        outs.config = config;

        if(metalink) {
          outfile = strdup(mlfile->file->name);
          if(!outfile) {
            res = CURLE_OUT_OF_MEMORY;
            goto show_error;
          }
          this_url = strdup((*mlres)->url);
          if(!this_url) {
            res = CURLE_OUT_OF_MEMORY;
            goto show_error;
          }
        }
        else {
          if(urls) {
            res = glob_next_url(&this_url, urls);
            if(res)
@@ -563,6 +580,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
              goto show_error;
            }
          }
        }

        if((urlnode->flags&GETOUT_USEREMOTE) ||
           (outfile && !curlx_strequal("-", outfile)) ) {
@@ -1408,6 +1426,28 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
              continue; /* curl_easy_perform loop */
            }
          } /* if retry_numretries */
          else if(metalink) {
            /* Metalink: Decide to try the next resource or
               not. Basically, we want to try the next resource if
               download was not successful. */
            long response;
            if(CURLE_OK == res) {
              /* TODO We want to try next resource when download was
                 not successful. How to know that? */
              char *effective_url = NULL;
              curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url);
              if(effective_url &&
                 curlx_strnequal(effective_url, "http", 4)) {
                /* This was HTTP(S) */
                curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
                if(response != 200 && response != 206) {
                  metalink_next_res = 1;
                }
              }
            }
            else
              metalink_next_res = 1;
          }

          /* In all ordinary cases, just break out of loop here */
          break; /* curl_easy_perform loop */
@@ -1532,7 +1572,14 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
          infd = STDIN_FILENO;
        }

        if(urlnum > 1) {
        if(metalink) {
          if(is_fatal_error(res)) {
            break;
          }
          if(!metalink_next_res || *(++mlres) == NULL)
            break;
        }
        else if(urlnum > 1) {
          /* when url globbing, exit loop upon critical error */
          if(is_fatal_error(res))
            break;