fix Accept patterns with semicolons

This commit is contained in:
Christian Grothoff 2020-07-16 00:19:48 +02:00
parent c6278ceeab
commit 6ef6de6c5c
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -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
*/
@ -107,6 +108,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.
@ -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,