diff options
author | Simo Sorce <idra@samba.org> | 2002-07-28 18:10:39 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2002-07-28 18:10:39 +0000 |
commit | a4ec4acd61d58bca9c1f6d474ab16265e4113f7a (patch) | |
tree | 83a1ff7a5b26b4007e4479ed4e7466624292f0a0 /source3/web | |
parent | 551d50c4e2bdde0b4f92001c92f8f69ffade44ad (diff) | |
download | samba-a4ec4acd61d58bca9c1f6d474ab16265e4113f7a.tar.gz samba-a4ec4acd61d58bca9c1f6d474ab16265e4113f7a.tar.bz2 samba-a4ec4acd61d58bca9c1f6d474ab16265e4113f7a.zip |
found nasty bug in intl/lang_tdb.c tdb structure was not tested to not be null before close
this one fixes swat not working with browsers that set more then one language.
along the way implemented language priority in web/neg_lang.c with bubble sort
also changet str_list_make to be able to use a different separator string
Simo.
(This used to be commit 69765e4faa8aaae74c97afc917891fc72d80703d)
Diffstat (limited to 'source3/web')
-rw-r--r-- | source3/web/neg_lang.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 88bc5498e9..72dd70fd98 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -52,14 +52,54 @@ int web_open(const char *fname, int flags, mode_t mode) choose from a list of languages. The list can be comma or space separated Keep choosing until we get a hit + Changed to habdle priority -- Simo */ -void web_set_lang(const char *lang_list) +void web_set_lang(const char *lang_string) { - fstring lang; - char *p = (char *)lang_list; + char **lang_list, **count; + float *pri; + int lang_num, i; + + /* build the lang list */ + lang_list = str_list_make(lang_string, ", \t\r\n"); + if (!lang_list) return; - while (next_token(&p, lang, ", \t\r\n", sizeof(lang))) { - if (lang_tdb_init(lang)) return; + /* sort the list by priority */ + lang_num = 0; + count = lang_list; + while (*count && **count) { + count++; + lang_num++; + } + pri = (float *)malloc(sizeof(float) * lang_num); + for (i = 0; i < lang_num; i++) { + char *pri_code; + if ((pri_code=strstr(lang_list[i], ";q="))) { + *pri_code = '\0'; + pri_code += 3; + pri[i] = strtof(pri_code, NULL); + } else { + pri[i] = 1; + } + if (i != 0) { + int l; + for (l = i; l > 0; l--) { + if (pri[l] > pri[l-1]) { + char *tempc; + int tempf; + tempc = lang_list[l]; + tempf = pri[l]; + lang_list[l] = lang_list[l-1]; + pri[i] = pri[l-1]; + lang_list[l-1] = tempc; + pri[l-1] = tempf; + } + } + } + } + + for (i = 0; i < lang_num; i++) { + if (lang_tdb_init(lang_list[i])) return; } /* it's not an error to not initialise - we just fall back to |