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

Support media-type parameter in Content-Type

parent 963bcde4
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@
 *
 ***************************************************************************/
#include "tool_setup.h"

#include "rawstr.h"

#include "tool_metalink.h"
#include "tool_getparam.h"
#include "tool_paramhlp.h"
@@ -142,3 +145,24 @@ int parse_metalink(struct Configurable *config, const char *infile)
  }
  return 0;
}

/*
 * Returns nonzero if content_type includes mediatype.
 */
static int check_content_type(const char *content_type, const char *media_type)
{
  const char *ptr = content_type;
  size_t media_type_len = strlen(media_type);
  for(; *ptr && (*ptr == ' ' || *ptr == '\t'); ++ptr);
  if(!*ptr) {
    return 0;
  }
  return Curl_raw_nequal(ptr, media_type, media_type_len) &&
    (*(ptr+media_type_len) == '\0' || *(ptr+media_type_len) == ' ' ||
     *(ptr+media_type_len) == '\t' || *(ptr+media_type_len) == ';');
}

int check_metalink_content_type(const char *content_type)
{
  return check_content_type(content_type, "application/metalink+xml");
}
+6 −0
Original line number Diff line number Diff line
@@ -50,4 +50,10 @@ void clean_metalink(struct Configurable *config);

int parse_metalink(struct Configurable *config, const char *infile);

/*
 * Returns nonzero if content_type includes "application/metalink+xml"
 * media-type. The check is done in case-insensitive manner.
 */
int check_metalink_content_type(const char *content_type);

#endif /* HEADER_CURL_TOOL_METALINK_H */
+1 −2
Original line number Diff line number Diff line
@@ -1582,8 +1582,7 @@ int operate(struct Configurable *config, int argc, argv_item_t argv[])
             Metalink file, parse it and add getout for them. */
          char *content_type;
          curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &content_type);
          if(content_type &&
             Curl_raw_equal("application/metalink+xml", content_type)) {
          if(content_type && check_metalink_content_type(content_type)) {
            if(!(config->mute)) {
              fprintf(config->errors, "\nParsing Metalink file: %s\n",
                      outs.filename);