mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
r26315: Avoid using lp_ functions in libcharset.
This commit is contained in:
parent
aa98a1781c
commit
db6dd425e3
@ -42,11 +42,10 @@ struct smb_iconv_convenience {
|
|||||||
const char *unix_charset;
|
const char *unix_charset;
|
||||||
const char *dos_charset;
|
const char *dos_charset;
|
||||||
const char *display_charset;
|
const char *display_charset;
|
||||||
|
bool native_iconv;
|
||||||
smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
|
smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct smb_iconv_convenience *global_smb_iconv_convenience = NULL;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the name of a charset to give to iconv().
|
* Return the name of a charset to give to iconv().
|
||||||
@ -86,32 +85,28 @@ static int close_iconv(struct smb_iconv_convenience *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
|
struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx,
|
||||||
struct loadparm_context *lp_ctx)
|
const char *dos_charset,
|
||||||
|
const char *unix_charset,
|
||||||
|
const char *display_charset,
|
||||||
|
bool native_iconv)
|
||||||
{
|
{
|
||||||
struct smb_iconv_convenience *ret = talloc_zero(mem_ctx,
|
struct smb_iconv_convenience *ret = talloc_zero(mem_ctx,
|
||||||
struct smb_iconv_convenience);
|
struct smb_iconv_convenience);
|
||||||
|
|
||||||
|
if (ret == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
talloc_set_destructor(ret, close_iconv);
|
talloc_set_destructor(ret, close_iconv);
|
||||||
|
|
||||||
ret->display_charset = talloc_strdup(ret, lp_display_charset(lp_ctx));
|
ret->dos_charset = talloc_strdup(ret, dos_charset);
|
||||||
ret->dos_charset = talloc_strdup(ret, lp_dos_charset(lp_ctx));
|
ret->unix_charset = talloc_strdup(ret, unix_charset);
|
||||||
ret->unix_charset = talloc_strdup(ret, lp_unix_charset(lp_ctx));
|
ret->display_charset = talloc_strdup(ret, display_charset);
|
||||||
|
ret->native_iconv = native_iconv;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_PUBLIC_ void reload_charcnv(void)
|
|
||||||
{
|
|
||||||
talloc_free(global_smb_iconv_convenience);
|
|
||||||
global_smb_iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), global_loadparm);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void free_global_smb_iconv_convenience(void)
|
|
||||||
{
|
|
||||||
talloc_free(global_smb_iconv_convenience);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
on-demand initialisation of conversion handles
|
on-demand initialisation of conversion handles
|
||||||
*/
|
*/
|
||||||
@ -120,8 +115,7 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
|
|||||||
{
|
{
|
||||||
const char *n1, *n2;
|
const char *n1, *n2;
|
||||||
static int initialised;
|
static int initialised;
|
||||||
/* auto-free iconv memory on exit so valgrind reports are easier
|
|
||||||
to look at */
|
|
||||||
if (initialised == 0) {
|
if (initialised == 0) {
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
@ -134,7 +128,6 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
|
|||||||
*/
|
*/
|
||||||
setlocale(LC_ALL, "C");
|
setlocale(LC_ALL, "C");
|
||||||
#endif
|
#endif
|
||||||
atexit(free_global_smb_iconv_convenience);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ic->conv_handles[from][to]) {
|
if (ic->conv_handles[from][to]) {
|
||||||
@ -144,7 +137,7 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
|
|||||||
n1 = charset_name(ic, from);
|
n1 = charset_name(ic, from);
|
||||||
n2 = charset_name(ic, to);
|
n2 = charset_name(ic, to);
|
||||||
|
|
||||||
ic->conv_handles[from][to] = smb_iconv_open(n2,n1);
|
ic->conv_handles[from][to] = smb_iconv_open(n2, n1, ic->native_iconv);
|
||||||
|
|
||||||
if (ic->conv_handles[from][to] == (smb_iconv_t)-1) {
|
if (ic->conv_handles[from][to] == (smb_iconv_t)-1) {
|
||||||
if ((from == CH_DOS || to == CH_DOS) &&
|
if ((from == CH_DOS || to == CH_DOS) &&
|
||||||
@ -156,7 +149,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic,
|
|||||||
n1 = charset_name(ic, from);
|
n1 = charset_name(ic, from);
|
||||||
n2 = charset_name(ic, to);
|
n2 = charset_name(ic, to);
|
||||||
|
|
||||||
ic->conv_handles[from][to] = smb_iconv_open(n2,n1);
|
ic->conv_handles[from][to] = smb_iconv_open(n2, n1,
|
||||||
|
ic->native_iconv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,8 @@ static bool is_utf16(const char *name)
|
|||||||
/*
|
/*
|
||||||
simple iconv_open() wrapper
|
simple iconv_open() wrapper
|
||||||
*/
|
*/
|
||||||
smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
|
smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode,
|
||||||
|
bool native_iconv)
|
||||||
{
|
{
|
||||||
smb_iconv_t ret;
|
smb_iconv_t ret;
|
||||||
const struct charset_functions *from=NULL, *to=NULL;
|
const struct charset_functions *from=NULL, *to=NULL;
|
||||||
@ -199,7 +200,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_NATIVE_ICONV
|
#ifdef HAVE_NATIVE_ICONV
|
||||||
if ((!from || !to) && !lp_parm_bool(global_loadparm, NULL, "iconv", "native", true)) {
|
if ((!from || !to) && !native_iconv) {
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (!from) {
|
if (!from) {
|
||||||
|
@ -157,8 +157,8 @@ static bool test_buffer(struct torture_context *test,
|
|||||||
"failed to open %s to UTF-16LE",
|
"failed to open %s to UTF-16LE",
|
||||||
charset));
|
charset));
|
||||||
}
|
}
|
||||||
cd2 = smb_iconv_open(charset, "UTF-16LE");
|
cd2 = smb_iconv_open(charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
|
||||||
cd3 = smb_iconv_open("UTF-16LE", charset);
|
cd3 = smb_iconv_open("UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true));
|
||||||
last_charset = charset;
|
last_charset = charset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,5 +64,6 @@ struct loadparm_service;
|
|||||||
|
|
||||||
extern struct loadparm_context *global_loadparm;
|
extern struct loadparm_context *global_loadparm;
|
||||||
extern struct loadparm_service sDefault;
|
extern struct loadparm_service sDefault;
|
||||||
|
extern struct smb_iconv_convenience *global_smb_iconv_convenience;
|
||||||
|
|
||||||
#endif /* _PARAM_H */
|
#endif /* _PARAM_H */
|
||||||
|
@ -283,3 +283,19 @@ _PUBLIC_ const char *lp_messaging_path(TALLOC_CTX *mem_ctx,
|
|||||||
return smbd_tmp_path(mem_ctx, lp_ctx, "messaging");
|
return smbd_tmp_path(mem_ctx, lp_ctx, "messaging");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct smb_iconv_convenience *global_smb_iconv_convenience = NULL;
|
||||||
|
|
||||||
|
struct smb_iconv_convenience *smb_iconv_convenience_init_lp(TALLOC_CTX *mem_ctx,
|
||||||
|
struct loadparm_context *lp_ctx)
|
||||||
|
{
|
||||||
|
return smb_iconv_convenience_init(mem_ctx, lp_dos_charset(lp_ctx),
|
||||||
|
lp_unix_charset(lp_ctx),
|
||||||
|
lp_display_charset(lp_ctx),
|
||||||
|
lp_parm_bool(lp_ctx, NULL, "iconv", "native", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
_PUBLIC_ void reload_charcnv(void)
|
||||||
|
{
|
||||||
|
talloc_free(global_smb_iconv_convenience);
|
||||||
|
global_smb_iconv_convenience = smb_iconv_convenience_init_lp(talloc_autofree_context(), global_loadparm);
|
||||||
|
}
|
||||||
|
@ -205,7 +205,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cd = smb_iconv_open(to, from);
|
cd = smb_iconv_open(to, from, lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true));
|
||||||
if((int)cd == -1) {
|
if((int)cd == -1) {
|
||||||
DEBUG(0,("unable to find from or to encoding, exiting...\n"));
|
DEBUG(0,("unable to find from or to encoding, exiting...\n"));
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user