For a given variant, find the 'q' value of the charset given * on the Accept-Charset line. If no charsets are listed, * assume value of '1'. */
| 1843 | * assume value of '1'. |
| 1844 | */ |
| 1845 | static void set_charset_quality(negotiation_state *neg, var_rec *variant) |
| 1846 | { |
| 1847 | int i; |
| 1848 | accept_rec *accept_recs; |
| 1849 | const char *charset = variant->content_charset; |
| 1850 | accept_rec *star = NULL; |
| 1851 | |
| 1852 | /* if no Accept-Charset: header, leave quality alone (will |
| 1853 | * remain at the default value of 1) |
| 1854 | */ |
| 1855 | if (!neg->accept_charsets) { |
| 1856 | if (charset && *charset) |
| 1857 | variant->definite = 0; |
| 1858 | return; |
| 1859 | } |
| 1860 | |
| 1861 | accept_recs = (accept_rec *) neg->accept_charsets->elts; |
| 1862 | |
| 1863 | if (charset == NULL || !*charset) { |
| 1864 | /* Charset of variant not known */ |
| 1865 | |
| 1866 | /* if not a text / * type, leave quality alone */ |
| 1867 | if (!(!strncmp(variant->mime_type, "text/", 5) |
| 1868 | || !strcmp(variant->mime_type, INCLUDES_MAGIC_TYPE) |
| 1869 | || !strcmp(variant->mime_type, INCLUDES_MAGIC_TYPE3) |
| 1870 | )) |
| 1871 | return; |
| 1872 | |
| 1873 | /* Don't go guessing if we are in strict header mode, |
| 1874 | * e.g. when running the rvsa, as any guess won't be reflected |
| 1875 | * in the variant list or content-location headers. |
| 1876 | */ |
| 1877 | if (neg->dont_fiddle_headers) |
| 1878 | return; |
| 1879 | |
| 1880 | charset = "iso-8859-1"; /* The default charset for HTTP text types */ |
| 1881 | } |
| 1882 | |
| 1883 | /* |
| 1884 | * Go through each of the items on the Accept-Charset header, |
| 1885 | * looking for a match with this variant's charset. If none |
| 1886 | * match, charset is unacceptable, so set quality to 0. |
| 1887 | */ |
| 1888 | for (i = 0; i < neg->accept_charsets->nelts; ++i) { |
| 1889 | |
| 1890 | accept_rec *type = &accept_recs[i]; |
| 1891 | |
| 1892 | if (!strcmp(type->name, charset)) { |
| 1893 | variant->charset_quality = type->quality; |
| 1894 | return; |
| 1895 | } |
| 1896 | else if (strcmp(type->name, "*") == 0) { |
| 1897 | star = type; |
| 1898 | } |
| 1899 | } |
| 1900 | /* No explicit match */ |
| 1901 | if (star) { |
| 1902 | variant->charset_quality = star->quality; |