2001-09-24 19:55:09 +04:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
2001-10-14 16:10:29 +04:00
SWAT language handling
2001-09-24 19:55:09 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2001-09-24 19:55:09 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2001-09-24 19:55:09 +04:00
Created by Ryo Kawahara < rkawa @ lbe . co . jp >
*/
# include "includes.h"
2004-10-07 08:01:18 +04:00
# include "web/swat_proto.h"
2011-03-23 01:58:21 +03:00
# include "intl/lang_tdb.h"
2001-09-24 19:55:09 +04:00
/*
2001-10-14 16:10:29 +04:00
during a file download we first check to see if there is a language
specific file available . If there is then use that , otherwise
just open the specified file
*/
int web_open ( const char * fname , int flags , mode_t mode )
2001-09-24 19:55:09 +04:00
{
2001-10-14 16:10:29 +04:00
char * p = NULL ;
char * lang = lang_tdb_current ( ) ;
int fd ;
if ( lang ) {
2008-12-31 05:24:39 +03:00
if ( asprintf ( & p , " lang/%s/%s " , lang , fname ) ! = - 1 ) {
2001-10-14 16:10:29 +04:00
fd = sys_open ( p , flags , mode ) ;
free ( p ) ;
if ( fd ! = - 1 ) {
return fd ;
}
2001-09-24 19:55:09 +04:00
}
}
2001-10-14 16:10:29 +04:00
/* fall through to default name */
return sys_open ( fname , flags , mode ) ;
2001-09-24 19:55:09 +04:00
}
2002-08-17 18:34:48 +04:00
struct pri_list {
float pri ;
char * string ;
} ;
2010-02-14 02:03:55 +03:00
static int qsort_cmp_list ( struct pri_list * a , struct pri_list * b )
{
2002-08-17 18:34:48 +04:00
if ( a - > pri > b - > pri ) return - 1 ;
2006-07-11 22:01:26 +04:00
if ( a - > pri < b - > pri ) return 1 ;
return 0 ;
2002-08-17 18:34:48 +04:00
}
2001-10-14 16:10:29 +04:00
/*
choose from a list of languages . The list can be comma or space
separated
Keep choosing until we get a hit
2002-08-17 18:34:48 +04:00
Changed to habdle priority - - Simo
2001-10-14 16:10:29 +04:00
*/
2002-08-17 18:34:48 +04:00
void web_set_lang ( const char * lang_string )
2001-09-24 19:55:09 +04:00
{
2002-08-17 18:34:48 +04:00
char * * lang_list , * * count ;
struct pri_list * pl ;
int lang_num , i ;
/* build the lang list */
2008-11-07 05:53:00 +03:00
lang_list = str_list_make_v3 ( talloc_tos ( ) , lang_string , " , \t \r \n " ) ;
2002-08-17 18:34:48 +04:00
if ( ! lang_list ) return ;
2001-10-14 16:10:29 +04:00
2002-08-17 18:34:48 +04:00
/* sort the list by priority */
lang_num = 0 ;
count = lang_list ;
while ( * count & & * * count ) {
count + + ;
lang_num + + ;
2001-10-14 16:10:29 +04:00
}
2004-12-07 21:25:53 +03:00
pl = SMB_MALLOC_ARRAY ( struct pri_list , lang_num ) ;
2006-06-28 05:59:04 +04:00
if ( ! pl ) {
return ;
}
2002-08-17 18:34:48 +04:00
for ( i = 0 ; i < lang_num ; i + + ) {
char * pri_code ;
if ( ( pri_code = strstr ( lang_list [ i ] , " ;q= " ) ) ) {
* pri_code = ' \0 ' ;
pri_code + = 3 ;
sscanf ( pri_code , " %f " , & ( pl [ i ] . pri ) ) ;
} else {
pl [ i ] . pri = 1 ;
}
2004-12-07 21:25:53 +03:00
pl [ i ] . string = SMB_STRDUP ( lang_list [ i ] ) ;
2002-08-17 18:34:48 +04:00
}
2008-02-04 22:57:35 +03:00
TALLOC_FREE ( lang_list ) ;
2002-08-17 18:34:48 +04:00
2010-02-14 02:03:55 +03:00
TYPESAFE_QSORT ( pl , lang_num , qsort_cmp_list ) ;
2002-08-17 18:34:48 +04:00
2001-10-14 16:10:29 +04:00
/* it's not an error to not initialise - we just fall back to
the default */
2002-08-17 18:34:48 +04:00
for ( i = 0 ; i < lang_num ; i + + ) {
if ( lang_tdb_init ( pl [ i ] . string ) ) break ;
}
for ( i = 0 ; i < lang_num ; i + + ) {
SAFE_FREE ( pl [ i ] . string ) ;
}
SAFE_FREE ( pl ) ;
return ;
2001-09-24 19:55:09 +04:00
}