From 5573a1c7394362f5e46c58b8cfaf6bf7a080c391 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Sep 2001 14:14:57 +0000 Subject: added "display charset" option in smb.conf, along with d_printf() which should now be used instead of DEBUG(0) or printf() for interactive messages I have only converted client.c to use d_printf(), and the code hasn't had much testing yet. Eventually we want all interactive code to use d_printf(), plus SWAT (This used to be commit 266d8e67669adb329f25676c4bc4d4c50f223428) --- source3/lib/charcnv.c | 95 ++++++++++++++++++++++++++++----------------- source3/lib/dprintf.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ source3/lib/iconv.c | 4 +- 3 files changed, 167 insertions(+), 36 deletions(-) create mode 100644 source3/lib/dprintf.c (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 9bbb8a8507..ebcceef816 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -26,32 +26,56 @@ extern int DEBUGLEVEL; static pstring cvtbuf; -static smb_iconv_t - ucs2_to_unix=(smb_iconv_t)-1, /*ucs2 (MS) <-> unix format */ - unix_to_ucs2=(smb_iconv_t)-1, - dos_to_unix=(smb_iconv_t)-1, /*unix format <-> dos codepage*/ - unix_to_dos=(smb_iconv_t)-1; /*for those clients who does not support unicode*/ +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; + +/**************************************************************************** +return the name of a charset to give to iconv() +****************************************************************************/ +static char *charset_name(charset_t ch) +{ + char *ret = NULL; + + if (ch == CH_UCS2) ret = "UCS-2LE"; + else if (ch == CH_UNIX) ret = lp_unix_charset(); + else if (ch == CH_DOS) ret = lp_dos_charset(); + else if (ch == CH_DISPLAY) ret = lp_display_charset(); + + if (!ret || !*ret) ret = "ASCII"; + return ret; +} /**************************************************************************** Initialize iconv conversion descriptors ****************************************************************************/ -void init_iconv(char *unix_charset, char *dos_charset) +void init_iconv(void) { -#define ICONV(descr, from_name, to_name)\ - if(descr!=(smb_iconv_t)-1) smb_iconv_close(descr);\ - descr = smb_iconv_open(to_name, from_name);\ - if(descr==(smb_iconv_t)-1)\ - DEBUG(0,("Conversion from %s to %s is not supported\n",from_name,to_name)); - - if (!unix_charset || !*unix_charset) unix_charset = "ASCII"; - if (!dos_charset || !*dos_charset) dos_charset = "ASCII"; + int c1, c2; + + /* so that charset_name() works we need to get the UNIX<->UCS2 going + first */ + if (!conv_handles[CH_UNIX][CH_UCS2]) { + conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open("UCS-2LE", "ASCII"); + } + if (!conv_handles[CH_UCS2][CH_UNIX]) { + conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", "UCS-2LE"); + } - ICONV(ucs2_to_unix, "UCS-2LE", unix_charset) - ICONV(unix_to_ucs2, unix_charset, "UCS-2LE") - ICONV(dos_to_unix, dos_charset, unix_charset) - ICONV(unix_to_dos, unix_charset, dos_charset) -#undef ICONV + for (c1=0;c1= maxlen) { + /* it didn't fit - try a larger buffer */ + maxlen *= 2; + free(p2); + goto again; + } + + /* good, its converted OK */ + free(p); + ret = fwrite(p2, 1, clen, f); + free(p2); + + return ret; +} + + +int d_fprintf(FILE *f, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = d_vfprintf(f, format, ap); + va_end(ap); + + return ret; +} + +static FILE *outfile; + +int d_printf(const char *format, ...) +{ + int ret; + va_list ap; + + if (!outfile) outfile = stdout; + + va_start(ap, format); + ret = d_vfprintf(outfile, format, ap); + va_end(ap); + + return ret; +} + +/* interactive programs need a way of tell d_*() to write to stderr instead + of stdout */ +void display_set_stderr(void) +{ + outfile = stderr; +} diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 2285d8debf..46507dd624 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -142,12 +142,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) if (!charsets[from].name) { ret->pull = sys_iconv; ret->cd_pull = iconv_open("UCS-2LE", fromcode); - if (!ret->cd_pull) goto failed; + if (ret->cd_pull == (iconv_t)-1) goto failed; } if (!charsets[to].name) { ret->push = sys_iconv; ret->cd_push = iconv_open(tocode, "UCS-2LE"); - if (!ret->cd_push) goto failed; + if (ret->cd_push == (iconv_t)-1) goto failed; } #else if (!charsets[from].name || !charsets[to].name) { -- cgit