gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: fix Accept patterns with semicol


From: gnunet
Subject: [taler-exchange] branch master updated: fix Accept patterns with semicolons
Date: Thu, 16 Jul 2020 00:19:55 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 6ef6de6c fix Accept patterns with semicolons
6ef6de6c is described below

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

    fix Accept patterns with semicolons
---
 src/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
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
  */
@@ -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,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]