s3:lib: remove function connections_forall()
[Samba/gebeck_regimport.git] / source3 / web / neg_lang.c
blobc415449d09182304f3fe17d55c2e6f3e3ef76ff8
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"
23 #include "intl/lang_tdb.h"
24 #include "system/filesys.h"
27 during a file download we first check to see if there is a language
28 specific file available. If there is then use that, otherwise
29 just open the specified file
31 int web_open(const char *fname, int flags, mode_t mode)
33 char *p = NULL;
34 char *lang = lang_tdb_current();
35 int fd;
36 if (lang) {
37 if (asprintf(&p, "lang/%s/%s", lang, fname) != -1) {
38 fd = open(p, flags, mode);
39 free(p);
40 if (fd != -1) {
41 return fd;
46 /* fall through to default name */
47 return open(fname, flags, mode);
51 struct pri_list {
52 float pri;
53 char *string;
56 static int qsort_cmp_list(struct pri_list *a, struct pri_list *b)
58 if (a->pri > b->pri) return -1;
59 if (a->pri < b->pri) return 1;
60 return 0;
64 choose from a list of languages. The list can be comma or space
65 separated
66 Keep choosing until we get a hit
67 Changed to habdle priority -- Simo
70 void web_set_lang(const char *lang_string)
72 char **lang_list, **count;
73 struct pri_list *pl;
74 int lang_num, i;
76 /* build the lang list */
77 lang_list = str_list_make_v3(talloc_tos(), lang_string, ", \t\r\n");
78 if (!lang_list) return;
80 /* sort the list by priority */
81 lang_num = 0;
82 count = lang_list;
83 while (*count && **count) {
84 count++;
85 lang_num++;
87 pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
88 if (!pl) {
89 return;
92 for (i = 0; i < lang_num; i++) {
93 char *pri_code;
94 if ((pri_code=strstr(lang_list[i], ";q="))) {
95 *pri_code = '\0';
96 pri_code += 3;
97 sscanf(pri_code, "%f", &(pl[i].pri));
98 } else {
99 pl[i].pri = 1;
101 pl[i].string = SMB_STRDUP(lang_list[i]);
103 TALLOC_FREE(lang_list);
105 TYPESAFE_QSORT(pl, lang_num, qsort_cmp_list);
107 /* it's not an error to not initialise - we just fall back to
108 the default */
110 for (i = 0; i < lang_num; i++) {
111 if (lang_tdb_init(pl[i].string)) break;
114 for (i = 0; i < lang_num; i++) {
115 SAFE_FREE(pl[i].string);
117 SAFE_FREE(pl);
119 return;