exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 6ef6de6c5c13a8614d334e9e49233326b18c8025
parent c6278ceeab336169c72ef55b2c3399738bcc89be
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 16 Jul 2020 00:19:48 +0200

fix Accept patterns with semicolons

Diffstat:
Msrc/mhd/mhd_legal.c | 45+++++++++++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 6 deletions(-)

diff --git 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,