From 96db4b1ba3a48f50b80b2cfbf0b940e073b7843c Mon Sep 17 00:00:00 2001 From: Motonobu Takahashi Date: Mon, 24 Sep 2001 15:55:09 +0000 Subject: Added SWAT i18n feature: TO enable configure with --with-i18n-swat to support this gettext is integrated and a new directories name "po" and "intl" are created. now these languages are supported: en - English (default) ja - Japanese po - Polish tr - Turkish To add your language, to create ${your_language}.po by translating source/po/en.po into your language is needed. some of html and image files of various language version are not included yet, though message catalogue files are installed. you need to copy files manually under ${swatdir}/lang/$ln/{help,images,included,using_samba} And also added a option to intall manual pages: of various lang version To enable configure with --with-manlangs but manual pages themself are not included yet. (This used to be commit 486b79a6fc4ba20a751aab544bd0f7ccff2b3d19) --- source3/web/neg_lang.c | 378 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 source3/web/neg_lang.c (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c new file mode 100644 index 0000000000..8cb41a34ec --- /dev/null +++ b/source3/web/neg_lang.c @@ -0,0 +1,378 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + Samba Web Administration Tool + + 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 + the Free Software Foundation; either version 2 of the License, or + (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 + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Created by Ryo Kawahara +*/ + +#include "includes.h" +/* #include "config.h" */ +#include "webintl.h" + +#if I18N_SWAT +/* constants. */ +/* it is ok to make them bigger.*/ +#define LN_PREFLANG_MAX 10 +#define LN_LNAME_LENGTH 8+1+8 + +#define LN_DEFAULT_LANG I18N_DEFAULT_LANG +#define LN_LANGDESC_DEFAULT -1 +#define LN_NO_AVAILABLE_LANG -1 + +/* ****************************************************************** + * macros for debugging. + ***************************************************************** */ +#ifdef LN_R_NODEBUG + +#else +/* + *#define LN_DEBUG_LOG "/tmp/lndebug.log" + *void ln_debug_error(const char *info, int nLine) + *{ + * FILE* fp; + * fp = sys_fopen(LN_DEBUG_LOG, "a"); + * fprintf(fp, "%s at %d.\n", info, nLine); + * fclose(fp); + *} + *void rassert_help(BOOL b, int l) + *{ + * if(!b) + * { + * ln_debug_error("language negotiation error.", l); + * exit(1); + * } + *} + */ +#endif /* LN_R_NODEBUG */ + +/* **************************************************************** + LNNegotiator struct. It contains... + [aPrefLang] + the array of strings. each string is the name of + languages ("ja", "ko"...), given by web browser. + [nPrefLang] + the number of the languages in aPrefLang. + [lOriginalLang] + == "en": indicates what language the default(original) files + are written with. +**************************************************************** */ +typedef char lnstring[LN_LNAME_LENGTH + 1]; +#define lnstrcpy(d,s) safe_strcpy((d),(s),sizeof(lnstring)-1) + +typedef struct tagLNNegotiator +{ + lnstring aPrefLang[LN_PREFLANG_MAX]; + int nPrefLang; + lnstring lOriginalLang; +}LNNegotiator; + +/* ************************************************************** + * some access functions & macros for LNNegotiator struct. + * ************************************************************ */ +#define ln_getPreflangCount(pLn) ((pLn)->nPrefLang) +#define ln_getOriginalLang(pLn) ((pLn)->lOriginalLang) +#define ln_getDefaultPrefLang(pLn) ((pLn)->lDefaultPrefLang) + +/* make it inline-expanded (or macro) to get better performance */ +static const char* ln_getPreflang(LNNegotiator* pLn, int i) +{ + rassert(i == LN_LANGDESC_DEFAULT + || (0 <= i && i < ln_getPreflangCount(pLn))); + + if(i == LN_LANGDESC_DEFAULT) + return NULL; + if(0 <= i && i < ln_getPreflangCount(pLn)) + return pLn->aPrefLang[i]; + return NULL; +} +/* initialize structures */ +static void ln_resetln(LNNegotiator* pLn) +{ + pLn->nPrefLang = 0; + /* using fixed memory.*/ +} +static BOOL ln_addPreflang(LNNegotiator* pLn, const char* pLang) +{ + int nPref = ln_getPreflangCount(pLn); + + if(nPref >= LN_PREFLANG_MAX) + return False; + + lnstrcpy(pLn->aPrefLang[nPref], pLang); + (pLn->nPrefLang)++; + return True; +} +static void ln_initln_help(LNNegotiator* pLn) +{ + ln_resetln(pLn); + lnstrcpy(pLn->lOriginalLang, I18N_ORIGINAL_LANG); + /* I18N_ORIGINAL_LANG = "en" is hardcoded in + webintl.h. */ + if (I18N_DEFAULT_PREF_LANG[0] != '\0') + ln_addPreflang(pLn, I18N_DEFAULT_PREF_LANG); + + /* this entry is used only when web browser didn't send + ACCEPT-LANGUAGE header. */ +} +/* **************************************************************** + * store acceptable languages into LNNegotiator object. + * [pstrLangarray] The arguments of "accept-language" http header, + * which is like "en-GB, es;q=0.5, ja". "q=0.5" is called quality value, + * but it is ignored now. wiled card "*" is also ignored. + ***************************************************************** */ +static BOOL ln_negotiate_language_help( LNNegotiator* pLn, const char* pstrLangarray ) +{ + char* pToken; + const char* pDelim = " \n\r\t,;"; + pstring strBuffer; + + rassert(pstrLangarray); + rassert(pLn); + + ln_resetln(pLn); + pstrcpy(strBuffer, pstrLangarray); + pToken = strtok(strBuffer, pDelim); + while(pToken != NULL) + { + if(strncmp(pToken, "q=", strlen("q=")) == 0) + { + pToken = strtok(NULL, pDelim); + continue; + } + if(!ln_addPreflang(pLn, pToken)) + break; + pToken = strtok(NULL, pDelim); + } + rassert(ln_getPreflangCount(pLn) != 0); + return (ln_getPreflangCount(pLn) != 0); +} +/* parse catalog file header and get encoding information.*/ +static BOOL parse_po_header(const char* pheader, pstring pencoding_name) +{ + const char *ap_i_v = "Project-Id-Version:"; + const char *acharset = "charset="; + char* penc; + int nenc; + + if(pencoding_name == NULL) return False; + if(pheader == NULL || *pheader == '\0') + { + /* error or catalog is not available. */ + pstrcpy(pencoding_name,""); + return False; + } + penc = strstr(pheader, acharset); + if(strncmp(pheader, ap_i_v, strlen(ap_i_v)) != 0 || penc == NULL) + { + /* catalog file exists, but header is not good.*/ + pstrcpy(pencoding_name, ""); + return True; + } + nenc = strcspn(penc + strlen(acharset), "\n"); + strncpy(pencoding_name, + penc + strlen(acharset), nenc); + return True; +} +/* ad-hoc mime charset -> samba encoding name converter. + character conversion is done when internal samba data, + such as paramters, open files, share names, are going to be displayed. + it is only valid for japanese encodings because samba-2.0.7 only has + these three character convertors. + so other .po file(catalog file) should be encoded with one which + samba can deal with (i.e same as DOS codepage). + + display-time conversion is deleted on this version because + all catalog files are encoded with samba internal encoding (DOS codepage). + + THIS FUNCTION is ALREADY obsolated and maybe removed soon, -- monyo +*/ +#define LN_SAMBA_ENCODINGS 3 +static const char* get_samba_enc(const char* penc) +{ + int i; + static const fstring fdefault = ""; + static const fstring fmimeenc[LN_SAMBA_ENCODINGS] = + { + "EUC-JP", "Shift_JIS", "ISO-2022-JP" + }; + static const fstring fsambaenc[LN_SAMBA_ENCODINGS] = + { + "euc", "sjis", "jis" + }; + for(i = 0; i < LN_SAMBA_ENCODINGS; i++) + { + if(strcasecmp(penc, fmimeenc[i]) == 0) + return fsambaenc[i]; + } + return fdefault; +} +/* ************************************************************ + find a better language. + if the language specified by web browser matches to a language + which is supported by the swat server, this function returns it. + *********************************************************** */ +static void set_a_language(const char* planguage) +{ + /* included gettext source is affected by + these env.variables without locale settings. + */ + /* + putenv(env) will not duplicate env argument + but smbw_setenv() does this. + */ + FILE *file; + smbw_setenv("LANGUAGE", planguage); + smbw_setenv("LANG", planguage); + bindtextdomain(I18N_PACKAGE, I18N_LOCALEDIR); + textdomain(I18N_PACKAGE); +} +static int ln_set_pref_language(LNNegotiator* pLn) +{ + int j; + pstring enc_name; + + for(j = 0; j < ln_getPreflangCount(pLn); j++) + { + set_a_language(ln_getPreflang(pLn, j)); + /* then check for _("") special entry which has + a lot of information about .po file. */ + if(parse_po_header(_(""), enc_name)) + { + /* the catalog file must exist and may have + encoding information .*/ + /* + but in this version, catalog files must be + written with samba-internal encoding (i.e. + dos encoding, dos codepage) + so there is no need to convert. + //ln_init_swat_encoding(get_samba_enc(enc_name)); + ln_init_swat_encoding(enc_name); + */ + return j; + } + } + return LN_NO_AVAILABLE_LANG; + /* no available or return the default? */ +} +/* ************************************************************** + initialize gettext. Before this, cgi_setup() should be done. + cgi_setup() calls ln_negotiate_language() if the user specifies + languages in web browser. Then, ln_set_pref_language() will work. + ************************************************************* */ +static BOOL ln_init_lang_env_help(LNNegotiator* pLn) +{ +#if I18N_GETTEXT + int nLang; + + nLang = ln_set_pref_language(pLn); + rstrace(getenv("LANGUAGE")); +#endif /* I18N_GETTEXT */ + return True; +} +/* ***************************************************************** + * This function searches for the "PrefLang" version of pFile. + * if not available, returns pFile. + * [pFile] the filename. + * [pst] the address of a struct. it will be filled with the information + * of the file. + * [pLangDesc] The address of an integer. a value which indicates the + * language of the returned value is written to the address. the value + * is used in ln_get_lang(). + * [return value] address of the name of the language version of the file. + * It is static object so it will be destroyed at the time ln_get_pref_file() + * is called. + **************************************************************** */ +static void ln_make_filename( pstring afname, const char* pFile, const char* pAdd ) +{ +#if LANG_PREFIX + /* LANG_PREFIX is already undefined, maybe removed soon */ + /* maybe, foo.html.ja */ + pstrcpy(afname, pFile); + pstrcat(afname, "."); + pstrcat(afname, pAdd); +#else + /* maybe, lang/ja/foo.html */ + pstrcpy(afname, "lang/"); + pstrcat(afname, pAdd); + pstrcat(afname, "/"); + pstrcat(afname, pFile); +#endif +} +static const char* ln_get_pref_file_help( + LNNegotiator* pLn, const char* pFile, + SMB_STRUCT_STAT* pst, int* pLangDesc) +{ + static pstring afname; + int i; + + for(i = 0; i < ln_getPreflangCount(pLn); i++) + { + if(strcmp(ln_getPreflang(pLn, i), ln_getOriginalLang(pLn)) + == 0) + break; + ln_make_filename(afname, pFile, ln_getPreflang(pLn, i)); + if(file_exist(afname, pst)) + { + *pLangDesc = i; + return afname; + } + } + pstrcpy(afname, pFile); + file_exist(afname, pst); + *pLangDesc = LN_LANGDESC_DEFAULT; + return afname; +} +/* ******************************************************************* + * file scope variables. this variable is not locked. + * (not multithread-safe) + ******************************************************************** */ +static LNNegotiator lnLanguagenegotiator; + +/* ******************************************************************* + * interfaces to the outside of this file. + ******************************************************************** */ +void ln_initln(void) +{ + ln_initln_help(&lnLanguagenegotiator); +} +BOOL ln_init_lang_env(void) +{ + return ln_init_lang_env_help(&lnLanguagenegotiator); +} +const char* ln_get_lang(int nLangDesc) +{ + return ln_getPreflang(&lnLanguagenegotiator, nLangDesc); +} +const char* ln_get_pref_file(const char* pFile, + SMB_STRUCT_STAT* pst, int* pLangDesc) +{ + return ln_get_pref_file_help( + &lnLanguagenegotiator, pFile, pst, pLangDesc); +} +BOOL ln_negotiate_language(const char* pstrLangarray) +{ + return ln_negotiate_language_help( + &lnLanguagenegotiator, pstrLangarray); +} +const char* ln_get_pref_file_n_o(const char* pFile) +{ + SMB_STRUCT_STAT st; + int nLangDesc; + return ln_get_pref_file(pFile, &st, &nLangDesc); +} +#endif /* I18N_SWAT */ -- cgit From 8cec5cf35f17568009c70d37bb8b2a1f360d3422 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Oct 2001 08:40:42 +0000 Subject: first step in converting the head branch to use lang_tdb.c instead of gettext for internationalisation support. There is more to do (This used to be commit ab7f67677a1ade4669e5c2750d0a38422ea616a9) --- source3/web/neg_lang.c | 107 ------------------------------------------------- 1 file changed, 107 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 8cb41a34ec..32f52aa473 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -161,114 +161,7 @@ static BOOL ln_negotiate_language_help( LNNegotiator* pLn, const char* pstrLanga rassert(ln_getPreflangCount(pLn) != 0); return (ln_getPreflangCount(pLn) != 0); } -/* parse catalog file header and get encoding information.*/ -static BOOL parse_po_header(const char* pheader, pstring pencoding_name) -{ - const char *ap_i_v = "Project-Id-Version:"; - const char *acharset = "charset="; - char* penc; - int nenc; - - if(pencoding_name == NULL) return False; - if(pheader == NULL || *pheader == '\0') - { - /* error or catalog is not available. */ - pstrcpy(pencoding_name,""); - return False; - } - penc = strstr(pheader, acharset); - if(strncmp(pheader, ap_i_v, strlen(ap_i_v)) != 0 || penc == NULL) - { - /* catalog file exists, but header is not good.*/ - pstrcpy(pencoding_name, ""); - return True; - } - nenc = strcspn(penc + strlen(acharset), "\n"); - strncpy(pencoding_name, - penc + strlen(acharset), nenc); - return True; -} -/* ad-hoc mime charset -> samba encoding name converter. - character conversion is done when internal samba data, - such as paramters, open files, share names, are going to be displayed. - it is only valid for japanese encodings because samba-2.0.7 only has - these three character convertors. - so other .po file(catalog file) should be encoded with one which - samba can deal with (i.e same as DOS codepage). - display-time conversion is deleted on this version because - all catalog files are encoded with samba internal encoding (DOS codepage). - - THIS FUNCTION is ALREADY obsolated and maybe removed soon, -- monyo -*/ -#define LN_SAMBA_ENCODINGS 3 -static const char* get_samba_enc(const char* penc) -{ - int i; - static const fstring fdefault = ""; - static const fstring fmimeenc[LN_SAMBA_ENCODINGS] = - { - "EUC-JP", "Shift_JIS", "ISO-2022-JP" - }; - static const fstring fsambaenc[LN_SAMBA_ENCODINGS] = - { - "euc", "sjis", "jis" - }; - for(i = 0; i < LN_SAMBA_ENCODINGS; i++) - { - if(strcasecmp(penc, fmimeenc[i]) == 0) - return fsambaenc[i]; - } - return fdefault; -} -/* ************************************************************ - find a better language. - if the language specified by web browser matches to a language - which is supported by the swat server, this function returns it. - *********************************************************** */ -static void set_a_language(const char* planguage) -{ - /* included gettext source is affected by - these env.variables without locale settings. - */ - /* - putenv(env) will not duplicate env argument - but smbw_setenv() does this. - */ - FILE *file; - smbw_setenv("LANGUAGE", planguage); - smbw_setenv("LANG", planguage); - bindtextdomain(I18N_PACKAGE, I18N_LOCALEDIR); - textdomain(I18N_PACKAGE); -} -static int ln_set_pref_language(LNNegotiator* pLn) -{ - int j; - pstring enc_name; - - for(j = 0; j < ln_getPreflangCount(pLn); j++) - { - set_a_language(ln_getPreflang(pLn, j)); - /* then check for _("") special entry which has - a lot of information about .po file. */ - if(parse_po_header(_(""), enc_name)) - { - /* the catalog file must exist and may have - encoding information .*/ - /* - but in this version, catalog files must be - written with samba-internal encoding (i.e. - dos encoding, dos codepage) - so there is no need to convert. - //ln_init_swat_encoding(get_samba_enc(enc_name)); - ln_init_swat_encoding(enc_name); - */ - return j; - } - } - return LN_NO_AVAILABLE_LANG; - /* no available or return the default? */ -} /* ************************************************************** initialize gettext. Before this, cgi_setup() should be done. cgi_setup() calls ln_negotiate_language() if the user specifies -- cgit From a689b24db14436ab1faa2f2f79b9f27b777b1fdb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 14 Oct 2001 12:10:29 +0000 Subject: the next step in the intl changeover. This should get us compiling agian, and also completes the switch to lang_tdb.c. SWAT should now work with a po file in the lib/ directory also removed useless SYSLOG defines in many files (This used to be commit 5296b20ad85d7519c870768455cb4d8df048c55a) --- source3/web/neg_lang.c | 274 +++++++------------------------------------------ 1 file changed, 35 insertions(+), 239 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 32f52aa473..8a5b60d99f 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -1,7 +1,7 @@ /* Unix SMB/Netbios implementation. - Version 1.9. - Samba Web Administration Tool + Version 3.0 + SWAT language handling 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 @@ -21,251 +21,47 @@ */ #include "includes.h" -/* #include "config.h" */ -#include "webintl.h" -#if I18N_SWAT -/* constants. */ -/* it is ok to make them bigger.*/ -#define LN_PREFLANG_MAX 10 -#define LN_LNAME_LENGTH 8+1+8 - -#define LN_DEFAULT_LANG I18N_DEFAULT_LANG -#define LN_LANGDESC_DEFAULT -1 -#define LN_NO_AVAILABLE_LANG -1 - -/* ****************************************************************** - * macros for debugging. - ***************************************************************** */ -#ifdef LN_R_NODEBUG - -#else /* - *#define LN_DEBUG_LOG "/tmp/lndebug.log" - *void ln_debug_error(const char *info, int nLine) - *{ - * FILE* fp; - * fp = sys_fopen(LN_DEBUG_LOG, "a"); - * fprintf(fp, "%s at %d.\n", info, nLine); - * fclose(fp); - *} - *void rassert_help(BOOL b, int l) - *{ - * if(!b) - * { - * ln_debug_error("language negotiation error.", l); - * exit(1); - * } - *} - */ -#endif /* LN_R_NODEBUG */ - -/* **************************************************************** - LNNegotiator struct. It contains... - [aPrefLang] - the array of strings. each string is the name of - languages ("ja", "ko"...), given by web browser. - [nPrefLang] - the number of the languages in aPrefLang. - [lOriginalLang] - == "en": indicates what language the default(original) files - are written with. -**************************************************************** */ -typedef char lnstring[LN_LNAME_LENGTH + 1]; -#define lnstrcpy(d,s) safe_strcpy((d),(s),sizeof(lnstring)-1) - -typedef struct tagLNNegotiator -{ - lnstring aPrefLang[LN_PREFLANG_MAX]; - int nPrefLang; - lnstring lOriginalLang; -}LNNegotiator; - -/* ************************************************************** - * some access functions & macros for LNNegotiator struct. - * ************************************************************ */ -#define ln_getPreflangCount(pLn) ((pLn)->nPrefLang) -#define ln_getOriginalLang(pLn) ((pLn)->lOriginalLang) -#define ln_getDefaultPrefLang(pLn) ((pLn)->lDefaultPrefLang) - -/* make it inline-expanded (or macro) to get better performance */ -static const char* ln_getPreflang(LNNegotiator* pLn, int i) -{ - rassert(i == LN_LANGDESC_DEFAULT - || (0 <= i && i < ln_getPreflangCount(pLn))); - - if(i == LN_LANGDESC_DEFAULT) - return NULL; - if(0 <= i && i < ln_getPreflangCount(pLn)) - return pLn->aPrefLang[i]; - return NULL; -} -/* initialize structures */ -static void ln_resetln(LNNegotiator* pLn) -{ - pLn->nPrefLang = 0; - /* using fixed memory.*/ -} -static BOOL ln_addPreflang(LNNegotiator* pLn, const char* pLang) -{ - int nPref = ln_getPreflangCount(pLn); - - if(nPref >= LN_PREFLANG_MAX) - return False; - - lnstrcpy(pLn->aPrefLang[nPref], pLang); - (pLn->nPrefLang)++; - return True; -} -static void ln_initln_help(LNNegotiator* pLn) -{ - ln_resetln(pLn); - lnstrcpy(pLn->lOriginalLang, I18N_ORIGINAL_LANG); - /* I18N_ORIGINAL_LANG = "en" is hardcoded in - webintl.h. */ - if (I18N_DEFAULT_PREF_LANG[0] != '\0') - ln_addPreflang(pLn, I18N_DEFAULT_PREF_LANG); - - /* this entry is used only when web browser didn't send - ACCEPT-LANGUAGE header. */ -} -/* **************************************************************** - * store acceptable languages into LNNegotiator object. - * [pstrLangarray] The arguments of "accept-language" http header, - * which is like "en-GB, es;q=0.5, ja". "q=0.5" is called quality value, - * but it is ignored now. wiled card "*" is also ignored. - ***************************************************************** */ -static BOOL ln_negotiate_language_help( LNNegotiator* pLn, const char* pstrLangarray ) + 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) { - char* pToken; - const char* pDelim = " \n\r\t,;"; - pstring strBuffer; - - rassert(pstrLangarray); - rassert(pLn); - - ln_resetln(pLn); - pstrcpy(strBuffer, pstrLangarray); - pToken = strtok(strBuffer, pDelim); - while(pToken != NULL) - { - if(strncmp(pToken, "q=", strlen("q=")) == 0) - { - pToken = strtok(NULL, pDelim); - continue; + char *p = NULL; + char *lang = lang_tdb_current(); + int fd; + if (lang) { + asprintf(&p, "lang/%s/%s", lang, fname); + if (p) { + fd = sys_open(p, flags, mode); + free(p); + if (fd != -1) { + return fd; + } } - if(!ln_addPreflang(pLn, pToken)) - break; - pToken = strtok(NULL, pDelim); } - rassert(ln_getPreflangCount(pLn) != 0); - return (ln_getPreflangCount(pLn) != 0); -} - -/* ************************************************************** - initialize gettext. Before this, cgi_setup() should be done. - cgi_setup() calls ln_negotiate_language() if the user specifies - languages in web browser. Then, ln_set_pref_language() will work. - ************************************************************* */ -static BOOL ln_init_lang_env_help(LNNegotiator* pLn) -{ -#if I18N_GETTEXT - int nLang; - nLang = ln_set_pref_language(pLn); - rstrace(getenv("LANGUAGE")); -#endif /* I18N_GETTEXT */ - return True; + /* fall through to default name */ + return sys_open(fname, flags, mode); } -/* ***************************************************************** - * This function searches for the "PrefLang" version of pFile. - * if not available, returns pFile. - * [pFile] the filename. - * [pst] the address of a struct. it will be filled with the information - * of the file. - * [pLangDesc] The address of an integer. a value which indicates the - * language of the returned value is written to the address. the value - * is used in ln_get_lang(). - * [return value] address of the name of the language version of the file. - * It is static object so it will be destroyed at the time ln_get_pref_file() - * is called. - **************************************************************** */ -static void ln_make_filename( pstring afname, const char* pFile, const char* pAdd ) -{ -#if LANG_PREFIX - /* LANG_PREFIX is already undefined, maybe removed soon */ - /* maybe, foo.html.ja */ - pstrcpy(afname, pFile); - pstrcat(afname, "."); - pstrcat(afname, pAdd); -#else - /* maybe, lang/ja/foo.html */ - pstrcpy(afname, "lang/"); - pstrcat(afname, pAdd); - pstrcat(afname, "/"); - pstrcat(afname, pFile); -#endif -} -static const char* ln_get_pref_file_help( - LNNegotiator* pLn, const char* pFile, - SMB_STRUCT_STAT* pst, int* pLangDesc) -{ - static pstring afname; - int i; - for(i = 0; i < ln_getPreflangCount(pLn); i++) - { - if(strcmp(ln_getPreflang(pLn, i), ln_getOriginalLang(pLn)) - == 0) - break; - ln_make_filename(afname, pFile, ln_getPreflang(pLn, i)); - if(file_exist(afname, pst)) - { - *pLangDesc = i; - return afname; - } - } - pstrcpy(afname, pFile); - file_exist(afname, pst); - *pLangDesc = LN_LANGDESC_DEFAULT; - return afname; -} -/* ******************************************************************* - * file scope variables. this variable is not locked. - * (not multithread-safe) - ******************************************************************** */ -static LNNegotiator lnLanguagenegotiator; -/* ******************************************************************* - * interfaces to the outside of this file. - ******************************************************************** */ -void ln_initln(void) -{ - ln_initln_help(&lnLanguagenegotiator); -} -BOOL ln_init_lang_env(void) -{ - return ln_init_lang_env_help(&lnLanguagenegotiator); -} -const char* ln_get_lang(int nLangDesc) -{ - return ln_getPreflang(&lnLanguagenegotiator, nLangDesc); -} -const char* ln_get_pref_file(const char* pFile, - SMB_STRUCT_STAT* pst, int* pLangDesc) -{ - return ln_get_pref_file_help( - &lnLanguagenegotiator, pFile, pst, pLangDesc); -} -BOOL ln_negotiate_language(const char* pstrLangarray) -{ - return ln_negotiate_language_help( - &lnLanguagenegotiator, pstrLangarray); -} -const char* ln_get_pref_file_n_o(const char* pFile) +/* + choose from a list of languages. The list can be comma or space + separated + Keep choosing until we get a hit +*/ +void web_set_lang(const char *lang_list) { - SMB_STRUCT_STAT st; - int nLangDesc; - return ln_get_pref_file(pFile, &st, &nLangDesc); + fstring lang; + char *p = (char *)lang_list; + + while (next_token(&p, lang, ", \t\r\n", sizeof(lang))) { + if (lang_tdb_init(lang)) return; + } + + /* it's not an error to not initialise - we just fall back to + the default */ } -#endif /* I18N_SWAT */ -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/web/neg_lang.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 8a5b60d99f..fc115bfd61 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. SWAT language handling This program is free software; you can redistribute it and/or modify -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/web/neg_lang.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index fc115bfd61..88bc5498e9 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "../web/swat_proto.h" /* during a file download we first check to see if there is a language -- cgit From fcbb06414d2c8385ce4e68f23905a528c8fbd4e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 14:34:48 +0000 Subject: sync 3.0 branch with HEAD (This used to be commit d53d77cc8e21dfbfd376d529661ef299e14e31a0) --- source3/web/neg_lang.c | 62 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 88bc5498e9..da974f78a4 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -48,20 +48,70 @@ int web_open(const char *fname, int flags, mode_t mode) } +struct pri_list { + float pri; + char *string; +}; + +static int qsort_cmp_list(const void *x, const void *y) { + struct pri_list *a = (struct pri_list *)x; + struct pri_list *b = (struct pri_list *)y; + if (a->pri > b->pri) return -1; + if (a->pri == b->pri) return 0; + return 1; +} + /* choose from a list of languages. The list can be comma or space separated Keep choosing until we get a hit + Changed to habdle priority -- Simo */ -void web_set_lang(const char *lang_list) + +void web_set_lang(const char *lang_string) { - fstring lang; - char *p = (char *)lang_list; + char **lang_list, **count; + struct pri_list *pl; + int lang_num, i; + + /* build the lang list */ + lang_list = str_list_make(lang_string, ", \t\r\n"); + if (!lang_list) return; - while (next_token(&p, lang, ", \t\r\n", sizeof(lang))) { - if (lang_tdb_init(lang)) return; + /* sort the list by priority */ + lang_num = 0; + count = lang_list; + while (*count && **count) { + count++; + lang_num++; } - + pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num); + 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; + } + pl[i].string = strdup(lang_list[i]); + } + str_list_free(&lang_list); + + qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list); + /* it's not an error to not initialise - we just fall back to the default */ + + 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; } -- cgit From b4cf9e95059071df49b34ff8574e48cb96f42da1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/web/neg_lang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index da974f78a4..aa285745d6 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "../web/swat_proto.h" +#include "web/swat_proto.h" /* during a file download we first check to see if there is a language -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/web/neg_lang.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index aa285745d6..ca671822d8 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -85,7 +85,7 @@ void web_set_lang(const char *lang_string) count++; lang_num++; } - pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num); + pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num); for (i = 0; i < lang_num; i++) { char *pri_code; if ((pri_code=strstr(lang_list[i], ";q="))) { @@ -95,7 +95,7 @@ void web_set_lang(const char *lang_string) } else { pl[i].pri = 1; } - pl[i].string = strdup(lang_list[i]); + pl[i].string = SMB_STRDUP(lang_list[i]); } str_list_free(&lang_list); -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- source3/web/neg_lang.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index ca671822d8..cc2924afde 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -54,8 +54,8 @@ struct pri_list { }; static int qsort_cmp_list(const void *x, const void *y) { - struct pri_list *a = (struct pri_list *)x; - struct pri_list *b = (struct pri_list *)y; + struct pri_list *a = CONST_DISCARD(struct pri_list *, x); + struct pri_list *b = CONST_DISCARD(struct pri_list *, y); if (a->pri > b->pri) return -1; if (a->pri == b->pri) return 0; return 1; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/web/neg_lang.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index cc2924afde..ca671822d8 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -54,8 +54,8 @@ struct pri_list { }; static int qsort_cmp_list(const void *x, const void *y) { - struct pri_list *a = CONST_DISCARD(struct pri_list *, x); - struct pri_list *b = CONST_DISCARD(struct pri_list *, y); + struct pri_list *a = (struct pri_list *)x; + struct pri_list *b = (struct pri_list *)y; if (a->pri > b->pri) return -1; if (a->pri == b->pri) return 0; return 1; -- cgit From 9f4c335401e5e34f290295c0b36e193d0b0f43ff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 01:59:04 +0000 Subject: r16597: Klocwork #2006. Fix possible null deref. Jeremy. (This used to be commit 9b73385d6b90c7806d8ccfc1f2354ede761fad61) --- source3/web/neg_lang.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index ca671822d8..fb79f41f13 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -86,6 +86,10 @@ void web_set_lang(const char *lang_string) lang_num++; } pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num); + if (!pl) { + return; + } + for (i = 0; i < lang_num; i++) { char *pri_code; if ((pri_code=strstr(lang_list[i], ";q="))) { -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/web/neg_lang.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index fb79f41f13..207614655d 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -57,8 +57,8 @@ static int qsort_cmp_list(const void *x, const void *y) { struct pri_list *a = (struct pri_list *)x; struct pri_list *b = (struct pri_list *)y; if (a->pri > b->pri) return -1; - if (a->pri == b->pri) return 0; - return 1; + if (a->pri < b->pri) return 1; + return 0; } /* -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/web/neg_lang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 207614655d..3142491051 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -4,7 +4,7 @@ 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 - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/web/neg_lang.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index 3142491051..bb481306e7 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -13,8 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . Created by Ryo Kawahara */ -- cgit From 2762b9a97582b9b28fd5985ba8e3d0299126820e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 4 Feb 2008 20:57:35 +0100 Subject: Always pass a TALLOC_CTX to str_list_make and str_list_copy (This used to be commit e2c9fc4cf5f0ff725330fa44f53782db65fca37e) --- source3/web/neg_lang.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/neg_lang.c') diff --git a/source3/web/neg_lang.c b/source3/web/neg_lang.c index bb481306e7..82411000cd 100644 --- a/source3/web/neg_lang.c +++ b/source3/web/neg_lang.c @@ -74,7 +74,7 @@ void web_set_lang(const char *lang_string) int lang_num, i; /* build the lang list */ - lang_list = str_list_make(lang_string, ", \t\r\n"); + lang_list = str_list_make(talloc_tos(), lang_string, ", \t\r\n"); if (!lang_list) return; /* sort the list by priority */ @@ -100,7 +100,7 @@ void web_set_lang(const char *lang_string) } pl[i].string = SMB_STRDUP(lang_list[i]); } - str_list_free(&lang_list); + TALLOC_FREE(lang_list); qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list); -- cgit