s4:pydsdb: remove unused variable from py_dsdb_am_pdc()
[Samba/id10ts.git] / source3 / web / neg_lang.c
blob59475d12b57ccb4299ea44a042a0156f67b51f92
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"
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 if (asprintf(&p, "lang/%s/%s", lang, fname) != -1) {
37 fd = sys_open(p, flags, mode);
38 free(p);
39 if (fd != -1) {
40 return fd;
45 /* fall through to default name */
46 return sys_open(fname, flags, mode);
50 struct pri_list {
51 float pri;
52 char *string;
55 static int qsort_cmp_list(struct pri_list *a, struct pri_list *b)
57 if (a->pri > b->pri) return -1;
58 if (a->pri < b->pri) return 1;
59 return 0;
63 choose from a list of languages. The list can be comma or space
64 separated
65 Keep choosing until we get a hit
66 Changed to habdle priority -- Simo
69 void web_set_lang(const char *lang_string)
71 char **lang_list, **count;
72 struct pri_list *pl;
73 int lang_num, i;
75 /* build the lang list */
76 lang_list = str_list_make_v3(talloc_tos(), lang_string, ", \t\r\n");
77 if (!lang_list) return;
79 /* sort the list by priority */
80 lang_num = 0;
81 count = lang_list;
82 while (*count && **count) {
83 count++;
84 lang_num++;
86 pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
87 if (!pl) {
88 return;
91 for (i = 0; i < lang_num; i++) {
92 char *pri_code;
93 if ((pri_code=strstr(lang_list[i], ";q="))) {
94 *pri_code = '\0';
95 pri_code += 3;
96 sscanf(pri_code, "%f", &(pl[i].pri));
97 } else {
98 pl[i].pri = 1;
100 pl[i].string = SMB_STRDUP(lang_list[i]);
102 TALLOC_FREE(lang_list);
104 TYPESAFE_QSORT(pl, lang_num, qsort_cmp_list);
106 /* it's not an error to not initialise - we just fall back to
107 the default */
109 for (i = 0; i < lang_num; i++) {
110 if (lang_tdb_init(pl[i].string)) break;
113 for (i = 0; i < lang_num; i++) {
114 SAFE_FREE(pl[i].string);
116 SAFE_FREE(pl);
118 return;