Useful debug message. Patch by metze.
[Samba/nascimento.git] / source3 / web / neg_lang.c
blobda974f78a4a0a542bd9a0502179d4683a5e53611
1 /*
2 Unix SMB/CIFS implementation.
3 SWAT language handling
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 Created by Ryo Kawahara <rkawa@lbe.co.jp>
22 #include "includes.h"
23 #include "../web/swat_proto.h"
26 during a file download we first check to see if there is a language
27 specific file available. If there is then use that, otherwise
28 just open the specified file
30 int web_open(const char *fname, int flags, mode_t mode)
32 char *p = NULL;
33 char *lang = lang_tdb_current();
34 int fd;
35 if (lang) {
36 asprintf(&p, "lang/%s/%s", lang, fname);
37 if (p) {
38 fd = sys_open(p, flags, mode);
39 free(p);
40 if (fd != -1) {
41 return fd;
46 /* fall through to default name */
47 return sys_open(fname, flags, mode);
51 struct pri_list {
52 float pri;
53 char *string;
56 static int qsort_cmp_list(const void *x, const void *y) {
57 struct pri_list *a = (struct pri_list *)x;
58 struct pri_list *b = (struct pri_list *)y;
59 if (a->pri > b->pri) return -1;
60 if (a->pri == b->pri) return 0;
61 return 1;
65 choose from a list of languages. The list can be comma or space
66 separated
67 Keep choosing until we get a hit
68 Changed to habdle priority -- Simo
71 void web_set_lang(const char *lang_string)
73 char **lang_list, **count;
74 struct pri_list *pl;
75 int lang_num, i;
77 /* build the lang list */
78 lang_list = str_list_make(lang_string, ", \t\r\n");
79 if (!lang_list) return;
81 /* sort the list by priority */
82 lang_num = 0;
83 count = lang_list;
84 while (*count && **count) {
85 count++;
86 lang_num++;
88 pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num);
89 for (i = 0; i < lang_num; i++) {
90 char *pri_code;
91 if ((pri_code=strstr(lang_list[i], ";q="))) {
92 *pri_code = '\0';
93 pri_code += 3;
94 sscanf(pri_code, "%f", &(pl[i].pri));
95 } else {
96 pl[i].pri = 1;
98 pl[i].string = strdup(lang_list[i]);
100 str_list_free(&lang_list);
102 qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list);
104 /* it's not an error to not initialise - we just fall back to
105 the default */
107 for (i = 0; i < lang_num; i++) {
108 if (lang_tdb_init(pl[i].string)) break;
111 for (i = 0; i < lang_num; i++) {
112 SAFE_FREE(pl[i].string);
114 SAFE_FREE(pl);
116 return;