expose language check logic
This commit is contained in:
parent
ad27d52bdb
commit
f1cc1ca208
@ -96,6 +96,22 @@ MHD_RESULT
|
|||||||
TALER_MHD_can_compress (struct MHD_Connection *connection);
|
TALER_MHD_can_compress (struct MHD_Connection *connection);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send JSON object as response.
|
* Send JSON object as response.
|
||||||
*
|
*
|
||||||
|
@ -165,9 +165,9 @@ xmime_matches (const char *accept_pattern,
|
|||||||
* @return q-weight given for @a lang in @a language_pattern, 1.0 if no weights are given;
|
* @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
|
* 0 if @a lang is not in @a language_pattern
|
||||||
*/
|
*/
|
||||||
static double
|
double
|
||||||
language_matches (const char *language_pattern,
|
TALER_MHD_language_matches (const char *language_pattern,
|
||||||
const char *lang)
|
const char *lang)
|
||||||
{
|
{
|
||||||
char *p = GNUNET_strdup (language_pattern);
|
char *p = GNUNET_strdup (language_pattern);
|
||||||
char *sptr;
|
char *sptr;
|
||||||
@ -271,10 +271,10 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
|
|||||||
if ( (NULL == t) ||
|
if ( (NULL == t) ||
|
||||||
(! xmime_matches (mime,
|
(! xmime_matches (mime,
|
||||||
t->mime_type)) ||
|
t->mime_type)) ||
|
||||||
(language_matches (lang,
|
(TALER_MHD_language_matches (lang,
|
||||||
p->language) >
|
p->language) >
|
||||||
language_matches (lang,
|
TALER_MHD_language_matches (lang,
|
||||||
t->language) ) )
|
t->language) ) )
|
||||||
t = p;
|
t = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user