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

tool_metalink.c: Filtered resource URLs by type

In Metalink v3, the type attribute of url element indicates the
type of the resource the URL points to. It can include URL to the
meta data, such as BitTorrent metainfo file.  In Curl, we are not
interested in these meta data URLs. Instead, we are only
interested in the HTTP and FTP URLs. This change filters out
non-HTTP and FTP URLs. If we don't filter out them, it will be
downloaded by curl and hash check will fail if hash is provided
and next URL will be tried. This change will cut this useless
network transfer.
parent c01b6f4d
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -573,10 +573,25 @@ static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo)
    tail = &root;
    for(p = fileinfo->resources; *p; ++p) {
      metalink_resource *res;
      /* Filter by type if it is non-NULL. In Metalink v3, type
         includes the type of the resource. In curl, we are only
         interested in HTTP, HTTPS and FTP. In addition to them,
         Metalink v3 file may contain bittorrent type URL, which
         points to the BitTorrent metainfo file. We ignore it here.
         In Metalink v4, type was deprecated and all
         fileinfo->resources point to the target file. BitTorrent
         metainfo file URL may be appeared in fileinfo->metaurls.
      */
      if((*p)->type == NULL ||
         Curl_raw_equal((*p)->type, "http") ||
         Curl_raw_equal((*p)->type, "https") ||
         Curl_raw_equal((*p)->type, "ftp") ||
         Curl_raw_equal((*p)->type, "ftps")) {
        res = new_metalink_resource((*p)->url);
        tail->next = res;
        tail = res;
      }
    }
    f->resource = root.next;
  }
  return f;