diff options
| author | Christian Grothoff <christian@grothoff.org> | 2020-07-16 00:19:48 +0200 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2020-07-16 00:19:48 +0200 | 
| commit | 6ef6de6c5c13a8614d334e9e49233326b18c8025 (patch) | |
| tree | dcf8f87e97188d89551914f13d1846e60945d601 | |
| parent | c6278ceeab336169c72ef55b2c3399738bcc89be (diff) | |
fix Accept patterns with semicolons
| -rw-r--r-- | src/mhd/mhd_legal.c | 45 | 
1 files changed, 39 insertions, 6 deletions
| diff --git a/src/mhd/mhd_legal.c b/src/mhd/mhd_legal.c index 19a21475..f46f9742 100644 --- a/src/mhd/mhd_legal.c +++ b/src/mhd/mhd_legal.c @@ -1,6 +1,6 @@  /*    This file is part of TALER -  Copyright (C) 2019 Taler Systems SA +  Copyright (C) 2019, 2020 Taler Systems SA    TALER is free software; you can redistribute it and/or modify it under the    terms of the GNU Affero General Public License as published by the Free Software @@ -80,7 +80,8 @@ struct TALER_MHD_Legal  /**   * Check if @a mime matches the @a accept_pattern.   * - * @param accept_pattern a mime pattern like text/plain or image/STAR + * @param accept_pattern a mime pattern like "text/plain" + *        or "image/STAR"   * @param mime the mime type to match   * @return true if @a mime matches the @a accept_pattern   */ @@ -108,6 +109,38 @@ mime_matches (const char *accept_pattern,  /** + * Check if @a mime matches the @a accept_pattern.  For this function, the @a + * accept_pattern may include multiple values separated by ";". + * + * @param accept_pattern a mime pattern like "text/plain" + *        or "image/STAR" or "text/plain; text/xml" + * @param mime the mime type to match + * @return true if @a mime matches the @a accept_pattern + */ +static bool +xmime_matches (const char *accept_pattern, +               const char *mime) +{ +  char *ap = GNUNET_strdup (accept_pattern); +  char *sptr; + +  for (const char *tok = strtok_r (ap, ";", &sptr); +       NULL != tok; +       tok = strtok_r (NULL, ";", &sptr)) +  { +    if (mime_matches (tok, +                      mime)) +    { +      GNUNET_free (ap); +      return true; +    } +  } +  GNUNET_free (ap); +  return false; +} + + +/**   * Check if @a lang matches the @a language_pattern, and if so with   * which preference.   * See also: https://tools.ietf.org/html/rfc7231#section-5.3.1 @@ -218,12 +251,12 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,        struct Terms *p = &legal->terms[i];        if ( (NULL == t) || -           (mime_matches (mime, -                          p->mime_type)) ) +           (xmime_matches (mime, +                           p->mime_type)) )        {          if ( (NULL == t) || -             (! mime_matches (mime, -                              t->mime_type)) || +             (! xmime_matches (mime, +                               t->mime_type)) ||               (language_matches (lang,                                  p->language) >                language_matches (lang, | 
