| 1532 | */ |
| 1533 | |
| 1534 | static void set_language_quality(negotiation_state *neg, var_rec *variant) |
| 1535 | { |
| 1536 | int forcepriority = neg->conf->forcelangpriority; |
| 1537 | if (forcepriority == FLP_UNDEF) { |
| 1538 | forcepriority = FLP_DEFAULT; |
| 1539 | } |
| 1540 | |
| 1541 | if (!variant->content_languages || !variant->content_languages->nelts) { |
| 1542 | /* This variant has no content-language, so use the default |
| 1543 | * quality factor for variants with no content-language |
| 1544 | * (previously set by set_default_lang_quality()). |
| 1545 | * Leave the factor alone (it remains at 1.0) when we may not fiddle |
| 1546 | * with the headers. |
| 1547 | */ |
| 1548 | if (!neg->dont_fiddle_headers) { |
| 1549 | variant->lang_quality = neg->default_lang_quality; |
| 1550 | } |
| 1551 | return; |
| 1552 | } |
| 1553 | else { |
| 1554 | /* Variant has one (or more) languages. Look for the best |
| 1555 | * match. We do this by going through each language on the |
| 1556 | * variant description looking for a match on the |
| 1557 | * Accept-Language header. The best match is the longest |
| 1558 | * matching language on the header. The final result is the |
| 1559 | * best q value from all the languages on the variant |
| 1560 | * description. |
| 1561 | */ |
| 1562 | |
| 1563 | if (!neg->accept_langs) { |
| 1564 | /* no accept-language header makes the variant indefinite */ |
| 1565 | variant->definite = 0; |
| 1566 | } |
| 1567 | else { /* There is an accept-language with 0 or more items */ |
| 1568 | accept_rec *accs = (accept_rec *) neg->accept_langs->elts; |
| 1569 | accept_rec *best = NULL, *star = NULL; |
| 1570 | accept_rec *bestthistag; |
| 1571 | char *lang, *p; |
| 1572 | float fiddle_q = 0.0f; |
| 1573 | int any_match_on_star = 0; |
| 1574 | int i, j; |
| 1575 | apr_size_t alen, longest_lang_range_len; |
| 1576 | |
| 1577 | for (j = 0; j < variant->content_languages->nelts; ++j) { |
| 1578 | p = NULL; |
| 1579 | bestthistag = NULL; |
| 1580 | longest_lang_range_len = 0; |
| 1581 | |
| 1582 | /* lang is the variant's language-tag, which is the one |
| 1583 | * we are allowed to use the prefix of in HTTP/1.1 |
| 1584 | */ |
| 1585 | lang = ((char **) (variant->content_languages->elts))[j]; |
| 1586 | |
| 1587 | /* now find the best (i.e. longest) matching |
| 1588 | * Accept-Language header language. We put the best match |
| 1589 | * for this tag in bestthistag. We cannot update the |
| 1590 | * overall best (based on q value) because the best match |
| 1591 | * for this tag is the longest language item on the accept |
no test coverage detected