s3: re-run make samba3-idl.
[Samba/cd1.git] / source3 / web / neg_lang.c
blobf897d1097432a9262cd1badd42e0043e369e3746
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 3 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, see <http://www.gnu.org/licenses/>.
18 Created by Ryo Kawahara <rkawa@lbe.co.jp>
21 #include "includes.h"
22 #include "web/swat_proto.h"
25 during a file download we first check to see if there is a language
26 specific file available. If there is then use that, otherwise
27 just open the specified file
29 int web_open(const char *fname, int flags, mode_t mode)
31 char *p = NULL;
32 char *lang = lang_tdb_current();
33 int fd;
34 if (lang) {
35 if (asprintf(&p, "lang/%s/%s", lang, fname) != -1) {
36 fd = sys_open(p, flags, mode);
37 free(p);
38 if (fd != -1) {
39 return fd;
44 /* fall through to default name */
45 return sys_open(fname, flags, mode);
49 struct pri_list {
50 float pri;
51 char *string;
54 static int qsort_cmp_list(struct pri_list *a, struct pri_list *b)
56 if (a->pri > b->pri) return -1;
57 if (a->pri < b->pri) return 1;
58 return 0;
62 choose from a list of languages. The list can be comma or space
63 separated
64 Keep choosing until we get a hit
65 Changed to habdle priority -- Simo
68 void web_set_lang(const char *lang_string)
70 char **lang_list, **count;
71 struct pri_list *pl;
72 int lang_num, i;
74 /* build the lang list */
75 lang_list = str_list_make_v3(talloc_tos(), lang_string, ", \t\r\n");
76 if (!lang_list) return;
78 /* sort the list by priority */
79 lang_num = 0;
80 count = lang_list;
81 while (*count && **count) {
82 count++;
83 lang_num++;
85 pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
86 if (!pl) {
87 return;
90 for (i = 0; i < lang_num; i++) {
91 char *pri_code;
92 if ((pri_code=strstr(lang_list[i], ";q="))) {
93 *pri_code = '\0';
94 pri_code += 3;
95 sscanf(pri_code, "%f", &(pl[i].pri));
96 } else {
97 pl[i].pri = 1;
99 pl[i].string = SMB_STRDUP(lang_list[i]);
101 TALLOC_FREE(lang_list);
103 TYPESAFE_QSORT(pl, lang_num, qsort_cmp_list);
105 /* it's not an error to not initialise - we just fall back to
106 the default */
108 for (i = 0; i < lang_num; i++) {
109 if (lang_tdb_init(pl[i].string)) break;
112 for (i = 0; i < lang_num; i++) {
113 SAFE_FREE(pl[i].string);
115 SAFE_FREE(pl);
117 return;