From 46dde9368f75013b2383c24d4c8a11763ac8e31e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Aug 2020 18:19:00 +0200 Subject: implement i18n lookup logic for #6458 --- src/mhd/mhd_legal.c | 54 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 50 deletions(-) (limited to 'src/mhd/mhd_legal.c') diff --git a/src/mhd/mhd_legal.c b/src/mhd/mhd_legal.c index 7de189cce..0f2433c2c 100644 --- a/src/mhd/mhd_legal.c +++ b/src/mhd/mhd_legal.c @@ -154,52 +154,6 @@ xmime_matches (const char *accept_pattern, } -/** - * 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 - * - * @param language_pattern a language preferences string - * like "fr-CH, fr;q=0.9, en;q=0.8, *;q=0.1" - * @param lang the 2-digit language to match - * @return q-weight given for @a lang in @a language_pattern, 1.0 if no weights are given; - * 0 if @a lang is not in @a language_pattern - */ -double -TALER_MHD_language_matches (const char *language_pattern, - const char *lang) -{ - char *p = GNUNET_strdup (language_pattern); - char *sptr; - double r = 0.0; - - for (char *tok = strtok_r (p, ",", &sptr); - NULL != tok; - tok = strtok_r (NULL, ",", &sptr)) - { - char *sptr2; - char *lp = strtok_r (tok, ";", &sptr2); - char *qp = strtok_r (NULL, ";", &sptr2); - double q = 1.0; - - while (isspace ((int) *lp)) - lp++; - if (NULL != qp) - while (isspace ((int) *qp)) - qp++; - GNUNET_break_op ( (NULL == qp) || - (1 == sscanf (qp, - "q=%lf", - &q)) ); - if (0 == strcasecmp (lang, - lp)) - r = GNUNET_MAX (r, q); - } - GNUNET_free (p); - return r; -} - - /** * Generate a response with a legal document in the format and language of the * user's choosing. @@ -271,10 +225,10 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn, if ( (NULL == t) || (! xmime_matches (mime, t->mime_type)) || - (TALER_MHD_language_matches (lang, - p->language) > - TALER_MHD_language_matches (lang, - t->language) ) ) + (TALER_language_matches (lang, + p->language) > + TALER_language_matches (lang, + t->language) ) ) t = p; } } -- cgit v1.2.3