Removed version number from file header.
[samba.git] / source3 / web / neg_lang.c
1 /*
2    Unix SMB/CIFS implementation.
3    SWAT language handling
4    
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.
9    
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.
14    
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.
18
19    Created by Ryo Kawahara <rkawa@lbe.co.jp> 
20 */
21
22 #include "includes.h"
23
24 /*
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
28 */
29 int web_open(const char *fname, int flags, mode_t mode)
30 {
31         char *p = NULL;
32         char *lang = lang_tdb_current();
33         int fd;
34         if (lang) {
35                 asprintf(&p, "lang/%s/%s", lang, fname);
36                 if (p) {
37                         fd = sys_open(p, flags, mode);
38                         free(p);
39                         if (fd != -1) {
40                                 return fd;
41                         }
42                 }
43         }
44
45         /* fall through to default name */
46         return sys_open(fname, flags, mode);
47 }
48
49
50 /*
51   choose from a list of languages. The list can be comma or space
52   separated
53   Keep choosing until we get a hit 
54 */
55 void web_set_lang(const char *lang_list)
56 {
57         fstring lang;
58         char *p = (char *)lang_list;
59         
60         while (next_token(&p, lang, ", \t\r\n", sizeof(lang))) {
61                 if (lang_tdb_init(lang)) return;
62         }
63         
64         /* it's not an error to not initialise - we just fall back to 
65            the default */
66 }