From 6243e2a30414ef059fe2fd3636563269f4b12d06 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 4 Aug 2005 23:56:18 +0000 Subject: r9078: - move charset stuff to lib/charset - don't use the global $LIBS variable for -liconv as $LIBS is not used anymore should fix the build on solaris 10 metze (This used to be commit 69ade058fde8e4cc62e4830c0b080e720d8e581d) --- source4/lib/charset/charcnv.c | 723 ++++++++++++++++++++++++++++++++++++++++++ source4/lib/charset/config.m4 | 65 ++++ source4/lib/charset/config.mk | 10 + source4/lib/charset/iconv.c | 693 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1491 insertions(+) create mode 100644 source4/lib/charset/charcnv.c create mode 100644 source4/lib/charset/config.m4 create mode 100644 source4/lib/charset/config.mk create mode 100644 source4/lib/charset/iconv.c (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c new file mode 100644 index 0000000000..e632790155 --- /dev/null +++ b/source4/lib/charset/charcnv.c @@ -0,0 +1,723 @@ +/* + Unix SMB/CIFS implementation. + Character set conversion Extensions + Copyright (C) Igor Vergeichik 2001 + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Simo Sorce 2001 + + 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. + +*/ +#include "includes.h" +#include "system/iconv.h" +#include "pstring.h" + +/** + * @file + * + * @brief Character-set conversion routines built on our iconv. + * + * @note Samba's internal character set (at least in the 3.0 series) + * is always the same as the one for the Unix filesystem. It is + * not necessarily UTF-8 and may be different on machines that + * need i18n filenames to be compatible with Unix software. It does + * have to be a superset of ASCII. All multibyte sequences must start + * with a byte with the high bit set. + * + * @sa lib/iconv.c + */ + +/** + * Return the name of a charset to give to iconv(). + **/ +static const char *charset_name(charset_t ch) +{ + const char *ret = NULL; + + if (ch == CH_UTF16) ret = "UTF-16LE"; + 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(); + else if (ch == CH_UTF8) ret = "UTF8"; + else if (ch == CH_UTF16BE) ret = "UTF-16BE"; + + if (!ret || !*ret) ret = "ASCII"; + return ret; +} + +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; + +/** + re-initialize iconv conversion descriptors +**/ +void init_iconv(void) +{ + charset_t c1, c2; + for (c1=0;c1 + *
STR_TERMINATE
means include the null termination
+ *
STR_UPPER
means uppercase in the destination
+ * + * + * @param dest_len the maximum length in bytes allowed in the + * destination. If @p dest_len is -1 then no maximum is used. + **/ +ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) +{ + size_t src_len; + ssize_t ret; + + if (flags & STR_UPPER) { + char *tmpbuf = strupper_talloc(NULL, src); + if (tmpbuf == NULL) { + return -1; + } + ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + talloc_free(tmpbuf); + return ret; + } + + /* treat a pstring as "unlimited" length */ + if (dest_len == (size_t)-1) + dest_len = sizeof(pstring); + + src_len = strlen(src); + + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) + src_len++; + + return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); +} + +/** + * Copy a string from a unix char* src to an ASCII destination, + * allocating a buffer using talloc(). + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. + **/ +ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest); +} + + +/** + * Copy a string from a dos codepage source to a unix char* destination. + * + * The resulting string in "dest" is always null terminated. + * + * @param flags can have: + *
+ *
STR_TERMINATE
+ *
STR_TERMINATE means the string in @p src + * is null terminated, and src_len is ignored.
+ *
+ * + * @param src_len is the length of the source area in bytes. + * @returns the number of bytes occupied by the string in @p src. + **/ +ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + size_t ret; + + if (dest_len == (size_t)-1) + dest_len = sizeof(pstring); + + if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { + if (src_len == (size_t)-1) { + src_len = strlen(src) + 1; + } else { + size_t len = strnlen(src, src_len); + if (len < src_len) + len++; + src_len = len; + } + } + + ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); + + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; + + return src_len; +} + +/** + * Copy a string from a char* src to a unicode destination. + * + * @returns the number of bytes occupied by the string in the destination. + * + * @param flags can have: + * + *
+ *
STR_TERMINATE
means include the null termination. + *
STR_UPPER
means uppercase in the destination. + *
STR_NOALIGN
means don't do alignment. + *
+ * + * @param dest_len is the maximum length allowed in the + * destination. If dest_len is -1 then no maxiumum is used. + **/ +ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) +{ + size_t len=0; + size_t src_len = strlen(src); + size_t ret; + + if (flags & STR_UPPER) { + char *tmpbuf = strupper_talloc(NULL, src); + if (tmpbuf == NULL) { + return -1; + } + ret = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + talloc_free(tmpbuf); + return ret; + } + + /* treat a pstring as "unlimited" length */ + if (dest_len == (size_t)-1) + dest_len = sizeof(pstring); + + if (flags & STR_TERMINATE) + src_len++; + + if (ucs2_align(NULL, dest, flags)) { + *(char *)dest = 0; + dest = (void *)((char *)dest + 1); + if (dest_len) dest_len--; + len++; + } + + /* ucs2 is always a multiple of 2 bytes */ + dest_len &= ~1; + + ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); + if (ret == (size_t)-1) { + return 0; + } + + len += ret; + + return len; +} + + +/** + * Copy a string from a unix char* src to a UCS2 destination, + * allocating a buffer using talloc(). + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + * or -1 in case of error. + **/ +ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest); +} + + +/** + * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + + *dest = NULL; + return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); +} + +/** + Copy a string from a ucs2 source to a unix char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_NOALIGN means don't try to align. + if STR_TERMINATE is set then src_len is ignored if it is -1. + src_len is the length of the source area in bytes + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. +**/ + +size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + size_t ret; + + if (dest_len == (size_t)-1) + dest_len = sizeof(pstring); + + if (ucs2_align(NULL, src, flags)) { + src = (const void *)((const char *)src + 1); + if (src_len > 0) + src_len--; + } + + if (flags & STR_TERMINATE) { + if (src_len == (size_t)-1) { + src_len = utf16_len(src); + } else { + src_len = utf16_len_n(src, src_len); + } + } + + /* ucs2 is always a multiple of 2 bytes */ + if (src_len != (size_t)-1) + src_len &= ~1; + + ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); + if (dest_len) + dest[MIN(ret, dest_len-1)] = 0; + + return src_len; +} + +/** + * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) +{ + size_t src_len = utf16_len(src); + *dest = NULL; + return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); +} + +/** + * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); +} + +/** + Copy a string from a char* src to a unicode or ascii + dos codepage destination choosing unicode or ascii based on the + flags in the SMB buffer starting at base_ptr. + Return the number of bytes occupied by the string in the destination. + flags can have: + STR_TERMINATE means include the null termination. + STR_UPPER means uppercase in the destination. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + dest_len is the maximum length allowed in the destination. If dest_len + is -1 then no maxiumum is used. +**/ + +ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags) +{ + if (flags & STR_ASCII) { + return push_ascii(dest, src, dest_len, flags); + } else if (flags & STR_UNICODE) { + return push_ucs2(dest, src, dest_len, flags); + } else { + smb_panic("push_string requires either STR_ASCII or STR_UNICODE flag to be set"); + return -1; + } +} + + +/** + Copy a string from a unicode or ascii source (depending on + the packet flags) to a char* destination. + Flags can have: + STR_TERMINATE means the string in src is null terminated. + STR_UNICODE means to force as unicode. + STR_ASCII use ascii even with unicode packet. + STR_NOALIGN means don't do alignment. + if STR_TERMINATE is set then src_len is ignored is it is -1 + src_len is the length of the source area in bytes. + Return the number of bytes occupied by the string in src. + The resulting string in "dest" is always null terminated. +**/ + +ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +{ + if (flags & STR_ASCII) { + return pull_ascii(dest, src, dest_len, src_len, flags); + } else if (flags & STR_UNICODE) { + return pull_ucs2(dest, src, dest_len, src_len, flags); + } else { + smb_panic("pull_string requires either STR_ASCII or STR_UNICODE flag to be set"); + return -1; + } +} + + +/* + return the unicode codepoint for the next multi-byte CH_UNIX character + in the string + + also return the number of bytes consumed (which tells the caller + how many bytes to skip to get to the next CH_UNIX character) + + return INVALID_CODEPOINT if the next character cannot be converted +*/ +codepoint_t next_codepoint(const char *str, size_t *size) +{ + /* it cannot occupy more than 4 bytes in UTF16 format */ + uint8_t buf[4]; + smb_iconv_t descriptor; + size_t ilen_orig; + size_t ilen; + size_t olen; + char *outbuf; + + if ((str[0] & 0x80) == 0) { + *size = 1; + return (codepoint_t)str[0]; + } + + /* we assume that no multi-byte character can take + more than 5 bytes. This is OK as we only + support codepoints up to 1M */ + ilen_orig = strnlen(str, 5); + ilen = ilen_orig; + + descriptor = get_conv_handle(CH_UNIX, CH_UTF16); + if (descriptor == (smb_iconv_t)-1) { + *size = 1; + return INVALID_CODEPOINT; + } + + /* this looks a little strange, but it is needed to cope + with codepoints above 64k */ + olen = 2; + outbuf = buf; + smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); + if (olen == 2) { + olen = 4; + outbuf = buf; + smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); + if (olen == 4) { + /* we didn't convert any bytes */ + *size = 1; + return INVALID_CODEPOINT; + } + olen = 4 - olen; + } else { + olen = 2 - olen; + } + + *size = ilen_orig - ilen; + + if (olen == 2) { + return (codepoint_t)SVAL(buf, 0); + } + if (olen == 4) { + /* decode a 4 byte UTF16 character manually */ + return (codepoint_t)0x10000 + + (buf[2] | ((buf[3] & 0x3)<<8) | + (buf[0]<<10) | ((buf[1] & 0x3)<<18)); + } + + /* no other length is valid */ + return INVALID_CODEPOINT; +} + +/* + push a single codepoint into a CH_UNIX string the target string must + be able to hold the full character, which is guaranteed if it is at + least 5 bytes in size. The caller may pass less than 5 bytes if they + are sure the character will fit (for example, you can assume that + uppercase/lowercase of a character will not add more than 1 byte) + + return the number of bytes occupied by the CH_UNIX character, or + -1 on failure +*/ +ssize_t push_codepoint(char *str, codepoint_t c) +{ + smb_iconv_t descriptor; + uint8_t buf[4]; + size_t ilen, olen; + const char *inbuf; + + if (c < 128) { + *str = c; + return 1; + } + + descriptor = get_conv_handle(CH_UTF16, CH_UNIX); + if (descriptor == (smb_iconv_t)-1) { + return -1; + } + + if (c < 0x10000) { + ilen = 2; + olen = 5; + inbuf = buf; + SSVAL(buf, 0, c); + smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); + if (ilen != 0) { + return -1; + } + return 5 - olen; + } + + c -= 0x10000; + + buf[0] = (c>>10) & 0xFF; + buf[1] = (c>>18) | 0xd8; + buf[2] = c & 0xFF; + buf[3] = ((c>>8) & 0x3) | 0xdc; + + ilen = 4; + olen = 5; + inbuf = buf; + + smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); + if (ilen != 0) { + return -1; + } + return 5 - olen; +} diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 new file mode 100644 index 0000000000..9812c356ff --- /dev/null +++ b/source4/lib/charset/config.m4 @@ -0,0 +1,65 @@ +dnl # ICONV/CHARSET subsystem + +ICONV_LOCATION=standard +LOOK_DIRS="/usr /usr/local /sw" +AC_ARG_WITH(libiconv, +[ --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto) ], +[ + if test "$withval" = "no" ; then + AC_MSG_ERROR(I won't take no for an answer) + else + if test "$withval" != "yes" ; then + LOOK_DIRS="$withval $LOOK_DIRS" + fi + fi +]) + +ICONV_FOUND="no" +for i in $LOOK_DIRS ; do + save_LIBS=$LIBS + save_LDFLAGS=$LDFLAGS + save_CPPFLAGS=$CPPFLAGS + CPPFLAGS="-I$i/include" + LDFLAGS="-L$i/lib" + LIBS= + export LDFLAGS LIBS CPPFLAGS +dnl Try to find iconv(3) + jm_ICONV($i) + + TMP_ICONV_LIBS="$LIBS" + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + export LDFLAGS LIBS CPPFLAGS + + if test -n "$ICONV_FOUND" ; then + LIB_ADD_DIR(ICONV_LDFLAGS, $i/lib) + CFLAGS_ADD_DIR(ICONV_CPPFLAGS, $i/include) + ICONV_LIBS="$TMP_ICONV_LIBS" + break + fi +done + +############ +# check for iconv in libc +AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[ +AC_TRY_RUN([ +#include +main() { + iconv_t cd = iconv_open("ASCII", "UCS-2LE"); + if (cd == 0 || cd == (iconv_t)-1) return -1; + return 0; +} +], +samba_cv_HAVE_NATIVE_ICONV=yes,samba_cv_HAVE_NATIVE_ICONV=no,samba_cv_HAVE_NATIVE_ICONV=cross)]) +if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then + AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv]) +fi + +if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then + AC_MSG_WARN([Sufficient support for iconv function was not found. + Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!]) +fi + +SMB_EXT_LIB(ICONV,[${ICONV_LIBS}],[${ICONV_CFLAGS}],[${ICONV_CPPFLAGS}],[${ICONV_LDFLAGS}]) diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk new file mode 100644 index 0000000000..6b0fe02b72 --- /dev/null +++ b/source4/lib/charset/config.mk @@ -0,0 +1,10 @@ +################################################ +# Start SUBSYSTEM CHARSET +[SUBSYSTEM::CHARSET] +INIT_OBJ_FILES = \ + lib/charset/iconv.o +ADD_OBJ_FILES = \ + lib/charset/charcnv.o +REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV +# End SUBSYSTEM CHARSET +################################################ diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c new file mode 100644 index 0000000000..df590444e5 --- /dev/null +++ b/source4/lib/charset/iconv.c @@ -0,0 +1,693 @@ +/* + Unix SMB/CIFS implementation. + minimal iconv implementation + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2002 + + 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. +*/ + +#include "includes.h" +#include "dlinklist.h" +#include "system/iconv.h" +#include "system/filesys.h" + + +/** + * @file + * + * @brief Samba wrapper/stub for iconv character set conversion. + * + * iconv is the XPG2 interface for converting between character + * encodings. This file provides a Samba wrapper around it, and also + * a simple reimplementation that is used if the system does not + * implement iconv. + * + * Samba only works with encodings that are supersets of ASCII: ascii + * characters like whitespace can be tested for directly, multibyte + * sequences start with a byte with the high bit set, and strings are + * terminated by a nul byte. + * + * Note that the only function provided by iconv is conversion between + * characters. It doesn't directly support operations like + * uppercasing or comparison. We have to convert to UTF-16LE and + * compare there. + * + * @sa Samba Developers Guide + **/ + +static size_t ascii_pull (void *,const char **, size_t *, char **, size_t *); +static size_t ascii_push (void *,const char **, size_t *, char **, size_t *); +static size_t utf8_pull (void *,const char **, size_t *, char **, size_t *); +static size_t utf8_push (void *,const char **, size_t *, char **, size_t *); +static size_t ucs2hex_pull(void *,const char **, size_t *, char **, size_t *); +static size_t ucs2hex_push(void *,const char **, size_t *, char **, size_t *); +static size_t iconv_copy (void *,const char **, size_t *, char **, size_t *); +static size_t iconv_swab (void *,const char **, size_t *, char **, size_t *); + +static const struct charset_functions builtin_functions[] = { + /* windows is closest to UTF-16 */ + {"UCS-2LE", iconv_copy, iconv_copy}, + {"UTF-16LE", iconv_copy, iconv_copy}, + {"UCS-2BE", iconv_swab, iconv_swab}, + {"UTF-16BE", iconv_swab, iconv_swab}, + + /* we include the UTF-8 alias to cope with differing locale settings */ + {"UTF8", utf8_pull, utf8_push}, + {"UTF-8", utf8_pull, utf8_push}, + {"ASCII", ascii_pull, ascii_push}, + {"UCS2-HEX", ucs2hex_pull, ucs2hex_push} +}; + +static struct charset_functions *charsets = NULL; + +NTSTATUS charset_register_backend(const void *_funcs) +{ + struct charset_functions *funcs = memdup(_funcs,sizeof(struct charset_functions)); + struct charset_functions *c = charsets; + + /* Check whether we already have this charset... */ + while(c) { + if(!strcasecmp(c->name, funcs->name)){ + DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); + return NT_STATUS_OBJECT_NAME_COLLISION; + } + c = c->next; + } + + funcs->next = funcs->prev = NULL; + DLIST_ADD(charsets, funcs); + return NT_STATUS_OK; +} + +#ifdef HAVE_NATIVE_ICONV +/* if there was an error then reset the internal state, + this ensures that we don't have a shift state remaining for + character sets like SJIS */ +static size_t sys_iconv(void *cd, + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + size_t ret = iconv((iconv_t)cd, + discard_const_p(char *, inbuf), inbytesleft, + outbuf, outbytesleft); + if (ret == (size_t)-1) iconv(cd, NULL, NULL, NULL, NULL); + return ret; +} +#endif + +/** + * This is a simple portable iconv() implementaion. + * + * It only knows about a very small number of character sets - just + * enough that Samba works on systems that don't have iconv. + **/ +size_t smb_iconv(smb_iconv_t cd, + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + char cvtbuf[2048]; + size_t bufsize; + + /* in many cases we can go direct */ + if (cd->direct) { + return cd->direct(cd->cd_direct, + inbuf, inbytesleft, outbuf, outbytesleft); + } + + + /* otherwise we have to do it chunks at a time */ + while (*inbytesleft > 0) { + char *bufp1 = cvtbuf; + const char *bufp2 = cvtbuf; + + bufsize = sizeof(cvtbuf); + + if (cd->pull(cd->cd_pull, + inbuf, inbytesleft, &bufp1, &bufsize) == -1 + && errno != E2BIG) return -1; + + bufsize = sizeof(cvtbuf) - bufsize; + + if (cd->push(cd->cd_push, + &bufp2, &bufsize, + outbuf, outbytesleft) == -1) return -1; + } + + return 0; +} + +static BOOL is_utf16(const char *name) +{ + return strcasecmp(name, "UCS-2LE") == 0 || + strcasecmp(name, "UTF-16LE") == 0; +} + +/* + simple iconv_open() wrapper + */ +smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) +{ + smb_iconv_t ret; + const struct charset_functions *from=NULL, *to=NULL; + int i; + + ret = (smb_iconv_t)talloc_named(NULL, sizeof(*ret), + "iconv(%s,%s)", tocode, fromcode); + if (!ret) { + errno = ENOMEM; + return (smb_iconv_t)-1; + } + memset(ret, 0, sizeof(*ret)); + + /* check for the simplest null conversion */ + if (strcmp(fromcode, tocode) == 0) { + ret->direct = iconv_copy; + return ret; + } + + for (i=0;inext) { + if (strcasecmp(from->name, fromcode) == 0) break; + } + } + + if (to == NULL) { + for (to=charsets; to; to=to->next) { + if (strcasecmp(to->name, tocode) == 0) break; + } + } + +#ifdef HAVE_NATIVE_ICONV + if (!from) { + ret->pull = sys_iconv; + ret->cd_pull = iconv_open("UTF-16LE", fromcode); + if (ret->cd_pull == (iconv_t)-1) + ret->cd_pull = iconv_open("UCS-2LE", fromcode); + if (ret->cd_pull == (iconv_t)-1) goto failed; + } + + if (!to) { + ret->push = sys_iconv; + ret->cd_push = iconv_open(tocode, "UTF-16LE"); + if (ret->cd_push == (iconv_t)-1) + ret->cd_push = iconv_open(tocode, "UCS-2LE"); + if (ret->cd_push == (iconv_t)-1) goto failed; + } +#else + if (!from || !to) { + goto failed; + } +#endif + + /* check for conversion to/from ucs2 */ + if (is_utf16(fromcode) && to) { + ret->direct = to->push; + return ret; + } + if (is_utf16(tocode) && from) { + ret->direct = from->pull; + return ret; + } + +#ifdef HAVE_NATIVE_ICONV + if (is_utf16(fromcode)) { + ret->direct = sys_iconv; + ret->cd_direct = ret->cd_push; + ret->cd_push = NULL; + return ret; + } + if (is_utf16(tocode)) { + ret->direct = sys_iconv; + ret->cd_direct = ret->cd_pull; + ret->cd_pull = NULL; + return ret; + } +#endif + + /* the general case has to go via a buffer */ + if (!ret->pull) ret->pull = from->pull; + if (!ret->push) ret->push = to->push; + return ret; + +failed: + talloc_free(ret); + errno = EINVAL; + return (smb_iconv_t)-1; +} + +/* + simple iconv_close() wrapper +*/ +int smb_iconv_close(smb_iconv_t cd) +{ +#ifdef HAVE_NATIVE_ICONV + if (cd->cd_direct) iconv_close((iconv_t)cd->cd_direct); + if (cd->cd_pull) iconv_close((iconv_t)cd->cd_pull); + if (cd->cd_push) iconv_close((iconv_t)cd->cd_push); +#endif + + talloc_free(cd); + return 0; +} + + +/********************************************************************** + the following functions implement the builtin character sets in Samba + and also the "test" character sets that are designed to test + multi-byte character set support for english users +***********************************************************************/ +static size_t ascii_pull(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[1] = 0; + (*inbytesleft) -= 1; + (*outbytesleft) -= 2; + (*inbuf) += 1; + (*outbuf) += 2; + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t ascii_push(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int ir_count=0; + + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + (*outbuf)[0] = (*inbuf)[0] & 0x7F; + if ((*inbuf)[1]) ir_count++; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return ir_count; +} + + +static size_t ucs2hex_pull(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 1 && *outbytesleft >= 2) { + uint_t v; + + if ((*inbuf)[0] != '@') { + /* seven bit ascii case */ + (*outbuf)[0] = (*inbuf)[0]; + (*outbuf)[1] = 0; + (*inbytesleft) -= 1; + (*outbytesleft) -= 2; + (*inbuf) += 1; + (*outbuf) += 2; + continue; + } + /* it's a hex character */ + if (*inbytesleft < 5) { + errno = EINVAL; + return -1; + } + + if (sscanf(&(*inbuf)[1], "%04x", &v) != 1) { + errno = EILSEQ; + return -1; + } + + (*outbuf)[0] = v&0xff; + (*outbuf)[1] = v>>8; + (*inbytesleft) -= 5; + (*outbytesleft) -= 2; + (*inbuf) += 5; + (*outbuf) += 2; + } + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t ucs2hex_push(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + while (*inbytesleft >= 2 && *outbytesleft >= 1) { + char buf[6]; + + if ((*inbuf)[1] == 0 && + ((*inbuf)[0] & 0x80) == 0 && + (*inbuf)[0] != '@') { + (*outbuf)[0] = (*inbuf)[0]; + (*inbytesleft) -= 2; + (*outbytesleft) -= 1; + (*inbuf) += 2; + (*outbuf) += 1; + continue; + } + if (*outbytesleft < 5) { + errno = E2BIG; + return -1; + } + snprintf(buf, 6, "@%04x", SVAL(*inbuf, 0)); + memcpy(*outbuf, buf, 5); + (*inbytesleft) -= 2; + (*outbytesleft) -= 5; + (*inbuf) += 2; + (*outbuf) += 5; + } + + if (*inbytesleft == 1) { + errno = EINVAL; + return -1; + } + + if (*inbytesleft > 1) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t iconv_swab(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int n; + + n = MIN(*inbytesleft, *outbytesleft); + + swab(*inbuf, *outbuf, (n&~1)); + if (n&1) { + (*outbuf)[n-1] = 0; + } + + (*inbytesleft) -= n; + (*outbytesleft) -= n; + (*inbuf) += n; + (*outbuf) += n; + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + + +static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + int n; + + n = MIN(*inbytesleft, *outbytesleft); + + memmove(*outbuf, *inbuf, n); + + (*inbytesleft) -= n; + (*outbytesleft) -= n; + (*inbuf) += n; + (*outbuf) += n; + + if (*inbytesleft > 0) { + errno = E2BIG; + return -1; + } + + return 0; +} + +static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + size_t in_left=*inbytesleft, out_left=*outbytesleft; + const uint8_t *c = (const uint8_t *)*inbuf; + uint8_t *uc = (uint8_t *)*outbuf; + + while (in_left >= 1 && out_left >= 2) { + if ((c[0] & 0x80) == 0) { + uc[0] = c[0]; + uc[1] = 0; + c += 1; + in_left -= 1; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xe0) == 0xc0) { + if (in_left < 2 || + (c[1] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; + } + uc[1] = (c[0]>>2) & 0x7; + uc[0] = (c[0]<<6) | (c[1]&0x3f); + c += 2; + in_left -= 2; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xf0) == 0xe0) { + if (in_left < 3 || + (c[1] & 0xc0) != 0x80 || + (c[2] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; + } + uc[1] = ((c[0]&0xF)<<4) | ((c[1]>>2)&0xF); + uc[0] = (c[1]<<6) | (c[2]&0x3f); + c += 3; + in_left -= 3; + out_left -= 2; + uc += 2; + continue; + } + + if ((c[0] & 0xf8) == 0xf0) { + unsigned int codepoint; + if (in_left < 4 || + (c[1] & 0xc0) != 0x80 || + (c[2] & 0xc0) != 0x80 || + (c[3] & 0xc0) != 0x80) { + errno = EILSEQ; + goto error; + } + codepoint = + (c[3]&0x3f) | + ((c[2]&0x3f)<<6) | + ((c[1]&0x3f)<<12) | + ((c[0]&0x7)<<18); + if (codepoint < 0x10000) { + /* accept UTF-8 characters that are not + minimally packed, but pack the result */ + uc[0] = (codepoint & 0xFF); + uc[1] = (codepoint >> 8); + c += 4; + in_left -= 4; + out_left -= 2; + uc += 2; + continue; + } + + codepoint -= 0x10000; + + if (out_left < 4) { + errno = E2BIG; + goto error; + } + + uc[0] = (codepoint>>10) & 0xFF; + uc[1] = (codepoint>>18) | 0xd8; + uc[2] = codepoint & 0xFF; + uc[3] = ((codepoint>>8) & 0x3) | 0xdc; + c += 4; + in_left -= 4; + out_left -= 4; + uc += 4; + continue; + } + + /* we don't handle 5 byte sequences */ + errno = EINVAL; + goto error; + } + + if (in_left > 0) { + errno = E2BIG; + goto error; + } + + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = c; + *outbuf = uc; + return 0; + +error: + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = c; + *outbuf = uc; + return -1; +} + +static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + size_t in_left=*inbytesleft, out_left=*outbytesleft; + uint8_t *c = (uint8_t *)*outbuf; + const uint8_t *uc = (const uint8_t *)*inbuf; + + while (in_left >= 2 && out_left >= 1) { + unsigned int codepoint; + + if (uc[1] == 0 && !(uc[0] & 0x80)) { + /* simplest case */ + c[0] = uc[0]; + in_left -= 2; + out_left -= 1; + uc += 2; + c += 1; + continue; + } + + if ((uc[1]&0xf8) == 0) { + /* next simplest case */ + if (out_left < 2) { + errno = E2BIG; + goto error; + } + c[0] = 0xc0 | (uc[0]>>6) | (uc[1]<<2); + c[1] = 0x80 | (uc[0] & 0x3f); + in_left -= 2; + out_left -= 2; + uc += 2; + c += 2; + continue; + } + + if ((uc[1] & 0xfc) == 0xdc) { + /* its the second part of a 4 byte sequence. Illegal */ + if (in_left < 4) { + errno = EINVAL; + } else { + errno = EILSEQ; + } + goto error; + } + + if ((uc[1] & 0xfc) != 0xd8) { + codepoint = uc[0] | (uc[1]<<8); + if (out_left < 3) { + errno = E2BIG; + goto error; + } + c[0] = 0xe0 | (codepoint >> 12); + c[1] = 0x80 | ((codepoint >> 6) & 0x3f); + c[2] = 0x80 | (codepoint & 0x3f); + + in_left -= 2; + out_left -= 3; + uc += 2; + c += 3; + continue; + } + + /* its the first part of a 4 byte sequence */ + if (in_left < 4) { + errno = EINVAL; + goto error; + } + if ((uc[3] & 0xfc) != 0xdc) { + errno = EILSEQ; + goto error; + } + codepoint = 0x10000 + (uc[2] | ((uc[3] & 0x3)<<8) | + (uc[0]<<10) | ((uc[1] & 0x3)<<18)); + + if (out_left < 4) { + errno = E2BIG; + goto error; + } + c[0] = 0xf0 | (codepoint >> 18); + c[1] = 0x80 | ((codepoint >> 12) & 0x3f); + c[2] = 0x80 | ((codepoint >> 6) & 0x3f); + c[3] = 0x80 | (codepoint & 0x3f); + + in_left -= 4; + out_left -= 4; + uc += 4; + c += 4; + } + + if (in_left == 1) { + errno = EINVAL; + goto error; + } + + if (in_left > 1) { + errno = E2BIG; + goto error; + } + + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = uc; + *outbuf = c; + + return 0; + +error: + *inbytesleft = in_left; + *outbytesleft = out_left; + *inbuf = uc; + *outbuf = c; + return -1; +} + + + -- cgit From 523034b9fbc1841ed63137e3d8965d52997af4e6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 Sep 2005 19:19:10 +0000 Subject: r10323: Add first bits required for getting compile with scons working. This does not work yet and can exist parallel with the existing build system. (This used to be commit 829568d75985e875e3363d76fb44270a0298c7f8) --- source4/lib/charset/SConscript | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 source4/lib/charset/SConscript (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript new file mode 100644 index 0000000000..0b67bedb0f --- /dev/null +++ b/source4/lib/charset/SConscript @@ -0,0 +1,3 @@ +Import('hostenv') +charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c']) +Export('charset') -- cgit From 96745cbfc0e3386fa32631daa45b4096a1f80e61 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 19 Sep 2005 21:44:36 +0000 Subject: r10328: Add more emacs python-mode markers. (This used to be commit 540a3649e88690e829c17d79ecdccdc9ed464845) --- source4/lib/charset/SConscript | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 0b67bedb0f..d73d390309 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,3 +1,5 @@ +# tastes like -*- python -*- + Import('hostenv') charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c']) Export('charset') -- cgit From 069e498da2a03bd253a2fcf2b7ff13f266ab63b4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 Sep 2005 22:01:57 +0000 Subject: r10330: Add SConscript to more subsystems. Some of the tdb tools build now. Start on custom Samba scons tools (for handling proto generation, pidl, etc) (This used to be commit 4bffe4435944fffa3f9680b5a2fe63f2bdd98003) --- source4/lib/charset/SConscript | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index d73d390309..7d9044d547 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,5 +1,15 @@ +SConscript('../../build/scons/iconv.py') # tastes like -*- python -*- - Import('hostenv') -charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c']) + +#conf = Configure(hostenv, custom_tests = { 'CheckIconv' : CheckIconv }) +#(have_iconv,iconv) = conf.CheckIconv() +#conf.Finish() + +#if not have_iconv: +# print "Install iconv for better charset compatibility" + +iconv = [] + +charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c',iconv]) Export('charset') -- cgit From 6812c73534001d2dd05a9a74358d2b6d0029f1a7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 20 Sep 2005 11:59:03 +0000 Subject: r10348: Add scons scripts for remaining subsystems. Most subsystems build now, but final linking still fails (as does generating files asn1, et, idl and proto files) (This used to be commit 4f0d7f75b99c7f4388d8acb0838577d86baf68b5) --- source4/lib/charset/SConscript | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 7d9044d547..53e5db44bb 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,8 +1,8 @@ +Import('hostenv') SConscript('../../build/scons/iconv.py') # tastes like -*- python -*- -Import('hostenv') -#conf = Configure(hostenv, custom_tests = { 'CheckIconv' : CheckIconv }) +#conf = Configure( custom_tests = { 'CheckIconv' : CheckIconv }) #(have_iconv,iconv) = conf.CheckIconv() #conf.Finish() -- cgit From 4be0ae794e4af2354d678fddd7bf1e822ffa9148 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 23 Sep 2005 16:32:52 +0000 Subject: r10456: More SCons fixes: - Add framework for fallback generating code - Move pread / pwrite replacement functions to libreplace - Support pidl builds correctly - Support asn1 builds correctly - Move OS-specific checks to lib/replace/SConscript (This used to be commit fbbfad0a1f7dedbf48e835a864f8285f283d72f3) --- source4/lib/charset/SConscript | 92 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 8 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 53e5db44bb..b3305579e1 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,15 +1,91 @@ +#!/usr/bin/env python +# tastes like -*- python -*- + Import('hostenv') -SConscript('../../build/scons/iconv.py') -# tastes like -*- python -*- -#conf = Configure( custom_tests = { 'CheckIconv' : CheckIconv }) -#(have_iconv,iconv) = conf.CheckIconv() -#conf.Finish() +def _CheckIconvPath(context,path): + # Some systems have iconv in libc, some have it in libiconv (OSF/1 and + # those with the standalone portable libiconv installed). + context.Message("checking for iconv in " + path + " ... ") + + main = """ +int main() +{ + iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd); + return 0; +}""" + + have_giconv_iconv = context.TryLink(""" +#include +#include +""" + main, '.c') + if have_giconv_iconv: + context.Result(1) + return ("giconv.h", "") + + have_iconv_iconv = context.TryLink(""" +#include +#include +""" + main, '.c') + + if have_iconv_iconv: + context.Result(1) + return ("iconv.h", "") + + #FIXME: Add -lgiconv + have_giconv_lib_iconv = context.TryLink(""" +#include +#include +""" + main, '.c') + if have_giconv_lib_iconv: + context.Result(1) + return ("giconv.h", "-lgiconv") + + #FIXME: Add -liconv + have_iconv_lib_iconv = context.TryLink(""" +#include +#include +"""+main,'.c') + + if have_iconv_lib_iconv: + context.Result(1) + return ("iconv.h", "-liconv") + + return None + +def CheckIconv(context): + context.Message("checking for iconv ... ") + + look_dirs = ['/usr','/usr/local','/sw'] + + for p in look_dirs: + _CheckIconvPath(context,p) #FIXME: Handle return value + + if context.TryRun(""" +#include +main() { + iconv_t cd = iconv_open("ASCII", "UCS-2LE"); + if (cd == 0 || cd == (iconv_t)-1) return -1; + return 0; +} +""", '.c'): + context.Result(1) + return (1,[]) + + context.Result(0) + return (0,[]) -#if not have_iconv: -# print "Install iconv for better charset compatibility" +if hostenv['configure']: + conf = hostenv.Configure( custom_tests = { 'CheckIconv' : CheckIconv }) + (have_iconv,iconv) = conf.CheckIconv() + conf.Finish() -iconv = [] + if not have_iconv: + print "Install iconv for better charset compatibility" +else: + iconv = [] # FIXME charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c',iconv]) Export('charset') -- cgit From e337caeed1459f876449611ae1684616d0ea8f55 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 Sep 2005 15:15:50 +0000 Subject: r10509: Some more sconscript fixes. Now getting to link stage for smbclient (This used to be commit 6df956edbab7ad5e72b2f20e74ab0f0d62528932) --- source4/lib/charset/SConscript | 69 ++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 47 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index b3305579e1..5ef640d2dc 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -6,62 +6,39 @@ Import('hostenv') def _CheckIconvPath(context,path): # Some systems have iconv in libc, some have it in libiconv (OSF/1 and # those with the standalone portable libiconv installed). - context.Message("checking for iconv in " + path + " ... ") + if path: + context.Message("checking for iconv in " + path + " ... ") + context.env.Append(LIBPATH=path) + else: + context.Message("checking for iconv in default path ... ") + + for l in [None,'giconv','iconv']: + for h in ['giconv.h','iconv.h']: + if l: + context.env['LIBS'] = [l] + if context.TryLink(""" +#include +#include <%s> - main = """ int main() { iconv_t cd = iconv_open("",""); iconv(cd,NULL,NULL,NULL,NULL); iconv_close(cd); return 0; -}""" - - have_giconv_iconv = context.TryLink(""" -#include -#include -""" + main, '.c') - if have_giconv_iconv: - context.Result(1) - return ("giconv.h", "") - - have_iconv_iconv = context.TryLink(""" -#include -#include -""" + main, '.c') - - if have_iconv_iconv: - context.Result(1) - return ("iconv.h", "") - - #FIXME: Add -lgiconv - have_giconv_lib_iconv = context.TryLink(""" -#include -#include -""" + main, '.c') - if have_giconv_lib_iconv: - context.Result(1) - return ("giconv.h", "-lgiconv") - - #FIXME: Add -liconv - have_iconv_lib_iconv = context.TryLink(""" -#include -#include -"""+main,'.c') - - if have_iconv_lib_iconv: - context.Result(1) - return ("iconv.h", "-liconv") - - return None +}""" % h, '.c'): + context.Result(1) + return True + + context.Result(0) + return False def CheckIconv(context): - context.Message("checking for iconv ... ") - - look_dirs = ['/usr','/usr/local','/sw'] + look_dirs = [None, '/usr','/usr/local','/sw'] for p in look_dirs: - _CheckIconvPath(context,p) #FIXME: Handle return value + if _CheckIconvPath(context,p): + break if context.TryRun(""" #include @@ -71,10 +48,8 @@ main() { return 0; } """, '.c'): - context.Result(1) return (1,[]) - context.Result(0) return (0,[]) if hostenv['configure']: -- cgit From 5058f4b9e82ca8b9f2405930db3a46b8c37f06ed Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Sep 2005 18:18:09 +0000 Subject: r10586: Add MergedObject() builder. Default to Library() rather then StaticLibrary() (This used to be commit b53313dc517986c69a4e4cb8fe3885b696f8faa1) --- source4/lib/charset/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 5ef640d2dc..9bc474ff48 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -62,5 +62,5 @@ if hostenv['configure']: else: iconv = [] # FIXME -charset = hostenv.StaticLibrary('charset',['iconv.c','charcnv.c',iconv]) +charset = hostenv.Library('charset',['iconv.c','charcnv.c',iconv]) Export('charset') -- cgit From 2ecb46d595b880c533e2dafea43baf02f009bec6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 14 Oct 2005 12:54:52 +0000 Subject: r11037: (This used to be commit 6913e338405a5aca5c70cf6e022532c596ed0a36) --- source4/lib/charset/SConscript | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 9bc474ff48..15ee49909c 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,7 +1,6 @@ #!/usr/bin/env python # tastes like -*- python -*- -Import('hostenv') def _CheckIconvPath(context,path): # Some systems have iconv in libc, some have it in libiconv (OSF/1 and -- cgit From cffd522b5c806508dfacfb10234e4c0a115c0a98 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 14 Oct 2005 14:02:47 +0000 Subject: r11052: bring samba4 uptodate with the samba4-winsrepl branch, before the bad merge metze (This used to be commit 471c0ca4abb17fb5f73c0efed195c67628c1c06e) --- source4/lib/charset/SConscript | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript index 15ee49909c..9bc474ff48 100644 --- a/source4/lib/charset/SConscript +++ b/source4/lib/charset/SConscript @@ -1,6 +1,7 @@ #!/usr/bin/env python # tastes like -*- python -*- +Import('hostenv') def _CheckIconvPath(context,path): # Some systems have iconv in libc, some have it in libiconv (OSF/1 and -- cgit From f4d590662effeb80c2b55ae5ad869b4b7810cf08 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Oct 2005 10:04:57 +0000 Subject: r11214: Remove scons files (see http://lists.samba.org/archive/samba-technical/2005-October/043443.html) (This used to be commit 7fffc5c9178158249be632ac0ca179c13bd1f98f) --- source4/lib/charset/SConscript | 66 ------------------------------------------ 1 file changed, 66 deletions(-) delete mode 100644 source4/lib/charset/SConscript (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/SConscript b/source4/lib/charset/SConscript deleted file mode 100644 index 9bc474ff48..0000000000 --- a/source4/lib/charset/SConscript +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# tastes like -*- python -*- - -Import('hostenv') - -def _CheckIconvPath(context,path): - # Some systems have iconv in libc, some have it in libiconv (OSF/1 and - # those with the standalone portable libiconv installed). - if path: - context.Message("checking for iconv in " + path + " ... ") - context.env.Append(LIBPATH=path) - else: - context.Message("checking for iconv in default path ... ") - - for l in [None,'giconv','iconv']: - for h in ['giconv.h','iconv.h']: - if l: - context.env['LIBS'] = [l] - if context.TryLink(""" -#include -#include <%s> - -int main() -{ - iconv_t cd = iconv_open("",""); - iconv(cd,NULL,NULL,NULL,NULL); - iconv_close(cd); - return 0; -}""" % h, '.c'): - context.Result(1) - return True - - context.Result(0) - return False - -def CheckIconv(context): - look_dirs = [None, '/usr','/usr/local','/sw'] - - for p in look_dirs: - if _CheckIconvPath(context,p): - break - - if context.TryRun(""" -#include -main() { - iconv_t cd = iconv_open("ASCII", "UCS-2LE"); - if (cd == 0 || cd == (iconv_t)-1) return -1; - return 0; -} -""", '.c'): - return (1,[]) - - return (0,[]) - -if hostenv['configure']: - conf = hostenv.Configure( custom_tests = { 'CheckIconv' : CheckIconv }) - (have_iconv,iconv) = conf.CheckIconv() - conf.Finish() - - if not have_iconv: - print "Install iconv for better charset compatibility" -else: - iconv = [] # FIXME - -charset = hostenv.Library('charset',['iconv.c','charcnv.c',iconv]) -Export('charset') -- cgit From 4c5a4a7e0288e9ac0b2f795befd5684059e4c429 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 21 Oct 2005 16:29:54 +0000 Subject: r11244: Relative path names in .mk files (This used to be commit 24e10300906c380919d2d631bfb3b8fd6b3f54ba) --- source4/lib/charset/config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 6b0fe02b72..b61f9e7ea2 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -2,9 +2,9 @@ # Start SUBSYSTEM CHARSET [SUBSYSTEM::CHARSET] INIT_OBJ_FILES = \ - lib/charset/iconv.o + iconv.o ADD_OBJ_FILES = \ - lib/charset/charcnv.o + charcnv.o REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From d8e35f882879e189f55b3bca818dd44cc5f0c6fa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 26 Dec 2005 18:03:50 +0000 Subject: r12498: Eliminate INIT_OBJ_FILES and ADD_OBJ_FILES. We were not using the difference between these at all, and in the future the fact that INIT_OBJ_FILES include smb_build.h will be sufficient to have recompiles at the right time. (This used to be commit b24f2583edee38abafa58578d8b5c4b43e517def) --- source4/lib/charset/config.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index b61f9e7ea2..4fb8ee79bf 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -1,9 +1,8 @@ ################################################ # Start SUBSYSTEM CHARSET [SUBSYSTEM::CHARSET] -INIT_OBJ_FILES = \ - iconv.o -ADD_OBJ_FILES = \ +OBJ_FILES = \ + iconv.o \ charcnv.o REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV # End SUBSYSTEM CHARSET -- cgit From 78c50015bb8bd5a1d831a6e7ec796b3367c73145 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 3 Jan 2006 15:40:05 +0000 Subject: r12694: Move some headers to the directory of the subsystem they belong to. (This used to be commit c722f665c90103f3ed57621c460e32ad33e7a8a3) --- source4/lib/charset/charset.h | 69 +++++++++++++++++++++++++++++++++++++++++++ source4/lib/charset/config.mk | 1 + 2 files changed, 70 insertions(+) create mode 100644 source4/lib/charset/charset.h (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h new file mode 100644 index 0000000000..5ad2f431bf --- /dev/null +++ b/source4/lib/charset/charset.h @@ -0,0 +1,69 @@ +/* + Unix SMB/CIFS implementation. + charset defines + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2002 + + 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. +*/ + +/* this defines the charset types used in samba */ +typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; + +#define NUM_CHARSETS 6 + +/* + * for each charset we have a function that pulls from that charset to + * a ucs2 buffer, and a function that pushes to a ucs2 buffer + * */ + +struct charset_functions { + const char *name; + size_t (*pull)(void *, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + size_t (*push)(void *, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + struct charset_functions *prev, *next; +}; + +/* this type is used for manipulating unicode codepoints */ +typedef uint32_t codepoint_t; + +#define INVALID_CODEPOINT ((codepoint_t)-1) + + +/* generic iconv conversion structure */ +typedef struct { + size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + size_t (*push)(void *cd, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); + void *cd_direct, *cd_pull, *cd_push; +} *smb_iconv_t; + +/* string manipulation flags */ +#define STR_TERMINATE 1 +#define STR_UPPER 2 +#define STR_ASCII 4 +#define STR_UNICODE 8 +#define STR_NOALIGN 16 +#define STR_NO_RANGE_CHECK 32 +#define STR_LEN8BIT 64 +#define STR_TERMINATE_ASCII 128 /* only terminate if ascii */ +#define STR_LEN_NOTERM 256 /* the length field is the unterminated length */ + +#include "lib/charset/charset_proto.h" diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 4fb8ee79bf..a69bee1ec3 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -4,6 +4,7 @@ OBJ_FILES = \ iconv.o \ charcnv.o +PRIVATE_PROTO_HEADER = charset_proto.h REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From 7cc28a1c8b701b12ee735f267c194e52e44976df Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 27 Jan 2006 13:29:47 +0000 Subject: r13186: Remove assumption that callers that specify -1 actually mean sizeof(pstring) (This used to be commit da72f47226f9c514deb75bc6e69548c240822eb5) --- source4/lib/charset/charcnv.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index e632790155..6f07d78fb1 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -22,7 +22,6 @@ */ #include "includes.h" #include "system/iconv.h" -#include "pstring.h" /** * @file @@ -303,10 +302,6 @@ ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) return ret; } - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - src_len = strlen(src); if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) @@ -352,9 +347,6 @@ ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, { size_t ret; - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { if (src_len == (size_t)-1) { src_len = strlen(src) + 1; @@ -406,10 +398,6 @@ ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) return ret; } - /* treat a pstring as "unlimited" length */ - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - if (flags & STR_TERMINATE) src_len++; @@ -482,9 +470,6 @@ size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, i { size_t ret; - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - if (ucs2_align(NULL, src, flags)) { src = (const void *)((const char *)src + 1); if (src_len > 0) -- cgit From c71c86c52458eefae8a34774ec186c2837f473af Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:44:16 +0000 Subject: r13842: Make some more functions public. (This used to be commit aac1b99b362993352d80692afa55c38fc851c016) --- source4/lib/charset/charcnv.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 6f07d78fb1..a10a336fd2 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -61,7 +61,7 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /** re-initialize iconv conversion descriptors **/ -void init_iconv(void) +_PUBLIC_ void init_iconv(void) { charset_t c1, c2; for (c1=0;c1 Date: Wed, 15 Mar 2006 05:49:45 +0000 Subject: r14429: charset_t cannot be used to loop over charset_t, as otherwise it can go out of the range of the enum (This used to be commit caead24b6dd2f2e87e113587cacd57794487a83a) --- source4/lib/charset/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index a10a336fd2..3ee8adf772 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -63,7 +63,7 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; **/ _PUBLIC_ void init_iconv(void) { - charset_t c1, c2; + unsigned c1, c2; for (c1=0;c1 Date: Thu, 16 Mar 2006 20:02:31 +0000 Subject: r14488: Install more headers. Generate different #include lines in pidl depending on whether we're building inside or outside of the Samba tree (useful for 3rd-party projects). (This used to be commit 0c188833154c1fe565cb1735909e408a4a1a6049) --- source4/lib/charset/charset.h | 5 +++++ source4/lib/charset/config.mk | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 5ad2f431bf..df67aebb55 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -19,6 +19,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef __CHARSET_H__ +#define __CHARSET_H__ + /* this defines the charset types used in samba */ typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; @@ -67,3 +70,5 @@ typedef struct { #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */ #include "lib/charset/charset_proto.h" + +#endif /* __CHARSET_H__ */ diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index a69bee1ec3..5f423b3ba6 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -4,7 +4,8 @@ OBJ_FILES = \ iconv.o \ charcnv.o -PRIVATE_PROTO_HEADER = charset_proto.h +PUBLIC_HEADERS = charset.h +PUBLIC_PROTO_HEADER = charset_proto.h REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From 5b0051e0325aea7e46715aa61bba0a1dc025132c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 17 Mar 2006 13:55:10 +0000 Subject: r14511: Install more headers (This used to be commit e1f896948fad8cf5a1aec300865c250c5721ee7d) --- source4/lib/charset/charset.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index df67aebb55..629786ee95 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -22,6 +22,8 @@ #ifndef __CHARSET_H__ #define __CHARSET_H__ +#include "lib/talloc/talloc.h" + /* this defines the charset types used in samba */ typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; -- cgit From 64485f876152f27fb8052c7a1adc0c96f96a5009 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Apr 2006 02:01:35 +0000 Subject: r14902: change charcnv code to fail the conversion when it hits bad characters, rather than silently truncating the string. This makes the code much omre conservative, making it easier to test. It might mean users hit problems initially, but at least we'll hear about them, and thus can fix them. (This used to be commit bb99cbf069db5ab09ecf6c55e4c87d4c28ea8169) --- source4/lib/charset/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 3ee8adf772..d1d4561fa5 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -168,7 +168,7 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; - break; + return -1; case E2BIG: reason="No more room"; if (from == CH_UNIX) { @@ -181,10 +181,10 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, charset_name(from), charset_name(to), (int)srclen, (int)destlen)); } - break; + return -1; case EILSEQ: reason="Illegal multibyte sequence"; - break; + return -1; } /* smb_panic(reason); */ } -- cgit From 69b51f702af1ded825d5c17bdb97014cac12e752 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 15:47:59 +0000 Subject: r15207: Introduce PRIVATE_DEPENDENCIES and PUBLIC_DEPENDENCIES as replacement for REQUIRED_SUBSYSTEMS. (This used to be commit adc8a019b6da256f104abed1b82bfde6998a2ac9) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 5f423b3ba6..023bd5c588 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -6,6 +6,6 @@ OBJ_FILES = \ charcnv.o PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h -REQUIRED_SUBSYSTEMS = EXT_LIB_ICONV +PUBLIC_DEPENDENCIES = EXT_LIB_ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From 0d5587b5d128d9dd502a3b78c02fb986b33d92c4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 26 Apr 2006 12:22:54 +0000 Subject: r15274: Drop default EXT_LIB_ prefix for external libraries. Fixes issues with local (empty) libpopt.a overriding global one (This used to be commit 2f06305e53478e5030c24550954f221a9a97c83f) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 023bd5c588..fc49ffc70f 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -6,6 +6,6 @@ OBJ_FILES = \ charcnv.o PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h -PUBLIC_DEPENDENCIES = EXT_LIB_ICONV +PUBLIC_DEPENDENCIES = ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From 8d137d97858a618c8c5451bb7b11fb95990540c8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Apr 2006 16:05:05 +0000 Subject: r15295: Fix some dependencies Move unistr-specific code to lib/charset/. Remove _m from some places where it's not needed. (This used to be commit 03224e112424968fc3f547c6159c7ccae2d1aa5b) --- source4/lib/charset/charcnv.c | 21 +- source4/lib/charset/charset.h | 5 + source4/lib/charset/config.mk | 3 +- source4/lib/charset/util_unistr.c | 615 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 632 insertions(+), 12 deletions(-) create mode 100644 source4/lib/charset/util_unistr.c (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index d1d4561fa5..ca06b3b7d6 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -43,17 +43,16 @@ **/ static const char *charset_name(charset_t ch) { - const char *ret = NULL; - - if (ch == CH_UTF16) ret = "UTF-16LE"; - 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(); - else if (ch == CH_UTF8) ret = "UTF8"; - else if (ch == CH_UTF16BE) ret = "UTF-16BE"; - - if (!ret || !*ret) ret = "ASCII"; - return ret; + switch (ch) { + case CH_UTF16: return "UTF-16LE"; + case CH_UNIX: return lp_unix_charset(); + case CH_DOS: return lp_dos_charset(); + case CH_DISPLAY: return lp_display_charset(); + case CH_UTF8: return "UTF8"; + case CH_UTF16BE: return "UTF-16BE"; + default: + return "ASCII"; + } } static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 629786ee95..e91f81f30d 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -73,4 +73,9 @@ typedef struct { #include "lib/charset/charset_proto.h" +/* replace some string functions with multi-byte + versions */ +#define strlower(s) strlower_m(s) +#define strupper(s) strupper_m(s) + #endif /* __CHARSET_H__ */ diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index fc49ffc70f..67703fbc37 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -3,7 +3,8 @@ [SUBSYSTEM::CHARSET] OBJ_FILES = \ iconv.o \ - charcnv.o + charcnv.o \ + util_unistr.o PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c new file mode 100644 index 0000000000..faa1398eac --- /dev/null +++ b/source4/lib/charset/util_unistr.c @@ -0,0 +1,615 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Andrew Tridgell 1992-2001 + Copyright (C) Simo Sorce 2001 + + 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. +*/ + +#include "includes.h" +#include "system/iconv.h" + +/** + * @file + * @brief Unicode string manipulation + */ + +/* these 2 tables define the unicode case handling. They are loaded + at startup either via mmap() or read() from the lib directory */ +static void *upcase_table; +static void *lowcase_table; + + +/******************************************************************* +load the case handling tables +********************************************************************/ +static void load_case_tables(void) +{ + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("load_case_tables"); + if (!mem_ctx) { + smb_panic("No memory for case_tables"); + } + upcase_table = map_file(data_path(mem_ctx, "upcase.dat"), 0x20000); + lowcase_table = map_file(data_path(mem_ctx, "lowcase.dat"), 0x20000); + talloc_free(mem_ctx); + if (upcase_table == NULL) { + /* try also under codepages for testing purposes */ + upcase_table = map_file("codepages/upcase.dat", 0x20000); + if (upcase_table == NULL) { + upcase_table = (void *)-1; + } + } + if (lowcase_table == NULL) { + /* try also under codepages for testing purposes */ + lowcase_table = map_file("codepages/lowcase.dat", 0x20000); + if (lowcase_table == NULL) { + lowcase_table = (void *)-1; + } + } +} + +/** + Convert a codepoint_t to upper case. +**/ +codepoint_t toupper_w(codepoint_t val) +{ + if (val < 128) { + return toupper(val); + } + if (upcase_table == NULL) { + load_case_tables(); + } + if (upcase_table == (void *)-1) { + return val; + } + if (val & 0xFFFF0000) { + return val; + } + return SVAL(upcase_table, val*2); +} + +/** + Convert a codepoint_t to lower case. +**/ +codepoint_t tolower_w(codepoint_t val) +{ + if (val < 128) { + return tolower(val); + } + if (lowcase_table == NULL) { + load_case_tables(); + } + if (lowcase_table == (void *)-1) { + return val; + } + if (val & 0xFFFF0000) { + return val; + } + return SVAL(lowcase_table, val*2); +} + +/** + compare two codepoints case insensitively +*/ +int codepoint_cmpi(codepoint_t c1, codepoint_t c2) +{ + if (c1 == c2 || + toupper_w(c1) == toupper_w(c2)) { + return 0; + } + return c1 - c2; +} + +/** + Case insensitive string compararison +**/ +_PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + + while (*s1 && *s2) { + c1 = next_codepoint(s1, &size1); + c2 = next_codepoint(s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_w(c1) != toupper_w(c2)) { + return c1 - c2; + } + } + + return *s1 - *s2; +} + +/** + * Get the next token from a string, return False if none found. + * Handles double-quotes. + * + * Based on a routine by GJC@VILLAGE.COM. + * Extensively modified by Andrew.Tridgell@anu.edu.au + **/ +_PUBLIC_ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) +{ + const char *s; + BOOL quoted; + size_t len=1; + + if (!ptr) + return(False); + + s = *ptr; + + /* default to simple separators */ + if (!sep) + sep = " \t\n\r"; + + /* find the first non sep char */ + while (*s && strchr_m(sep,*s)) + s++; + + /* nothing left? */ + if (! *s) + return(False); + + /* copy over the token */ + for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { + if (*s == '\"') { + quoted = !quoted; + } else { + len++; + *buff++ = *s; + } + } + + *ptr = (*s) ? s+1 : s; + *buff = 0; + + return(True); +} + +/** + Case insensitive string compararison, length limited +**/ +_PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) +{ + codepoint_t c1=0, c2=0; + size_t size1, size2; + + while (*s1 && *s2 && n) { + n--; + + c1 = next_codepoint(s1, &size1); + c2 = next_codepoint(s2, &size2); + + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* what else can we do?? */ + return strcasecmp(s1, s2); + } + + if (toupper_w(c1) != toupper_w(c2)) { + return c1 - c2; + } + } + + if (n == 0) { + return 0; + } + + return *s1 - *s2; +} + +/** + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ +_PUBLIC_ BOOL strequal_w(const char *s1, const char *s2) +{ + if (s1 == s2) + return(True); + if (!s1 || !s2) + return(False); + + return strcasecmp_m(s1,s2) == 0; +} + +/** + Compare 2 strings (case sensitive). +**/ +_PUBLIC_ BOOL strcsequal_w(const char *s1,const char *s2) +{ + if (s1 == s2) + return(True); + if (!s1 || !s2) + return(False); + + return strcmp(s1,s2) == 0; +} + + +/** + String replace. + NOTE: oldc and newc must be 7 bit characters +**/ +_PUBLIC_ void string_replace_w(char *s, char oldc, char newc) +{ + while (*s) { + size_t size; + codepoint_t c = next_codepoint(s, &size); + if (c == oldc) { + *s = newc; + } + s += size; + } +} + +/** + Paranoid strcpy into a buffer of given length (includes terminating + zero. Strips out all but 'a-Z0-9' and the character in other_safe_chars + and replaces with '_'. Deliberately does *NOT* check for multibyte + characters. Don't change it ! +**/ + +_PUBLIC_ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) +{ + size_t len, i; + + if (maxlength == 0) { + /* can't fit any bytes at all! */ + return NULL; + } + + if (!dest) { + DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n")); + return NULL; + } + + if (!src) { + *dest = 0; + return dest; + } + + len = strlen(src); + if (len >= maxlength) + len = maxlength - 1; + + if (!other_safe_chars) + other_safe_chars = ""; + + for(i = 0; i < len; i++) { + int val = (src[i] & 0xff); + if (isupper(val) || islower(val) || isdigit(val) || strchr_m(other_safe_chars, val)) + dest[i] = src[i]; + else + dest[i] = '_'; + } + + dest[i] = '\0'; + + return dest; +} + +/** + Count the number of UCS2 characters in a string. Normally this will + be the same as the number of bytes in a string for single byte strings, + but will be different for multibyte. +**/ +_PUBLIC_ size_t strlen_m(const char *s) +{ + size_t count = 0; + + if (!s) { + return 0; + } + + while (*s && !(((uint8_t)*s) & 0x80)) { + s++; + count++; + } + + if (!*s) { + return count; + } + + while (*s) { + size_t c_size; + codepoint_t c = next_codepoint(s, &c_size); + if (c < 0x10000) { + count += 1; + } else { + count += 2; + } + s += c_size; + } + + return count; +} + +/** + Work out the number of multibyte chars in a string, including the NULL + terminator. +**/ +_PUBLIC_ size_t strlen_m_term(const char *s) +{ + if (!s) { + return 0; + } + + return strlen_m(s) + 1; +} + +/** + Strchr and strrchr_m are a bit complex on general multi-byte strings. +**/ +_PUBLIC_ char *strchr_m(const char *s, char c) +{ + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) { + return discard_const(s); + } + s += size; + } + + return NULL; +} + +/** + * Multibyte-character version of strrchr + */ +_PUBLIC_ char *strrchr_m(const char *s, char c) +{ + char *ret = NULL; + + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strrchr(s, c); + } + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) { + ret = discard_const(s); + } + s += size; + } + + return ret; +} + +/** + return True if any (multi-byte) character is lower case +*/ +_PUBLIC_ BOOL strhaslower(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(string, &c_size); + string += c_size; + + t = toupper_w(s); + + if (s != t) { + return True; /* that means it has lower case chars */ + } + } + + return False; +} + +/** + return True if any (multi-byte) character is upper case +*/ +_PUBLIC_ BOOL strhasupper(const char *string) +{ + while (*string) { + size_t c_size; + codepoint_t s; + codepoint_t t; + + s = next_codepoint(string, &c_size); + string += c_size; + + t = tolower_w(s); + + if (s != t) { + return True; /* that means it has upper case chars */ + } + } + + return False; +} + +/** + Convert a string to lower case, allocated with talloc +**/ +_PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) +{ + size_t size=0; + char *dest; + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_size(ctx, 2*(strlen(src))+1); + if (dest == NULL) { + return NULL; + } + + while (*src) { + size_t c_size; + codepoint_t c = next_codepoint(src, &c_size); + src += c_size; + + c = tolower_w(c); + + c_size = push_codepoint(dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + return dest; +} + +/** + Convert a string to UPPER case, allocated with talloc +**/ +_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +{ + size_t size=0; + char *dest; + + if (!src) { + return NULL; + } + + /* this takes advantage of the fact that upper/lower can't + change the length of a character by more than 1 byte */ + dest = talloc_size(ctx, 2*(strlen(src))+1); + if (dest == NULL) { + return NULL; + } + + while (*src) { + size_t c_size; + codepoint_t c = next_codepoint(src, &c_size); + src += c_size; + + c = toupper_w(c); + + c_size = push_codepoint(dest+size, c); + if (c_size == -1) { + talloc_free(dest); + return NULL; + } + size += c_size; + } + + dest[size] = 0; + + return dest; +} + +/** + Convert a string to lower case. +**/ +_PUBLIC_ void strlower_m(char *s) +{ + char *d; + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + while (*s && !(((uint8_t)*s) & 0x80)) { + *s = tolower((uint8_t)*s); + s++; + } + + if (!*s) + return; + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(s, &c_size); + c_size2 = push_codepoint(d, tolower_w(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", + c, tolower_w(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strlower_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +/** + Convert a string to UPPER case. +**/ +_PUBLIC_ void strupper_m(char *s) +{ + char *d; + + /* this is quite a common operation, so we want it to be + fast. We optimise for the ascii case, knowing that all our + supported multi-byte character sets are ascii-compatible + (ie. they match for the first 128 chars) */ + while (*s && !(((uint8_t)*s) & 0x80)) { + *s = toupper((uint8_t)*s); + s++; + } + + if (!*s) + return; + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint(s, &c_size); + c_size2 = push_codepoint(d, toupper_w(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", + c, toupper_w(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strupper_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + -- cgit From 620d759f49f4b648d0fa4a84e67f1cecbbdd0f06 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Apr 2006 19:50:13 +0000 Subject: r15298: Fix the build using a few hacks in the build system. Recursive dependencies are now forbidden (the build system will bail out if there are any). I've split up auth_sam.c into auth_sam.c and sam.c. Andrew, please rename sam.c / move its contents to whatever/wherever you think suits best. (This used to be commit 6646384aaf3e7fa2aa798c3e564b94b0617ec4d0) --- source4/lib/charset/util_unistr.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index faa1398eac..f55e390856 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -613,3 +613,22 @@ _PUBLIC_ void strupper_m(char *s) *d = 0; } + +/** + Find the number of 'c' chars in a string +**/ +_PUBLIC_ size_t count_chars_w(const char *s, char c) +{ + size_t count = 0; + + while (*s) { + size_t size; + codepoint_t c2 = next_codepoint(s, &size); + if (c2 == c) count++; + s += size; + } + + return count; +} + + -- cgit From e572bbb94cb8a23d366647bcf584cc75029e8def Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 29 Apr 2006 12:39:19 +0000 Subject: r15321: Reduce the size of rewrite.m4 a bit more (This used to be commit c83e4b166534278c335254aa8890a50635bbf1b7) --- source4/lib/charset/util_unistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index f55e390856..1eb198d6f9 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -268,7 +268,7 @@ _PUBLIC_ BOOL strcsequal_w(const char *s1,const char *s2) **/ _PUBLIC_ void string_replace_w(char *s, char oldc, char newc) { - while (*s) { + for (; s && *s; s++) { size_t size; codepoint_t c = next_codepoint(s, &size); if (c == oldc) { -- cgit From 089cbd4a8e8108306ba92b01746ecd261e9fdd7c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 17:13:46 +0000 Subject: r15568: Simplify detection of iconv libraries a fair bit and fix it to work on FreeBSD. Based very loosely on a patch by Timur Bakevey Fixes #3688 (This used to be commit ea7b28572b453da8eced565a49e4c10e7ebd2e28) --- source4/lib/charset/config.m4 | 114 +++++++++++++++++++++++++----------------- 1 file changed, 69 insertions(+), 45 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index 9812c356ff..cbcae29f10 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -1,6 +1,47 @@ -dnl # ICONV/CHARSET subsystem +dnl SMB_CHECK_ICONV(action-if-found,action-if-not-found) +AC_DEFUN(SMB_CHECK_ICONV,[ + AC_CHECK_HEADERS(iconv.h giconv.h) -ICONV_LOCATION=standard + AC_TRY_RUN([#include +#ifdef HAVE_GICONV_H +#include +#endif +#ifdef HAVE_ICONV_H +#include +#endif + +int main() +{ + iconv_t cd = iconv_open("ASCII","UCS-2LE"); + if (cd == 0 || cd == (iconv_t)-1) return -1; + return 0; +} + ],[$1],[$2]) +]) + +dnl SMB_CHECK_ICONV_DIR(dir,action-if-found,action-if-not-found) +AC_DEFUN(SMB_CHECK_ICONV_DIR, +[ + if test -f "$1/include/iconv.h" -o -f "$1/include/giconv.h"; then + CPPFLAGS="-I$1/include" + LDFLAGS="-L$1/lib" + LIBS=-liconv + + SMB_CHECK_ICONV([$2], + [ + LIBS=-lgiconv + SMB_CHECK_ICONV([$2],[$3]) + ]) + + CPPFLAGS=$save_CPPFLAGS + LDFLAGS=$save_LDFLAGS + LIBS=$save_LIBS + else + $2 + fi +]) + +ICONV_FOUND=no LOOK_DIRS="/usr /usr/local /sw" AC_ARG_WITH(libiconv, [ --with-libiconv=BASEDIR Use libiconv in BASEDIR/lib and BASEDIR/include (default=auto) ], @@ -9,57 +50,40 @@ AC_ARG_WITH(libiconv, AC_MSG_ERROR(I won't take no for an answer) else if test "$withval" != "yes" ; then - LOOK_DIRS="$withval $LOOK_DIRS" + SMB_CHECK_ICONV_DIR($withval, [ + ICONV_FOUND=yes; + ICONV_CPPFLAGS="$CPPFLAGS" + ICONV_LIBS="$LIBS" + ICONV_LDFLAGS="$LDFLAGS" + ], [AC_MSG_ERROR([No iconv library found in $withval])]) fi fi ]) -ICONV_FOUND="no" -for i in $LOOK_DIRS ; do - save_LIBS=$LIBS - save_LDFLAGS=$LDFLAGS - save_CPPFLAGS=$CPPFLAGS - CPPFLAGS="-I$i/include" - LDFLAGS="-L$i/lib" - LIBS= - export LDFLAGS LIBS CPPFLAGS -dnl Try to find iconv(3) - jm_ICONV($i) - - TMP_ICONV_LIBS="$LIBS" - - CPPFLAGS=$save_CPPFLAGS - LDFLAGS=$save_LDFLAGS - LIBS=$save_LIBS - export LDFLAGS LIBS CPPFLAGS +if test x$ICONV_FOUND = xno; then + SMB_CHECK_ICONV([ICONV_FOUND=yes]) +fi - if test -n "$ICONV_FOUND" ; then - LIB_ADD_DIR(ICONV_LDFLAGS, $i/lib) - CFLAGS_ADD_DIR(ICONV_CPPFLAGS, $i/include) - ICONV_LIBS="$TMP_ICONV_LIBS" - break - fi +for i in $LOOK_DIRS ; do + if test x$ICONV_FOUND = xyes; then + break + fi + + SMB_CHECK_ICONV_DIR($withval, [ + ICONV_FOUND=yes; + ICONV_CPPFLAGS="$CPPFLAGS" + ICONV_LIBS="$LIBS" + ICONV_LDFLAGS="$LDFLAGS" + ], []) done -############ -# check for iconv in libc -AC_CACHE_CHECK([for working iconv],samba_cv_HAVE_NATIVE_ICONV,[ -AC_TRY_RUN([ -#include -main() { - iconv_t cd = iconv_open("ASCII", "UCS-2LE"); - if (cd == 0 || cd == (iconv_t)-1) return -1; - return 0; -} -], -samba_cv_HAVE_NATIVE_ICONV=yes,samba_cv_HAVE_NATIVE_ICONV=no,samba_cv_HAVE_NATIVE_ICONV=cross)]) -if test x"$samba_cv_HAVE_NATIVE_ICONV" = x"yes"; then - AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether to use native iconv]) -fi - -if test x"$ICONV_FOUND" = x"no" -o x"$samba_cv_HAVE_NATIVE_ICONV" != x"yes" ; then +if test x"$ICONV_FOUND" = x"no"; then AC_MSG_WARN([Sufficient support for iconv function was not found. - Install libiconv from http://freshmeat.net/projects/libiconv/ for better charset compatibility!]) + Install libiconv from http://www.gnu.org/software/libiconv/ for better charset compatibility!]) + SMB_ENABLE(ICONV,NO) +else + AC_DEFINE(HAVE_NATIVE_ICONV,1,[Whether external iconv is available]) + SMB_ENABLE(ICONV,YES) fi SMB_EXT_LIB(ICONV,[${ICONV_LIBS}],[${ICONV_CFLAGS}],[${ICONV_CPPFLAGS}],[${ICONV_LDFLAGS}]) -- cgit From 172a83d72491f90f6191be1040ef8b2e1789bd2e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 13 May 2006 19:14:12 +0000 Subject: r15573: Fix build of systems that have iconv headers in non-standard locations Split of system/locale.h header from system/iconv.h Previously, iconv wasn't being used on these systems (This used to be commit aa6d66fda69779d1c2948a1aca85dbd5208f1cba) --- source4/lib/charset/util_unistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 1eb198d6f9..80c1d3b125 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "system/iconv.h" +#include "system/locale.h" /** * @file -- cgit From 70afbd50908ab2c2bffbceebd1af30b2fbf1e4f0 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 24 May 2006 17:47:40 +0000 Subject: r15869: Fix loop var to search paths for iconv (This used to be commit 55843863ff1f92be9918c845e208a30660ed2ae5) --- source4/lib/charset/config.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index cbcae29f10..9fcea97add 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -69,7 +69,7 @@ for i in $LOOK_DIRS ; do break fi - SMB_CHECK_ICONV_DIR($withval, [ + SMB_CHECK_ICONV_DIR($i, [ ICONV_FOUND=yes; ICONV_CPPFLAGS="$CPPFLAGS" ICONV_LIBS="$LIBS" -- cgit From ca61b4f3b557b5505d9825fad81f6a22860cc716 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 24 May 2006 17:57:54 +0000 Subject: r15870: Improve detection of iconv - should prevent HAVE_ICONV_H being defined when the installed iconv library doesn't match our criteria as well as some other minor fixes. (This used to be commit 7937932615434a59c84d8a1b81e368f6a5f8e429) --- source4/lib/charset/config.m4 | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index 9fcea97add..2e20f7ab37 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -1,14 +1,7 @@ dnl SMB_CHECK_ICONV(action-if-found,action-if-not-found) AC_DEFUN(SMB_CHECK_ICONV,[ - AC_CHECK_HEADERS(iconv.h giconv.h) - AC_TRY_RUN([#include -#ifdef HAVE_GICONV_H -#include -#endif -#ifdef HAVE_ICONV_H -#include -#endif +#include <$1> int main() { @@ -16,29 +9,24 @@ int main() if (cd == 0 || cd == (iconv_t)-1) return -1; return 0; } - ],[$1],[$2]) + ],[$2],[$3]) ]) dnl SMB_CHECK_ICONV_DIR(dir,action-if-found,action-if-not-found) AC_DEFUN(SMB_CHECK_ICONV_DIR, [ - if test -f "$1/include/iconv.h" -o -f "$1/include/giconv.h"; then CPPFLAGS="-I$1/include" LDFLAGS="-L$1/lib" LIBS=-liconv - SMB_CHECK_ICONV([$2], - [ - LIBS=-lgiconv - SMB_CHECK_ICONV([$2],[$3]) + SMB_CHECK_ICONV(iconv.h,[ AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) $2 ], [ + LIBS=-lgiconv + SMB_CHECK_ICONV(giconv.h,[AC_DEFINE(HAVE_GICONV_H,1,[Whether giconv.h is present]) $2],[$3]) ]) CPPFLAGS=$save_CPPFLAGS LDFLAGS=$save_LDFLAGS LIBS=$save_LIBS - else - $2 - fi ]) ICONV_FOUND=no @@ -61,7 +49,7 @@ AC_ARG_WITH(libiconv, ]) if test x$ICONV_FOUND = xno; then - SMB_CHECK_ICONV([ICONV_FOUND=yes]) + SMB_CHECK_ICONV(iconv.h,[ICONV_FOUND=yes]) fi for i in $LOOK_DIRS ; do -- cgit From e157dccfaf699bc6fe436a8cdf1c95b125cde2db Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 24 May 2006 18:23:57 +0000 Subject: r15871: Fix systems with native iconv (This used to be commit 8ce292bdf3589e5d054bf9a534846c29dfc71124) --- source4/lib/charset/config.m4 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index 2e20f7ab37..5d37a781fd 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -49,7 +49,7 @@ AC_ARG_WITH(libiconv, ]) if test x$ICONV_FOUND = xno; then - SMB_CHECK_ICONV(iconv.h,[ICONV_FOUND=yes]) + SMB_CHECK_ICONV(iconv.h,[AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) ICONV_FOUND=yes]) fi for i in $LOOK_DIRS ; do @@ -58,7 +58,7 @@ for i in $LOOK_DIRS ; do fi SMB_CHECK_ICONV_DIR($i, [ - ICONV_FOUND=yes; + ICONV_FOUND=yes ICONV_CPPFLAGS="$CPPFLAGS" ICONV_LIBS="$LIBS" ICONV_LDFLAGS="$LDFLAGS" -- cgit From 46a6477268ecdaeb15dbc00cd3ae016e2f24228d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 Jun 2006 23:12:51 +0000 Subject: r16143: Fix disappearance of user-specified CPPFLAGS,LDFLAGS and LIBS variables. (This used to be commit b7c3f80efd08c2206048d00815b7396488c91d3b) --- source4/lib/charset/config.m4 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index 5d37a781fd..ce278a6e4c 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -15,6 +15,9 @@ int main() dnl SMB_CHECK_ICONV_DIR(dir,action-if-found,action-if-not-found) AC_DEFUN(SMB_CHECK_ICONV_DIR, [ + save_CPPFLAGS="$CPPFLAGS" + save_LDFLAGS="$LDFLAGS" + save_LIBS="$LIBS" CPPFLAGS="-I$1/include" LDFLAGS="-L$1/lib" LIBS=-liconv @@ -24,9 +27,9 @@ AC_DEFUN(SMB_CHECK_ICONV_DIR, SMB_CHECK_ICONV(giconv.h,[AC_DEFINE(HAVE_GICONV_H,1,[Whether giconv.h is present]) $2],[$3]) ]) - CPPFLAGS=$save_CPPFLAGS - LDFLAGS=$save_LDFLAGS - LIBS=$save_LIBS + CPPFLAGS="$save_CPPFLAGS" + LDFLAGS="$save_LDFLAGS" + LIBS="$save_LIBS" ]) ICONV_FOUND=no -- cgit From f0f1a5f4bf1c0c732a6c5a80c275656ac7d5617f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 27 Jun 2006 17:58:57 +0000 Subject: r16571: - make push/pull_ascii()/_ucs() functions static, callers should use push/pull_string() functions with STR_ASCII or STR_UNICODE - make the push/pull_ascii/ucs2/utf8_talloc() functions complete (they should be reduced to pull/push_string_talloc() later...) metze (This used to be commit b0af976187d2d46b7dbe5a532a5491476b459119) --- source4/lib/charset/charcnv.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index ca06b3b7d6..0df77f4eff 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -286,7 +286,7 @@ convert: * @param dest_len the maximum length in bytes allowed in the * destination. If @p dest_len is -1 then no maximum is used. **/ -_PUBLIC_ ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) +static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len; ssize_t ret; @@ -321,7 +321,6 @@ _PUBLIC_ ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int fl _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; - *dest = NULL; return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest); } @@ -342,7 +341,7 @@ _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src * @param src_len is the length of the source area in bytes. * @returns the number of bytes occupied by the string in @p src. **/ -_PUBLIC_ ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -381,7 +380,7 @@ _PUBLIC_ ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t * @param dest_len is the maximum length allowed in the * destination. If dest_len is -1 then no maxiumum is used. **/ -_PUBLIC_ ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) +static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; size_t src_len = strlen(src); @@ -449,7 +448,6 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) { size_t src_len = strlen(src)+1; - *dest = NULL; return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } @@ -465,7 +463,7 @@ _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) The resulting string in "dest" is always null terminated. **/ -_PUBLIC_ size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -494,6 +492,21 @@ _PUBLIC_ size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t s return src_len; } +/** + * Copy a string from a ASCII src to a unix char * destination, allocating a buffer using talloc + * + * @param dest always set at least to NULL + * + * @returns The number of bytes occupied by the string in the destination + **/ + +_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +{ + size_t src_len = strlen(src)+1; + *dest = NULL; + return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest); +} + /** * Copy a string from a UCS2 src to a unix char * destination, allocating a buffer using talloc * -- cgit From 0e5f94131dfd3c6db78f6236a872a0669b3e60b7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 22 Aug 2006 19:01:08 +0000 Subject: r17715: make the cast explicit and remove compiler warnings metze (This used to be commit dab51c1f7fa3cdb9e1c3b094935362af6d6725c4) --- source4/lib/charset/charcnv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 0df77f4eff..f46f861fac 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -630,11 +630,11 @@ _PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) /* this looks a little strange, but it is needed to cope with codepoints above 64k */ olen = 2; - outbuf = buf; + outbuf = (char *)buf; smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); if (olen == 2) { olen = 4; - outbuf = buf; + outbuf = (char *)buf; smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); if (olen == 4) { /* we didn't convert any bytes */ @@ -692,7 +692,7 @@ _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) if (c < 0x10000) { ilen = 2; olen = 5; - inbuf = buf; + inbuf = (char *)buf; SSVAL(buf, 0, c); smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); if (ilen != 0) { @@ -710,7 +710,7 @@ _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) ilen = 4; olen = 5; - inbuf = buf; + inbuf = (char *)buf; smb_iconv(descriptor, &inbuf, &ilen, &str, &olen); if (ilen != 0) { -- cgit From 4b7139242b1b8f3e270d4d7640ed206e0a6c6b26 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 22 Aug 2006 19:05:27 +0000 Subject: r17716: make casts explicit and remove compiler warnings metze (This used to be commit 43f030e71e50f7846d539e3952afc70fdc3daa58) --- source4/lib/charset/iconv.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index df590444e5..28f102a4a0 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -563,15 +563,15 @@ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (const char *)c; + *outbuf = (char *)uc; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = c; - *outbuf = uc; + *inbuf = (const char *)c; + *outbuf = (char *)uc; return -1; } @@ -676,16 +676,16 @@ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (const char *)uc; + *outbuf = (char *)c; return 0; error: *inbytesleft = in_left; *outbytesleft = out_left; - *inbuf = uc; - *outbuf = c; + *inbuf = (const char *)uc; + *outbuf = (char *)c; return -1; } -- cgit From 0329d755a7611ba3897fc1ee9bdce410cc33d7f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Aug 2006 11:29:34 +0000 Subject: r17930: Merge noinclude branch: * Move dlinklist.h, smb.h to subsystem-specific directories * Clean up ads.h and move what is left of it to dsdb/ (only place where it's used) (This used to be commit f7afa1cb77f3cfa7020b57de12e6003db7cfcc42) --- source4/lib/charset/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 28f102a4a0..d3aff7b24f 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "system/iconv.h" #include "system/filesys.h" -- cgit From e424b054d1c9c4c6e1adb4ae7da8232766282c33 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Sep 2006 04:23:24 +0000 Subject: r17980: handle NULL arguments without crashing in strcasecmp_m() and strncasecmp_m(). This makes the use of these functions in sorting routines with RPC replies sane (This used to be commit 93413f84502ff308e88947b9d3bdc9d219478935) --- source4/lib/charset/util_unistr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 80c1d3b125..e6d929b4e5 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -123,6 +123,11 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) codepoint_t c1=0, c2=0; size_t size1, size2; + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + while (*s1 && *s2) { c1 = next_codepoint(s1, &size1); c2 = next_codepoint(s2, &size2); @@ -202,6 +207,11 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) codepoint_t c1=0, c2=0; size_t size1, size2; + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + while (*s1 && *s2 && n) { n--; -- cgit From 886d020dbfa7e69ed780dfba579ad52ebd37e277 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 Sep 2006 05:21:32 +0000 Subject: r18131: fixed tdb subsystem to use right tdb.h fixed LIBREPLACE dep in lib/charset (This used to be commit 2f6cd41f40cf1625918f272458b6e103e4f3e00e) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 67703fbc37..b4ed37f705 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -7,6 +7,6 @@ OBJ_FILES = \ util_unistr.o PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h -PUBLIC_DEPENDENCIES = ICONV +PUBLIC_DEPENDENCIES = ICONV LIBREPLACE # End SUBSYSTEM CHARSET ################################################ -- cgit From a46e12d0e07e1630f8ef15aff0f97cb2f1f4c273 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 7 Sep 2006 10:02:32 +0000 Subject: r18213: don't list LIBREPLACE depdendecies explicit and always at it as first private dependencies metze (This used to be commit 135d096776b53ae09ffc2b4f767dfbd18139570f) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index b4ed37f705..67703fbc37 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -7,6 +7,6 @@ OBJ_FILES = \ util_unistr.o PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h -PUBLIC_DEPENDENCIES = ICONV LIBREPLACE +PUBLIC_DEPENDENCIES = ICONV # End SUBSYSTEM CHARSET ################################################ -- cgit From e96b2df638b12b2e85a311993c328d5251919279 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2006 09:19:58 +0000 Subject: r18376: added iconv:native=false option to turn off native iconv. Needed under valgrind as native iconv is so full of overflows (This used to be commit d1de0202efc6e6ca4bbc1997f3e493da18cd35f4) --- source4/lib/charset/iconv.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index d3aff7b24f..8a7f4b4f6b 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -200,6 +200,9 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } #ifdef HAVE_NATIVE_ICONV + if ((!from || !to) && !lp_parm_bool(-1, "iconv", "native", True)) { + goto failed; + } if (!from) { ret->pull = sys_iconv; ret->cd_pull = iconv_open("UTF-16LE", fromcode); -- cgit From 5a4b133d1ce7ec5043a092396072be5374b3cf24 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Oct 2006 09:15:15 +0000 Subject: r19438: try to fix up the build breakages on BSD systems due to incorrectly detecting iconv.h (This used to be commit e6baa13e1f9c35f95021512b713cebba680b2a72) --- source4/lib/charset/config.m4 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index ce278a6e4c..fb845aa67c 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -1,5 +1,6 @@ -dnl SMB_CHECK_ICONV(action-if-found,action-if-not-found) +dnl SMB_CHECK_ICONV(hdr, msg, action-if-found,action-if-not-found) AC_DEFUN(SMB_CHECK_ICONV,[ + AC_MSG_CHECKING($2) AC_TRY_RUN([#include #include <$1> @@ -9,7 +10,7 @@ int main() if (cd == 0 || cd == (iconv_t)-1) return -1; return 0; } - ],[$2],[$3]) + ],[AC_MSG_RESULT(yes); $3],[AC_MSG_RESULT(no); $4]) ]) dnl SMB_CHECK_ICONV_DIR(dir,action-if-found,action-if-not-found) @@ -22,9 +23,9 @@ AC_DEFUN(SMB_CHECK_ICONV_DIR, LDFLAGS="-L$1/lib" LIBS=-liconv - SMB_CHECK_ICONV(iconv.h,[ AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) $2 ], [ + SMB_CHECK_ICONV(iconv.h,Whether iconv.h is present,[ AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) $2 ], [ LIBS=-lgiconv - SMB_CHECK_ICONV(giconv.h,[AC_DEFINE(HAVE_GICONV_H,1,[Whether giconv.h is present]) $2],[$3]) + SMB_CHECK_ICONV(giconv.h,Whether giconv.h is present, [AC_DEFINE(HAVE_GICONV_H,1,[Whether giconv.h is present]) $2],[$3]) ]) CPPFLAGS="$save_CPPFLAGS" @@ -52,7 +53,9 @@ AC_ARG_WITH(libiconv, ]) if test x$ICONV_FOUND = xno; then - SMB_CHECK_ICONV(iconv.h,[AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) ICONV_FOUND=yes]) + SMB_CHECK_ICONV(iconv.h, + [Whether iconv.h is present], + [AC_DEFINE(HAVE_ICONV_H,1,[Whether iconv.h is present]) ICONV_FOUND=yes]) fi for i in $LOOK_DIRS ; do -- cgit From 153349788cc643135b347eec80620ce958877f4b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 12 Nov 2006 00:54:43 +0000 Subject: r19672: Make LIBSAMBA-UTIL a subsystem again for now because it has interdependencies with LIBSAMBA-CONFIG. (This used to be commit 4a044fb529075044755a0b5cc21446bf24bec72e) --- source4/lib/charset/config.mk | 1 + source4/lib/charset/util_unistr.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 67703fbc37..4f0c80c79d 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -8,5 +8,6 @@ OBJ_FILES = \ PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV +PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index e6d929b4e5..7e1b08ca3e 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -21,6 +21,7 @@ #include "includes.h" #include "system/locale.h" +#include "dynconfig.h" /** * @file @@ -44,8 +45,8 @@ static void load_case_tables(void) if (!mem_ctx) { smb_panic("No memory for case_tables"); } - upcase_table = map_file(data_path(mem_ctx, "upcase.dat"), 0x20000); - lowcase_table = map_file(data_path(mem_ctx, "lowcase.dat"), 0x20000); + upcase_table = map_file(talloc_asprintf(mem_ctx, "%s/upcase.dat", dyn_DATADIR), 0x20000); + lowcase_table = map_file(talloc_asprintf(mem_ctx, "%s/lowcase.dat", dyn_DATADIR), 0x20000); talloc_free(mem_ctx); if (upcase_table == NULL) { /* try also under codepages for testing purposes */ -- cgit From 95caeb1046c1899075238400fb07092542c91dcd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 12 Nov 2006 03:26:11 +0000 Subject: r19678: Fix the build for now (ugly hack because of circular dependencies) (This used to be commit 0953bb7d5f2f2a81688f5421e1fbfa3bc38aa810) --- source4/lib/charset/config.mk | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 4f0c80c79d..fff447574f 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -9,5 +9,6 @@ PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG +LDFLAGS = -lsamba-config -lsamba-util # End SUBSYSTEM CHARSET ################################################ -- cgit From cbbe5be832494fb69c7d0e9ea7df8d47805863e4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 12 Nov 2006 03:36:47 +0000 Subject: r19679: Fix shared library build as well. (This used to be commit ff9e1b4f0634847d0db178b2c283865c4fb39c9b) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index fff447574f..b2035672ba 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -9,6 +9,6 @@ PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG -LDFLAGS = -lsamba-config -lsamba-util +LDFLAGS = bin/static/libsamba-config.a bin/static/libsamba-util.a # End SUBSYSTEM CHARSET ################################################ -- cgit From c6ccfeb9cb78a95048ce0d91317b5948ae4ca46e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jan 2007 11:47:27 +0000 Subject: r20649: fixed strlower_talloc() and strupper_talloc() to end with right size, so talloc_append_string() works (This used to be commit 0d36b036b381d4f81a22ce31066d89932d73597b) --- source4/lib/charset/util_unistr.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 7e1b08ca3e..e2c9015d1d 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -510,6 +510,9 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) dest[size] = 0; + /* trim it so talloc_append_string() works */ + dest = talloc_realloc_size(ctx, dest, size+1); + return dest; } @@ -549,6 +552,9 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) dest[size] = 0; + /* trim it so talloc_append_string() works */ + dest = talloc_realloc_size(ctx, dest, size+1); + return dest; } -- cgit From 34fe5027d04e8ad1fa379ee1413b6e331b585d24 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 12 Jan 2007 03:05:31 +0000 Subject: r20697: A couple of minot cross-compile fixes. (This used to be commit d4c7dd19f3a114ee1527cbcd3071b4921600977d) --- source4/lib/charset/config.m4 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.m4 b/source4/lib/charset/config.m4 index fb845aa67c..453de9fe26 100644 --- a/source4/lib/charset/config.m4 +++ b/source4/lib/charset/config.m4 @@ -10,7 +10,10 @@ int main() if (cd == 0 || cd == (iconv_t)-1) return -1; return 0; } - ],[AC_MSG_RESULT(yes); $3],[AC_MSG_RESULT(no); $4]) + ], + [AC_MSG_RESULT(yes); $3], + [AC_MSG_RESULT(no); $4], + [AC_MSG_RESULT(cross); $4]) ]) dnl SMB_CHECK_ICONV_DIR(dir,action-if-found,action-if-not-found) -- cgit From 0474005d074163f95e03580e5b1da7f7efe4664a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 5 Mar 2007 00:11:46 +0000 Subject: r21691: Add testsuite for lib/charset (This used to be commit a4184893959bb25541704938ee621e5c575b817d) --- source4/lib/charset/testsuite.c | 236 ++++++++++++++++++++++++++++++++++++++ source4/lib/charset/util_unistr.c | 7 +- 2 files changed, 237 insertions(+), 6 deletions(-) create mode 100644 source4/lib/charset/testsuite.c (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/testsuite.c b/source4/lib/charset/testsuite.c new file mode 100644 index 0000000000..e00b0724e8 --- /dev/null +++ b/source4/lib/charset/testsuite.c @@ -0,0 +1,236 @@ +/* + Unix SMB/CIFS implementation. + test suite for the charcnv functions + + Copyright (C) Jelmer Vernooij 2007 + + 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. +*/ + +#include "includes.h" +#include "torture/torture.h" + +static bool test_toupper_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, toupper_w('c'), 'C', "c"); + torture_assert_int_equal(tctx, toupper_w('Z'), 'Z', "z"); + torture_assert_int_equal(tctx, toupper_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + return true; +} + +static bool test_tolower_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, tolower_w('C'), 'c', "c"); + torture_assert_int_equal(tctx, tolower_w('z'), 'z', "z"); + torture_assert_int_equal(tctx, tolower_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + return true; +} + +static bool test_codepoint_cmpi(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, codepoint_cmpi('a', 'a'), 0, "same char"); + torture_assert_int_equal(tctx, codepoint_cmpi('A', 'a'), 0, "upcase version"); + torture_assert_int_equal(tctx, codepoint_cmpi('b', 'a'), 1, "right diff"); + torture_assert_int_equal(tctx, codepoint_cmpi('a', 'b'), -1, "right diff"); + return true; +} + +static bool test_strcasecmp_m(struct torture_context *tctx) +{ + torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings"); + torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings"); + torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings"); + torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL"); + torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL"); + torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL"); + return true; +} + + +static bool test_strequal_w(struct torture_context *tctx) +{ + torture_assert(tctx, !strequal_w("foo", "bar"), "different strings"); + torture_assert(tctx, strequal_w("foo", "foo"), "same case strings"); + torture_assert(tctx, strequal_w("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strequal_w(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strequal_w("foo", NULL), "other NULL"); + torture_assert(tctx, strequal_w(NULL, NULL), "both NULL"); + return true; +} + +static bool test_strcsequal_w(struct torture_context *tctx) +{ + torture_assert(tctx, !strcsequal_w("foo", "bar"), "different strings"); + torture_assert(tctx, strcsequal_w("foo", "foo"), "same case strings"); + torture_assert(tctx, !strcsequal_w("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strcsequal_w(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strcsequal_w("foo", NULL), "other NULL"); + torture_assert(tctx, strcsequal_w(NULL, NULL), "both NULL"); + return true; +} + +static bool test_string_replace_w(struct torture_context *tctx) +{ + char data[] = "bla"; + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cla", "first char replaced"); + memcpy(data, "bab", 4); + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cac", "other chars replaced"); + memcpy(data, "bba", 4); + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cca", "other chars replaced"); + memcpy(data, "blala", 6); + string_replace_w(data, 'o', 'c'); + torture_assert_str_equal(tctx, data, "blala", "no chars replaced"); + string_replace_w(NULL, 'b', 'c'); + return true; +} + +static bool test_strncasecmp_m(struct torture_context *tctx) +{ + torture_assert(tctx, strncasecmp_m("foo", "bar", 3) != 0, "different strings"); + torture_assert(tctx, strncasecmp_m("foo", "foo", 3) == 0, "same case strings"); + torture_assert(tctx, strncasecmp_m("foo", "Foo", 3) == 0, "different case strings"); + torture_assert(tctx, strncasecmp_m("fool", "Foo", 3) == 0, "different case strings"); + torture_assert(tctx, strncasecmp_m("fool", "Fool", 40) == 0, "over size"); + torture_assert(tctx, strncasecmp_m("BLA", "Fool", 0) == 0, "empty"); + torture_assert(tctx, strncasecmp_m(NULL, "Foo", 3) != 0, "one NULL"); + torture_assert(tctx, strncasecmp_m("foo", NULL, 3) != 0, "other NULL"); + torture_assert(tctx, strncasecmp_m(NULL, NULL, 3) == 0, "both NULL"); + return true; +} + + + +static bool test_next_token(struct torture_context *tctx) +{ + const char *teststr = "foo bar bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo", "token matches"); + torture_assert_str_equal(tctx, teststr, "bar bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bar", "token matches"); + torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_seps(struct torture_context *tctx) +{ + const char *teststr = ",foo bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, ",", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, ",", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_quotes(struct torture_context *tctx) +{ + const char *teststr = "\"foo bar\" bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bar", "token matches"); + torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_quote_wrong(struct torture_context *tctx) +{ + const char *teststr = "\"foo bar bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bar bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_strlen_m(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, strlen_m("foo"), 3, "simple len"); + torture_assert_int_equal(tctx, strlen_m("foo\x83l"), 6, "extended len"); + torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); + return true; +} + +static bool test_strlen_m_term(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, strlen_m_term("foo"), 4, "simple len"); + torture_assert_int_equal(tctx, strlen_m_term("foo\x83l"), 7, "extended len"); + torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); + return true; +} + +static bool test_strhaslower(struct torture_context *tctx) +{ + torture_assert(tctx, strhaslower("a"), "one low char"); + torture_assert(tctx, strhaslower("aB"), "one low, one up char"); + torture_assert(tctx, !strhaslower("B"), "one up char"); + torture_assert(tctx, !strhaslower(""), "empty string"); + torture_assert(tctx, !strhaslower("3"), "one digit"); + return true; +} + +static bool test_strhasupper(struct torture_context *tctx) +{ + torture_assert(tctx, strhasupper("B"), "one up char"); + torture_assert(tctx, strhasupper("aB"), "one low, one up char"); + torture_assert(tctx, !strhasupper("a"), "one low char"); + torture_assert(tctx, !strhasupper(""), "empty string"); + torture_assert(tctx, !strhasupper("3"), "one digit"); + return true; +} + +struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET"); + + torture_suite_add_simple_test(suite, "toupper_w", test_toupper_w); + torture_suite_add_simple_test(suite, "tolower_w", test_tolower_w); + torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi); + torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m); + torture_suite_add_simple_test(suite, "strequal_w", test_strequal_w); + torture_suite_add_simple_test(suite, "strcsequal_w", test_strcsequal_w); + torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w); + torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m); + torture_suite_add_simple_test(suite, "next_token", test_next_token); + torture_suite_add_simple_test(suite, "next_token_quotes", test_next_token_quotes); + torture_suite_add_simple_test(suite, "next_token_seps", test_next_token_seps); + torture_suite_add_simple_test(suite, "next_token_quote_wrong", test_next_token_quote_wrong); + torture_suite_add_simple_test(suite, "strlen_m", test_strlen_m); + torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term); + torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower); + torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper); + + return suite; +} diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index e2c9015d1d..ca65d1fa00 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -251,11 +251,6 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) **/ _PUBLIC_ BOOL strequal_w(const char *s1, const char *s2) { - if (s1 == s2) - return(True); - if (!s1 || !s2) - return(False); - return strcasecmp_m(s1,s2) == 0; } @@ -279,7 +274,7 @@ _PUBLIC_ BOOL strcsequal_w(const char *s1,const char *s2) **/ _PUBLIC_ void string_replace_w(char *s, char oldc, char newc) { - for (; s && *s; s++) { + while (s && *s) { size_t size; codepoint_t c = next_codepoint(s, &size); if (c == oldc) { -- cgit From 1d75e907e28fa0ee21c4693cbac9e0cdfb11c111 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 5 Mar 2007 01:50:33 +0000 Subject: r21694: Some more testing updates. (This used to be commit 9247626b1c5f1eec0cedd6be221aafc41d9a26ab) --- source4/lib/charset/testsuite.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/testsuite.c b/source4/lib/charset/testsuite.c index e00b0724e8..4d2acc30b5 100644 --- a/source4/lib/charset/testsuite.c +++ b/source4/lib/charset/testsuite.c @@ -113,7 +113,12 @@ static bool test_strncasecmp_m(struct torture_context *tctx) return true; } - +static bool test_next_token_null(struct torture_context *tctx) +{ + char buf[20]; + torture_assert(tctx, !next_token(NULL, buf, " ", 20), "null ptr works"); + return true; +} static bool test_next_token(struct torture_context *tctx) { @@ -135,6 +140,26 @@ static bool test_next_token(struct torture_context *tctx) return true; } +static bool test_next_token_implicit_sep(struct torture_context *tctx) +{ + const char *teststr = "foo\tbar\n bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo", "token matches"); + torture_assert_str_equal(tctx, teststr, "bar\n bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bar", "token matches"); + torture_assert_str_equal(tctx, teststr, " bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, NULL, 20), "finding token doesn't work"); + return true; +} + static bool test_next_token_seps(struct torture_context *tctx) { const char *teststr = ",foo bla"; @@ -211,6 +236,15 @@ static bool test_strhasupper(struct torture_context *tctx) return true; } +static bool test_count_chars_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, count_chars_w("foo", 'o'), 2, "simple"); + torture_assert_int_equal(tctx, count_chars_w("", 'o'), 0, "empty"); + torture_assert_int_equal(tctx, count_chars_w("bla", 'o'), 0, "none"); + torture_assert_int_equal(tctx, count_chars_w("bla", '\0'), 0, "null"); + return true; +} + struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET"); @@ -224,6 +258,8 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w); torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m); torture_suite_add_simple_test(suite, "next_token", test_next_token); + torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null); + torture_suite_add_simple_test(suite, "next_token_implicit_sep", test_next_token_implicit_sep); torture_suite_add_simple_test(suite, "next_token_quotes", test_next_token_quotes); torture_suite_add_simple_test(suite, "next_token_seps", test_next_token_seps); torture_suite_add_simple_test(suite, "next_token_quote_wrong", test_next_token_quote_wrong); @@ -231,6 +267,7 @@ struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term); torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower); torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper); + torture_suite_add_simple_test(suite, "count_chars_w", test_count_chars_w); return suite; } -- cgit From 7a919bede78fb689edd19f8e4209079610540ecd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 7 May 2007 13:32:34 +0000 Subject: r22743: set the talloc name to the string... metze (This used to be commit d907fb26a7b0a6543a4bf0b848327a0b7d0da9fa) --- source4/lib/charset/util_unistr.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index ca65d1fa00..78af83973d 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -508,6 +508,8 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) /* trim it so talloc_append_string() works */ dest = talloc_realloc_size(ctx, dest, size+1); + talloc_set_name_const(dest, dest); + return dest; } @@ -550,6 +552,8 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) /* trim it so talloc_append_string() works */ dest = talloc_realloc_size(ctx, dest, size+1); + talloc_set_name_const(dest, dest); + return dest; } -- cgit From d2872b42f36ceac89970e3c1596300fa55ff7c50 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 19 May 2007 07:05:14 +0000 Subject: r23013: fixed a bug in the string_replace_w() test that caused OpenBSD to die (This used to be commit 1fe20a4555aac6f011eca98f138e125de0de4321) --- source4/lib/charset/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/testsuite.c b/source4/lib/charset/testsuite.c index 4d2acc30b5..db738d0c55 100644 --- a/source4/lib/charset/testsuite.c +++ b/source4/lib/charset/testsuite.c @@ -83,7 +83,7 @@ static bool test_strcsequal_w(struct torture_context *tctx) static bool test_string_replace_w(struct torture_context *tctx) { - char data[] = "bla"; + char data[6] = "bla"; string_replace_w(data, 'b', 'c'); torture_assert_str_equal(tctx, data, "cla", "first char replaced"); memcpy(data, "bab", 4); -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/charset/charcnv.c | 5 ++--- source4/lib/charset/charset.h | 5 ++--- source4/lib/charset/iconv.c | 5 ++--- source4/lib/charset/testsuite.c | 5 ++--- source4/lib/charset/util_unistr.c | 5 ++--- 5 files changed, 10 insertions(+), 15 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index f46f861fac..0f6e53f52c 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -7,7 +7,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, @@ -16,8 +16,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 . */ #include "includes.h" diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index e91f81f30d..e62f99a8fe 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -6,7 +6,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, @@ -15,8 +15,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 . */ #ifndef __CHARSET_H__ diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 8a7f4b4f6b..dacb65ccad 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -6,7 +6,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, @@ -15,8 +15,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 . */ #include "includes.h" diff --git a/source4/lib/charset/testsuite.c b/source4/lib/charset/testsuite.c index db738d0c55..5e42ca2932 100644 --- a/source4/lib/charset/testsuite.c +++ b/source4/lib/charset/testsuite.c @@ -6,7 +6,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, @@ -15,8 +15,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 . */ #include "includes.h" diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 78af83973d..feac7a65e9 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -6,7 +6,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, @@ -15,8 +15,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 . */ #include "includes.h" -- cgit From 61ffa08f4c95e29d301de9fbabd6e71c2dbc1056 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 18:10:19 +0000 Subject: r24712: No longer expose the 'BOOL' data type in any interfaces. (This used to be commit 1ce32673d960c8b05b6c1b1b99e1976a402417ae) --- source4/lib/charset/iconv.c | 2 +- source4/lib/charset/util_unistr.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index dacb65ccad..d10b3bb03c 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -148,7 +148,7 @@ size_t smb_iconv(smb_iconv_t cd, return 0; } -static BOOL is_utf16(const char *name) +static bool is_utf16(const char *name) { return strcasecmp(name, "UCS-2LE") == 0 || strcasecmp(name, "UTF-16LE") == 0; diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index feac7a65e9..3fa3bf75a9 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -160,10 +160,10 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) * Based on a routine by GJC@VILLAGE.COM. * Extensively modified by Andrew.Tridgell@anu.edu.au **/ -_PUBLIC_ BOOL next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) +_PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize) { const char *s; - BOOL quoted; + bool quoted; size_t len=1; if (!ptr) @@ -248,7 +248,7 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) * * @note The comparison is case-insensitive. **/ -_PUBLIC_ BOOL strequal_w(const char *s1, const char *s2) +_PUBLIC_ bool strequal_w(const char *s1, const char *s2) { return strcasecmp_m(s1,s2) == 0; } @@ -256,7 +256,7 @@ _PUBLIC_ BOOL strequal_w(const char *s1, const char *s2) /** Compare 2 strings (case sensitive). **/ -_PUBLIC_ BOOL strcsequal_w(const char *s1,const char *s2) +_PUBLIC_ bool strcsequal_w(const char *s1,const char *s2) { if (s1 == s2) return(True); @@ -429,7 +429,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) /** return True if any (multi-byte) character is lower case */ -_PUBLIC_ BOOL strhaslower(const char *string) +_PUBLIC_ bool strhaslower(const char *string) { while (*string) { size_t c_size; @@ -452,7 +452,7 @@ _PUBLIC_ BOOL strhaslower(const char *string) /** return True if any (multi-byte) character is upper case */ -_PUBLIC_ BOOL strhasupper(const char *string) +_PUBLIC_ bool strhasupper(const char *string) { while (*string) { size_t c_size; -- cgit From ed8d04ead92839d54ca67f55a8e2be9723dc6b0d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 18:43:18 +0000 Subject: r24717: Some more easy bool conversions, update TODO for registry (This used to be commit fc8771fb6aab815e63334da0159032f7ecd0a931) --- source4/lib/charset/iconv.c | 2 +- source4/lib/charset/util_unistr.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index d10b3bb03c..4eda585d4e 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -199,7 +199,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } #ifdef HAVE_NATIVE_ICONV - if ((!from || !to) && !lp_parm_bool(-1, "iconv", "native", True)) { + if ((!from || !to) && !lp_parm_bool(-1, "iconv", "native", true)) { goto failed; } if (!from) { diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 3fa3bf75a9..6c86b0b899 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -167,7 +167,7 @@ _PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bu size_t len=1; if (!ptr) - return(False); + return false; s = *ptr; @@ -180,11 +180,11 @@ _PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bu s++; /* nothing left? */ - if (! *s) - return(False); + if (!*s) + return false; /* copy over the token */ - for (quoted = False; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { + for (quoted = false; len < bufsize && *s && (quoted || !strchr_m(sep,*s)); s++) { if (*s == '\"') { quoted = !quoted; } else { @@ -196,7 +196,7 @@ _PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bu *ptr = (*s) ? s+1 : s; *buff = 0; - return(True); + return true; } /** @@ -259,9 +259,9 @@ _PUBLIC_ bool strequal_w(const char *s1, const char *s2) _PUBLIC_ bool strcsequal_w(const char *s1,const char *s2) { if (s1 == s2) - return(True); + return true; if (!s1 || !s2) - return(False); + return false; return strcmp(s1,s2) == 0; } @@ -442,11 +442,11 @@ _PUBLIC_ bool strhaslower(const char *string) t = toupper_w(s); if (s != t) { - return True; /* that means it has lower case chars */ + return true; /* that means it has lower case chars */ } } - return False; + return false; } /** @@ -465,11 +465,11 @@ _PUBLIC_ bool strhasupper(const char *string) t = tolower_w(s); if (s != t) { - return True; /* that means it has upper case chars */ + return true; /* that means it has upper case chars */ } } - return False; + return false; } /** -- cgit From 0b91f3916430d0271eab867675d44c5439de40c2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 29 Aug 2007 13:07:03 +0000 Subject: r24780: More work allowing libutil to be used by external users. (This used to be commit 31993cf67b816a184a4a4e92ef8ca2532c797190) --- source4/lib/charset/charcnv.c | 10 +++++++--- source4/lib/charset/charset.h | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 0f6e53f52c..fcf29d4647 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -37,6 +37,10 @@ * @sa lib/iconv.c */ +char *unix_charset = NULL; +char *dos_charset = NULL; +char *display_charset = NULL; + /** * Return the name of a charset to give to iconv(). **/ @@ -44,9 +48,9 @@ static const char *charset_name(charset_t ch) { switch (ch) { case CH_UTF16: return "UTF-16LE"; - case CH_UNIX: return lp_unix_charset(); - case CH_DOS: return lp_dos_charset(); - case CH_DISPLAY: return lp_display_charset(); + case CH_UNIX: return unix_charset; + case CH_DOS: return dos_charset; + case CH_DISPLAY: return display_charset; case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; default: diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index e62f99a8fe..3c548192b6 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -77,4 +77,9 @@ typedef struct { #define strlower(s) strlower_m(s) #define strupper(s) strupper_m(s) +/* from lib/charset */ +extern char *dos_charset; +extern char *unix_charset; +extern char *display_charset; + #endif /* __CHARSET_H__ */ -- cgit From 82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 30 Aug 2007 23:15:12 +0000 Subject: r24814: Fix headers, trim core.h even more. (This used to be commit 9647f860bdd5c0a74583e886182bd041a45e7655) --- source4/lib/charset/charset.h | 2 +- source4/lib/charset/iconv.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 3c548192b6..6943a60182 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -21,7 +21,7 @@ #ifndef __CHARSET_H__ #define __CHARSET_H__ -#include "lib/talloc/talloc.h" +#include /* this defines the charset types used in samba */ typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 4eda585d4e..062b4ddfc8 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -72,23 +72,22 @@ static const struct charset_functions builtin_functions[] = { static struct charset_functions *charsets = NULL; -NTSTATUS charset_register_backend(const void *_funcs) +bool charset_register_backend(const void *_funcs) { struct charset_functions *funcs = memdup(_funcs,sizeof(struct charset_functions)); - struct charset_functions *c = charsets; + struct charset_functions *c; /* Check whether we already have this charset... */ - while(c) { - if(!strcasecmp(c->name, funcs->name)){ + for (c = charsets; c != NULL; c = c->next) { + if(!strcasecmp(c->name, funcs->name)) { DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); - return NT_STATUS_OBJECT_NAME_COLLISION; + return false; } - c = c->next; } funcs->next = funcs->prev = NULL; DLIST_ADD(charsets, funcs); - return NT_STATUS_OK; + return true; } #ifdef HAVE_NATIVE_ICONV -- cgit From c37fa61abcfceb36c6f5e25ed20f43019ea8bd3f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Sep 2007 20:19:29 +0000 Subject: r24867: Avoid anonymous struct. Patch from Brad Hards. (This used to be commit e7866857fbdc9b7b7bebcecd41f34f54b37f3b04) --- source4/lib/charset/charset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 6943a60182..91408365ac 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -49,7 +49,7 @@ typedef uint32_t codepoint_t; /* generic iconv conversion structure */ -typedef struct { +typedef struct smb_iconv_s { size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft, -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/lib/charset/charcnv.c | 1 + source4/lib/charset/iconv.c | 1 + 2 files changed, 2 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index fcf29d4647..dda9f754b1 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -21,6 +21,7 @@ */ #include "includes.h" #include "system/iconv.h" +#include "param/param.h" /** * @file diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 062b4ddfc8..8510f70d96 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -22,6 +22,7 @@ #include "lib/util/dlinklist.h" #include "system/iconv.h" #include "system/filesys.h" +#include "param/param.h" /** -- cgit From dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/lib/charset/charcnv.c | 6 +++--- source4/lib/charset/util_unistr.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index dda9f754b1..ca96277679 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -152,7 +152,7 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, smb_iconv_t descriptor; if (srclen == (size_t)-1) - srclen = strlen(src)+1; + srclen = strlen(inbuf)+1; descriptor = get_conv_handle(from, to); @@ -351,9 +351,9 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) { if (src_len == (size_t)-1) { - src_len = strlen(src) + 1; + src_len = strlen((const char *)src) + 1; } else { - size_t len = strnlen(src, src_len); + size_t len = strnlen((const char *)src, src_len); if (len < src_len) len++; src_len = len; diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 6c86b0b899..e9cca090cc 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -393,7 +393,7 @@ _PUBLIC_ char *strchr_m(const char *s, char c) size_t size; codepoint_t c2 = next_codepoint(s, &size); if (c2 == c) { - return discard_const(s); + return discard_const_p(char, s); } s += size; } @@ -418,7 +418,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) size_t size; codepoint_t c2 = next_codepoint(s, &size); if (c2 == c) { - ret = discard_const(s); + ret = discard_const_p(char, s); } s += size; } @@ -482,7 +482,7 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) /* this takes advantage of the fact that upper/lower can't change the length of a character by more than 1 byte */ - dest = talloc_size(ctx, 2*(strlen(src))+1); + dest = talloc_array(ctx, char, 2*(strlen(src))+1); if (dest == NULL) { return NULL; } @@ -505,7 +505,7 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) dest[size] = 0; /* trim it so talloc_append_string() works */ - dest = talloc_realloc_size(ctx, dest, size+1); + dest = talloc_realloc(ctx, dest, char, size+1); talloc_set_name_const(dest, dest); @@ -526,7 +526,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) /* this takes advantage of the fact that upper/lower can't change the length of a character by more than 1 byte */ - dest = talloc_size(ctx, 2*(strlen(src))+1); + dest = talloc_array(ctx, char, 2*(strlen(src))+1); if (dest == NULL) { return NULL; } @@ -549,7 +549,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) dest[size] = 0; /* trim it so talloc_append_string() works */ - dest = talloc_realloc_size(ctx, dest, size+1); + dest = talloc_realloc(ctx, dest, char, size+1); talloc_set_name_const(dest, dest); -- cgit From 98b57d5eb61094a9c88e2f7d90d3e21b7e74e9d8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 16:46:30 +0000 Subject: r25035: Fix some more warnings, use service pointer rather than service number in more places. (This used to be commit df9cebcb97e20564359097148665bd519f31bc6f) --- source4/lib/charset/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 8510f70d96..1c571f8961 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -75,7 +75,7 @@ static struct charset_functions *charsets = NULL; bool charset_register_backend(const void *_funcs) { - struct charset_functions *funcs = memdup(_funcs,sizeof(struct charset_functions)); + struct charset_functions *funcs = (struct charset_functions *)memdup(_funcs,sizeof(struct charset_functions)); struct charset_functions *c; /* Check whether we already have this charset... */ @@ -199,7 +199,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } #ifdef HAVE_NATIVE_ICONV - if ((!from || !to) && !lp_parm_bool(-1, "iconv", "native", true)) { + if ((!from || !to) && !lp_parm_bool(NULL, "iconv", "native", true)) { goto failed; } if (!from) { -- cgit From 3048e9ad654506219b169a934edded388d10fcad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Sep 2007 23:31:28 +0000 Subject: r25392: Add loadparm context as argument in a couple more places. (This used to be commit c62f51cc28a37959128e78a1f34cfd4c6d3ba069) --- source4/lib/charset/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index ca96277679..d0c4461cc8 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -119,7 +119,7 @@ static smb_iconv_t get_conv_handle(charset_t from, charset_t to) strcasecmp(charset_name(CH_DOS), "ASCII") != 0) { DEBUG(0,("dos charset '%s' unavailable - using ASCII\n", charset_name(CH_DOS))); - lp_set_cmdline("dos charset", "ASCII"); + lp_set_cmdline(global_loadparm, "dos charset", "ASCII"); n1 = charset_name(from); n2 = charset_name(to); -- cgit From 60a1046c5c5783799bd64fe18e03534670f83d82 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 29 Sep 2007 18:00:19 +0000 Subject: r25430: Add the loadparm context to all parametric options. (This used to be commit fd697d77c9fe67a00939a1f04b35c451316fff58) --- source4/lib/charset/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 1c571f8961..9b035cd1db 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -199,7 +199,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) } #ifdef HAVE_NATIVE_ICONV - if ((!from || !to) && !lp_parm_bool(NULL, "iconv", "native", true)) { + if ((!from || !to) && !lp_parm_bool(global_loadparm, NULL, "iconv", "native", true)) { goto failed; } if (!from) { -- cgit From 5ecd526d1ca41821118165af039d16d0e729b59d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 Oct 2007 23:26:37 +0000 Subject: r25456: Avoid externs for charsets for now - it breaks openchange. (This used to be commit 836431af83674018e9700f9da92ce251d108687a) --- source4/lib/charset/charcnv.c | 30 +++++++++++++----------------- source4/lib/charset/charset.h | 5 ----- 2 files changed, 13 insertions(+), 22 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index d0c4461cc8..9c794202b2 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -38,20 +38,16 @@ * @sa lib/iconv.c */ -char *unix_charset = NULL; -char *dos_charset = NULL; -char *display_charset = NULL; - /** * Return the name of a charset to give to iconv(). **/ -static const char *charset_name(charset_t ch) +static const char *charset_name(struct loadparm_context *lp_ctx, charset_t ch) { switch (ch) { case CH_UTF16: return "UTF-16LE"; - case CH_UNIX: return unix_charset; - case CH_DOS: return dos_charset; - case CH_DISPLAY: return display_charset; + case CH_UNIX: return lp_unix_charset(lp_ctx); + case CH_DOS: return lp_dos_charset(lp_ctx); + case CH_DISPLAY: return lp_display_charset(lp_ctx); case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; default: @@ -109,20 +105,20 @@ static smb_iconv_t get_conv_handle(charset_t from, charset_t to) return conv_handles[from][to]; } - n1 = charset_name(from); - n2 = charset_name(to); + n1 = charset_name(global_loadparm, from); + n2 = charset_name(global_loadparm, to); conv_handles[from][to] = smb_iconv_open(n2,n1); if (conv_handles[from][to] == (smb_iconv_t)-1) { if ((from == CH_DOS || to == CH_DOS) && - strcasecmp(charset_name(CH_DOS), "ASCII") != 0) { + strcasecmp(charset_name(global_loadparm, CH_DOS), "ASCII") != 0) { DEBUG(0,("dos charset '%s' unavailable - using ASCII\n", - charset_name(CH_DOS))); + charset_name(global_loadparm, CH_DOS))); lp_set_cmdline(global_loadparm, "dos charset", "ASCII"); - n1 = charset_name(from); - n2 = charset_name(to); + n1 = charset_name(global_loadparm, from); + n2 = charset_name(global_loadparm, to); conv_handles[from][to] = smb_iconv_open(n2,n1); } @@ -176,12 +172,12 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, reason="No more room"; if (from == CH_UNIX) { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n", - charset_name(from), charset_name(to), + charset_name(global_loadparm, from), charset_name(global_loadparm, to), (int)srclen, (int)destlen, (const char *)src)); } else { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n", - charset_name(from), charset_name(to), + charset_name(global_loadparm, from), charset_name(global_loadparm, to), (int)srclen, (int)destlen)); } return -1; @@ -223,7 +219,7 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_ if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, return -1*/ DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n", - charset_name(from), charset_name(to))); + charset_name(global_loadparm, from), charset_name(global_loadparm, to))); return -1; } diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 91408365ac..be2705100a 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -77,9 +77,4 @@ typedef struct smb_iconv_s { #define strlower(s) strlower_m(s) #define strupper(s) strupper_m(s) -/* from lib/charset */ -extern char *dos_charset; -extern char *unix_charset; -extern char *display_charset; - #endif /* __CHARSET_H__ */ -- cgit From a86920600a59ddf2b534e3c66c477a6f9be8de5b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 Nov 2007 23:36:45 +0100 Subject: r25926: Move iconv test to iconv code directory. (This used to be commit e20c4b90e4a935d3249d0b631b942fd318a2ece2) --- source4/lib/charset/tests/charset.c | 272 +++++++++++++++++++++++ source4/lib/charset/tests/iconv.c | 424 ++++++++++++++++++++++++++++++++++++ source4/lib/charset/testsuite.c | 272 ----------------------- 3 files changed, 696 insertions(+), 272 deletions(-) create mode 100644 source4/lib/charset/tests/charset.c create mode 100644 source4/lib/charset/tests/iconv.c delete mode 100644 source4/lib/charset/testsuite.c (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/tests/charset.c b/source4/lib/charset/tests/charset.c new file mode 100644 index 0000000000..5e42ca2932 --- /dev/null +++ b/source4/lib/charset/tests/charset.c @@ -0,0 +1,272 @@ +/* + Unix SMB/CIFS implementation. + test suite for the charcnv functions + + Copyright (C) Jelmer Vernooij 2007 + + 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 3 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, see . +*/ + +#include "includes.h" +#include "torture/torture.h" + +static bool test_toupper_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, toupper_w('c'), 'C', "c"); + torture_assert_int_equal(tctx, toupper_w('Z'), 'Z', "z"); + torture_assert_int_equal(tctx, toupper_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + return true; +} + +static bool test_tolower_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, tolower_w('C'), 'c', "c"); + torture_assert_int_equal(tctx, tolower_w('z'), 'z', "z"); + torture_assert_int_equal(tctx, tolower_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); + return true; +} + +static bool test_codepoint_cmpi(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, codepoint_cmpi('a', 'a'), 0, "same char"); + torture_assert_int_equal(tctx, codepoint_cmpi('A', 'a'), 0, "upcase version"); + torture_assert_int_equal(tctx, codepoint_cmpi('b', 'a'), 1, "right diff"); + torture_assert_int_equal(tctx, codepoint_cmpi('a', 'b'), -1, "right diff"); + return true; +} + +static bool test_strcasecmp_m(struct torture_context *tctx) +{ + torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings"); + torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings"); + torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings"); + torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL"); + torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL"); + torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL"); + return true; +} + + +static bool test_strequal_w(struct torture_context *tctx) +{ + torture_assert(tctx, !strequal_w("foo", "bar"), "different strings"); + torture_assert(tctx, strequal_w("foo", "foo"), "same case strings"); + torture_assert(tctx, strequal_w("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strequal_w(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strequal_w("foo", NULL), "other NULL"); + torture_assert(tctx, strequal_w(NULL, NULL), "both NULL"); + return true; +} + +static bool test_strcsequal_w(struct torture_context *tctx) +{ + torture_assert(tctx, !strcsequal_w("foo", "bar"), "different strings"); + torture_assert(tctx, strcsequal_w("foo", "foo"), "same case strings"); + torture_assert(tctx, !strcsequal_w("foo", "Foo"), "different case strings"); + torture_assert(tctx, !strcsequal_w(NULL, "Foo"), "one NULL"); + torture_assert(tctx, !strcsequal_w("foo", NULL), "other NULL"); + torture_assert(tctx, strcsequal_w(NULL, NULL), "both NULL"); + return true; +} + +static bool test_string_replace_w(struct torture_context *tctx) +{ + char data[6] = "bla"; + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cla", "first char replaced"); + memcpy(data, "bab", 4); + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cac", "other chars replaced"); + memcpy(data, "bba", 4); + string_replace_w(data, 'b', 'c'); + torture_assert_str_equal(tctx, data, "cca", "other chars replaced"); + memcpy(data, "blala", 6); + string_replace_w(data, 'o', 'c'); + torture_assert_str_equal(tctx, data, "blala", "no chars replaced"); + string_replace_w(NULL, 'b', 'c'); + return true; +} + +static bool test_strncasecmp_m(struct torture_context *tctx) +{ + torture_assert(tctx, strncasecmp_m("foo", "bar", 3) != 0, "different strings"); + torture_assert(tctx, strncasecmp_m("foo", "foo", 3) == 0, "same case strings"); + torture_assert(tctx, strncasecmp_m("foo", "Foo", 3) == 0, "different case strings"); + torture_assert(tctx, strncasecmp_m("fool", "Foo", 3) == 0, "different case strings"); + torture_assert(tctx, strncasecmp_m("fool", "Fool", 40) == 0, "over size"); + torture_assert(tctx, strncasecmp_m("BLA", "Fool", 0) == 0, "empty"); + torture_assert(tctx, strncasecmp_m(NULL, "Foo", 3) != 0, "one NULL"); + torture_assert(tctx, strncasecmp_m("foo", NULL, 3) != 0, "other NULL"); + torture_assert(tctx, strncasecmp_m(NULL, NULL, 3) == 0, "both NULL"); + return true; +} + +static bool test_next_token_null(struct torture_context *tctx) +{ + char buf[20]; + torture_assert(tctx, !next_token(NULL, buf, " ", 20), "null ptr works"); + return true; +} + +static bool test_next_token(struct torture_context *tctx) +{ + const char *teststr = "foo bar bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo", "token matches"); + torture_assert_str_equal(tctx, teststr, "bar bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bar", "token matches"); + torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_implicit_sep(struct torture_context *tctx) +{ + const char *teststr = "foo\tbar\n bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo", "token matches"); + torture_assert_str_equal(tctx, teststr, "bar\n bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bar", "token matches"); + torture_assert_str_equal(tctx, teststr, " bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, NULL, 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_seps(struct torture_context *tctx) +{ + const char *teststr = ",foo bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, ",", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, ",", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_quotes(struct torture_context *tctx) +{ + const char *teststr = "\"foo bar\" bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bar", "token matches"); + torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); + + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_next_token_quote_wrong(struct torture_context *tctx) +{ + const char *teststr = "\"foo bar bla"; + char buf[20]; + torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); + torture_assert_str_equal(tctx, buf, "foo bar bla", "token matches"); + torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); + + torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); + return true; +} + +static bool test_strlen_m(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, strlen_m("foo"), 3, "simple len"); + torture_assert_int_equal(tctx, strlen_m("foo\x83l"), 6, "extended len"); + torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); + return true; +} + +static bool test_strlen_m_term(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, strlen_m_term("foo"), 4, "simple len"); + torture_assert_int_equal(tctx, strlen_m_term("foo\x83l"), 7, "extended len"); + torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); + return true; +} + +static bool test_strhaslower(struct torture_context *tctx) +{ + torture_assert(tctx, strhaslower("a"), "one low char"); + torture_assert(tctx, strhaslower("aB"), "one low, one up char"); + torture_assert(tctx, !strhaslower("B"), "one up char"); + torture_assert(tctx, !strhaslower(""), "empty string"); + torture_assert(tctx, !strhaslower("3"), "one digit"); + return true; +} + +static bool test_strhasupper(struct torture_context *tctx) +{ + torture_assert(tctx, strhasupper("B"), "one up char"); + torture_assert(tctx, strhasupper("aB"), "one low, one up char"); + torture_assert(tctx, !strhasupper("a"), "one low char"); + torture_assert(tctx, !strhasupper(""), "empty string"); + torture_assert(tctx, !strhasupper("3"), "one digit"); + return true; +} + +static bool test_count_chars_w(struct torture_context *tctx) +{ + torture_assert_int_equal(tctx, count_chars_w("foo", 'o'), 2, "simple"); + torture_assert_int_equal(tctx, count_chars_w("", 'o'), 0, "empty"); + torture_assert_int_equal(tctx, count_chars_w("bla", 'o'), 0, "none"); + torture_assert_int_equal(tctx, count_chars_w("bla", '\0'), 0, "null"); + return true; +} + +struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET"); + + torture_suite_add_simple_test(suite, "toupper_w", test_toupper_w); + torture_suite_add_simple_test(suite, "tolower_w", test_tolower_w); + torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi); + torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m); + torture_suite_add_simple_test(suite, "strequal_w", test_strequal_w); + torture_suite_add_simple_test(suite, "strcsequal_w", test_strcsequal_w); + torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w); + torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m); + torture_suite_add_simple_test(suite, "next_token", test_next_token); + torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null); + torture_suite_add_simple_test(suite, "next_token_implicit_sep", test_next_token_implicit_sep); + torture_suite_add_simple_test(suite, "next_token_quotes", test_next_token_quotes); + torture_suite_add_simple_test(suite, "next_token_seps", test_next_token_seps); + torture_suite_add_simple_test(suite, "next_token_quote_wrong", test_next_token_quote_wrong); + torture_suite_add_simple_test(suite, "strlen_m", test_strlen_m); + torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term); + torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower); + torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper); + torture_suite_add_simple_test(suite, "count_chars_w", test_count_chars_w); + + return suite; +} diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c new file mode 100644 index 0000000000..259769d60f --- /dev/null +++ b/source4/lib/charset/tests/iconv.c @@ -0,0 +1,424 @@ +/* + Unix SMB/CIFS implementation. + + local testing of iconv routines. This tests the system iconv code against + the built-in iconv code + + Copyright (C) Andrew Tridgell 2004 + + 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 3 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, see . +*/ + +#include "includes.h" +#include "torture/torture.h" +#include "system/iconv.h" +#include "system/time.h" +#include "libcli/raw/libcliraw.h" +#include "param/param.h" +#include "torture/util.h" + +#if HAVE_NATIVE_ICONV + +static bool iconv_untestable(struct torture_context *tctx) +{ + iconv_t cd; + + if (!lp_parm_bool(global_loadparm, NULL, "iconv", "native", true)) + torture_skip(tctx, "system iconv disabled - skipping test"); + + cd = iconv_open("UTF-16LE", "UCS-4LE"); + if (cd == (iconv_t)-1) + torture_skip(tctx, "unable to test - system iconv library does not support UTF-16LE -> UCS-4LE"); + iconv_close(cd); + + cd = iconv_open("UTF-16LE", "CP850"); + if (cd == (iconv_t)-1) + torture_skip(tctx, "unable to test - system iconv library does not support UTF-16LE -> CP850\n"); + iconv_close(cd); + + return false; +} + +/* + generate a UTF-16LE buffer for a given unicode codepoint +*/ +static int gen_codepoint_utf16(unsigned int codepoint, + char *buf, size_t *size) +{ + static iconv_t cd; + uint8_t in[4]; + char *ptr_in; + size_t size_in, size_out, ret; + if (!cd) { + cd = iconv_open("UTF-16LE", "UCS-4LE"); + if (cd == (iconv_t)-1) { + cd = NULL; + return -1; + } + } + + in[0] = codepoint & 0xFF; + in[1] = (codepoint>>8) & 0xFF; + in[2] = (codepoint>>16) & 0xFF; + in[3] = (codepoint>>24) & 0xFF; + + ptr_in = (char *)in; + size_in = 4; + size_out = 8; + + ret = iconv(cd, &ptr_in, &size_in, &buf, &size_out); + + *size = 8 - size_out; + + return ret; +} + + +/* + work out the unicode codepoint of the first UTF-8 character in the buffer +*/ +static unsigned int get_codepoint(char *buf, size_t size, const char *charset) +{ + iconv_t cd; + uint8_t out[4]; + char *ptr_out; + size_t size_out, size_in, ret; + + cd = iconv_open("UCS-4LE", charset); + + size_in = size; + ptr_out = (char *)out; + size_out = sizeof(out); + memset(out, 0, sizeof(out)); + + ret = iconv(cd, &buf, &size_in, &ptr_out, &size_out); + + iconv_close(cd); + + return out[0] | (out[1]<<8) | (out[2]<<16) | (out[3]<<24); +} + +/* + display a buffer with name prefix +*/ +static void show_buf(const char *name, uint8_t *buf, size_t size) +{ + int i; + printf("%s ", name); + for (i=0;i len1 && + memcmp(buf1, buf2, len1) == 0 && + get_codepoint((char *)(buf2+len1), len2-len1, charset) >= (1<<20)) { + return true; + } + if (len1 > len2 && + memcmp(buf1, buf2, len2) == 0 && + get_codepoint((char *)(buf1+len2), len1-len2, charset) >= (1<<20)) { + return true; + } + + torture_assert_int_equal(test, ret1, ret2, "ret mismatch"); + + if (errno1 != errno2) { + show_buf(" rem1:", inbuf+(size-size_in1), size_in1); + show_buf(" rem2:", inbuf+(size-size_in2), size_in2); + torture_fail(test, talloc_asprintf(test, + "e1=%d/%s e2=%d/%s", + errno1, strerror(errno1), + errno2, strerror(errno2))); + } + + torture_assert_int_equal(test, outsize1, outsize2, "outsize mismatch"); + + torture_assert_int_equal(test, size_in1, size_in2, "size_in mismatch"); + + if (len1 != len2 || + memcmp(buf1, buf2, len1) != 0) { + torture_comment(test, "size=%d ret1=%d ret2=%d", (int)size, (int)ret1, (int)ret2); + show_buf(" IN1:", inbuf, size-size_in1); + show_buf(" IN2:", inbuf, size-size_in2); + show_buf("OUT1:", buf1, len1); + show_buf("OUT2:", buf2, len2); + if (len2 > len1 && memcmp(buf1, buf2, len1) == 0) { + torture_comment(test, "next codepoint is %u", + get_codepoint((char *)(buf2+len1), len2-len1, charset)); + } + if (len1 > len2 && memcmp(buf1, buf2, len2) == 0) { + torture_comment(test, "next codepoint is %u", + get_codepoint((char *)(buf1+len2),len1-len2, charset)); + } + + torture_fail(test, "failed"); + } + + /* convert back to UTF-16, putting result in buf3 */ + size = size - size_in1; + ptr_in = (const char *)buf1; + ptr_out = (char *)buf3; + size_in3 = len1; + outsize3 = sizeof(buf3); + + memset(ptr_out, 0, outsize3); + ret3 = smb_iconv(cd3, &ptr_in, &size_in3, &ptr_out, &outsize3); + + /* we only internally support the first 1M codepoints */ + if (outsize3 != sizeof(buf3) - size && + get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3), + size - (sizeof(buf3) - outsize3), + "UTF-16LE") >= (1<<20)) { + return true; + } + + torture_assert_int_equal(test, ret3, 0, talloc_asprintf(test, + "pull failed - %s", strerror(errno))); + + if (strncmp(charset, "UTF", 3) != 0) { + /* don't expect perfect mappings for non UTF charsets */ + return true; + } + + + torture_assert_int_equal(test, outsize3, sizeof(buf3) - size, + "wrong outsize3"); + + if (memcmp(buf3, inbuf, size) != 0) { + torture_comment(test, "pull bytes mismatch:"); + show_buf("inbuf", inbuf, size); + show_buf(" buf3", buf3, sizeof(buf3) - outsize3); + torture_comment(test, "next codepoint is %u\n", + get_codepoint((char *)(inbuf+sizeof(buf3) - outsize3), + size - (sizeof(buf3) - outsize3), + "UTF-16LE")); + torture_fail(test, ""); + } + + return true; +} + + +/* + test the push_codepoint() and next_codepoint() functions for a given + codepoint +*/ +static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) +{ + uint8_t buf[10]; + size_t size, size2; + codepoint_t c; + + size = push_codepoint((char *)buf, codepoint); + torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), + "Invalid Codepoint range"); + + if (size == -1) return true; + + buf[size] = random(); + buf[size+1] = random(); + buf[size+2] = random(); + buf[size+3] = random(); + + c = next_codepoint((char *)buf, &size2); + + torture_assert(tctx, c == codepoint, + talloc_asprintf(tctx, + "next_codepoint(%u) failed - gave %u", codepoint, c)); + + torture_assert(tctx, size2 == size, + talloc_asprintf(tctx, "next_codepoint(%u) gave wrong size %d (should be %d)\n", + codepoint, (int)size2, (int)size)); + + return true; +} + +static bool test_next_codepoint(struct torture_context *tctx) +{ + unsigned int codepoint; + if (iconv_untestable(tctx)) + return true; + + for (codepoint=0;codepoint<(1<<20);codepoint++) { + if (!test_codepoint(tctx, codepoint)) + return false; + } + return true; +} + +static bool test_first_1m(struct torture_context *tctx) +{ + unsigned int codepoint; + size_t size; + unsigned char inbuf[1000]; + + if (iconv_untestable(tctx)) + return true; + + for (codepoint=0;codepoint<(1<<20);codepoint++) { + if (gen_codepoint_utf16(codepoint, (char *)inbuf, &size) != 0) { + continue; + } + + if (codepoint % 1000 == 0) { + if (torture_setting_bool(tctx, "progress", true)) { + torture_comment(tctx, "codepoint=%u \r", codepoint); + fflush(stdout); + } + } + + if (!test_buffer(tctx, inbuf, size, "UTF-8")) + return false; + } + return true; +} + +static bool test_random_5m(struct torture_context *tctx) +{ + unsigned char inbuf[1000]; + unsigned int i; + + if (iconv_untestable(tctx)) + return true; + + for (i=0;i<500000;i++) { + size_t size; + unsigned int c; + + if (i % 1000 == 0) { + if (torture_setting_bool(tctx, "progress", true)) { + torture_comment(tctx, "i=%u \r", i); + fflush(stdout); + } + } + + size = random() % 100; + for (c=0;c. -*/ - -#include "includes.h" -#include "torture/torture.h" - -static bool test_toupper_w(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, toupper_w('c'), 'C', "c"); - torture_assert_int_equal(tctx, toupper_w('Z'), 'Z', "z"); - torture_assert_int_equal(tctx, toupper_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); - return true; -} - -static bool test_tolower_w(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, tolower_w('C'), 'c', "c"); - torture_assert_int_equal(tctx, tolower_w('z'), 'z', "z"); - torture_assert_int_equal(tctx, tolower_w(0xFFFF4565), 0xFFFF4565, "0xFFFF4565"); - return true; -} - -static bool test_codepoint_cmpi(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, codepoint_cmpi('a', 'a'), 0, "same char"); - torture_assert_int_equal(tctx, codepoint_cmpi('A', 'a'), 0, "upcase version"); - torture_assert_int_equal(tctx, codepoint_cmpi('b', 'a'), 1, "right diff"); - torture_assert_int_equal(tctx, codepoint_cmpi('a', 'b'), -1, "right diff"); - return true; -} - -static bool test_strcasecmp_m(struct torture_context *tctx) -{ - torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings"); - torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings"); - torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings"); - torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL"); - torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL"); - torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL"); - return true; -} - - -static bool test_strequal_w(struct torture_context *tctx) -{ - torture_assert(tctx, !strequal_w("foo", "bar"), "different strings"); - torture_assert(tctx, strequal_w("foo", "foo"), "same case strings"); - torture_assert(tctx, strequal_w("foo", "Foo"), "different case strings"); - torture_assert(tctx, !strequal_w(NULL, "Foo"), "one NULL"); - torture_assert(tctx, !strequal_w("foo", NULL), "other NULL"); - torture_assert(tctx, strequal_w(NULL, NULL), "both NULL"); - return true; -} - -static bool test_strcsequal_w(struct torture_context *tctx) -{ - torture_assert(tctx, !strcsequal_w("foo", "bar"), "different strings"); - torture_assert(tctx, strcsequal_w("foo", "foo"), "same case strings"); - torture_assert(tctx, !strcsequal_w("foo", "Foo"), "different case strings"); - torture_assert(tctx, !strcsequal_w(NULL, "Foo"), "one NULL"); - torture_assert(tctx, !strcsequal_w("foo", NULL), "other NULL"); - torture_assert(tctx, strcsequal_w(NULL, NULL), "both NULL"); - return true; -} - -static bool test_string_replace_w(struct torture_context *tctx) -{ - char data[6] = "bla"; - string_replace_w(data, 'b', 'c'); - torture_assert_str_equal(tctx, data, "cla", "first char replaced"); - memcpy(data, "bab", 4); - string_replace_w(data, 'b', 'c'); - torture_assert_str_equal(tctx, data, "cac", "other chars replaced"); - memcpy(data, "bba", 4); - string_replace_w(data, 'b', 'c'); - torture_assert_str_equal(tctx, data, "cca", "other chars replaced"); - memcpy(data, "blala", 6); - string_replace_w(data, 'o', 'c'); - torture_assert_str_equal(tctx, data, "blala", "no chars replaced"); - string_replace_w(NULL, 'b', 'c'); - return true; -} - -static bool test_strncasecmp_m(struct torture_context *tctx) -{ - torture_assert(tctx, strncasecmp_m("foo", "bar", 3) != 0, "different strings"); - torture_assert(tctx, strncasecmp_m("foo", "foo", 3) == 0, "same case strings"); - torture_assert(tctx, strncasecmp_m("foo", "Foo", 3) == 0, "different case strings"); - torture_assert(tctx, strncasecmp_m("fool", "Foo", 3) == 0, "different case strings"); - torture_assert(tctx, strncasecmp_m("fool", "Fool", 40) == 0, "over size"); - torture_assert(tctx, strncasecmp_m("BLA", "Fool", 0) == 0, "empty"); - torture_assert(tctx, strncasecmp_m(NULL, "Foo", 3) != 0, "one NULL"); - torture_assert(tctx, strncasecmp_m("foo", NULL, 3) != 0, "other NULL"); - torture_assert(tctx, strncasecmp_m(NULL, NULL, 3) == 0, "both NULL"); - return true; -} - -static bool test_next_token_null(struct torture_context *tctx) -{ - char buf[20]; - torture_assert(tctx, !next_token(NULL, buf, " ", 20), "null ptr works"); - return true; -} - -static bool test_next_token(struct torture_context *tctx) -{ - const char *teststr = "foo bar bla"; - char buf[20]; - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "foo", "token matches"); - torture_assert_str_equal(tctx, teststr, "bar bla", "ptr modified correctly"); - - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "bar", "token matches"); - torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); - - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "bla", "token matches"); - torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); - - torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); - return true; -} - -static bool test_next_token_implicit_sep(struct torture_context *tctx) -{ - const char *teststr = "foo\tbar\n bla"; - char buf[20]; - torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "foo", "token matches"); - torture_assert_str_equal(tctx, teststr, "bar\n bla", "ptr modified correctly"); - - torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "bar", "token matches"); - torture_assert_str_equal(tctx, teststr, " bla", "ptr modified correctly"); - - torture_assert(tctx, next_token(&teststr, buf, NULL, 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "bla", "token matches"); - torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); - - torture_assert(tctx, !next_token(&teststr, buf, NULL, 20), "finding token doesn't work"); - return true; -} - -static bool test_next_token_seps(struct torture_context *tctx) -{ - const char *teststr = ",foo bla"; - char buf[20]; - torture_assert(tctx, next_token(&teststr, buf, ",", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "foo bla", "token matches"); - torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); - - torture_assert(tctx, !next_token(&teststr, buf, ",", 20), "finding token doesn't work"); - return true; -} - -static bool test_next_token_quotes(struct torture_context *tctx) -{ - const char *teststr = "\"foo bar\" bla"; - char buf[20]; - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "foo bar", "token matches"); - torture_assert_str_equal(tctx, teststr, "bla", "ptr modified correctly"); - - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "bla", "token matches"); - torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); - - torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); - return true; -} - -static bool test_next_token_quote_wrong(struct torture_context *tctx) -{ - const char *teststr = "\"foo bar bla"; - char buf[20]; - torture_assert(tctx, next_token(&teststr, buf, " ", 20), "finding token works"); - torture_assert_str_equal(tctx, buf, "foo bar bla", "token matches"); - torture_assert_str_equal(tctx, teststr, "", "ptr modified correctly"); - - torture_assert(tctx, !next_token(&teststr, buf, " ", 20), "finding token doesn't work"); - return true; -} - -static bool test_strlen_m(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, strlen_m("foo"), 3, "simple len"); - torture_assert_int_equal(tctx, strlen_m("foo\x83l"), 6, "extended len"); - torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); - return true; -} - -static bool test_strlen_m_term(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, strlen_m_term("foo"), 4, "simple len"); - torture_assert_int_equal(tctx, strlen_m_term("foo\x83l"), 7, "extended len"); - torture_assert_int_equal(tctx, strlen_m(NULL), 0, "NULL"); - return true; -} - -static bool test_strhaslower(struct torture_context *tctx) -{ - torture_assert(tctx, strhaslower("a"), "one low char"); - torture_assert(tctx, strhaslower("aB"), "one low, one up char"); - torture_assert(tctx, !strhaslower("B"), "one up char"); - torture_assert(tctx, !strhaslower(""), "empty string"); - torture_assert(tctx, !strhaslower("3"), "one digit"); - return true; -} - -static bool test_strhasupper(struct torture_context *tctx) -{ - torture_assert(tctx, strhasupper("B"), "one up char"); - torture_assert(tctx, strhasupper("aB"), "one low, one up char"); - torture_assert(tctx, !strhasupper("a"), "one low char"); - torture_assert(tctx, !strhasupper(""), "empty string"); - torture_assert(tctx, !strhasupper("3"), "one digit"); - return true; -} - -static bool test_count_chars_w(struct torture_context *tctx) -{ - torture_assert_int_equal(tctx, count_chars_w("foo", 'o'), 2, "simple"); - torture_assert_int_equal(tctx, count_chars_w("", 'o'), 0, "empty"); - torture_assert_int_equal(tctx, count_chars_w("bla", 'o'), 0, "none"); - torture_assert_int_equal(tctx, count_chars_w("bla", '\0'), 0, "null"); - return true; -} - -struct torture_suite *torture_local_charset(TALLOC_CTX *mem_ctx) -{ - struct torture_suite *suite = torture_suite_create(mem_ctx, "CHARSET"); - - torture_suite_add_simple_test(suite, "toupper_w", test_toupper_w); - torture_suite_add_simple_test(suite, "tolower_w", test_tolower_w); - torture_suite_add_simple_test(suite, "codepoint_cmpi", test_codepoint_cmpi); - torture_suite_add_simple_test(suite, "strcasecmp_m", test_strcasecmp_m); - torture_suite_add_simple_test(suite, "strequal_w", test_strequal_w); - torture_suite_add_simple_test(suite, "strcsequal_w", test_strcsequal_w); - torture_suite_add_simple_test(suite, "string_replace_w", test_string_replace_w); - torture_suite_add_simple_test(suite, "strncasecmp_m", test_strncasecmp_m); - torture_suite_add_simple_test(suite, "next_token", test_next_token); - torture_suite_add_simple_test(suite, "next_token_null", test_next_token_null); - torture_suite_add_simple_test(suite, "next_token_implicit_sep", test_next_token_implicit_sep); - torture_suite_add_simple_test(suite, "next_token_quotes", test_next_token_quotes); - torture_suite_add_simple_test(suite, "next_token_seps", test_next_token_seps); - torture_suite_add_simple_test(suite, "next_token_quote_wrong", test_next_token_quote_wrong); - torture_suite_add_simple_test(suite, "strlen_m", test_strlen_m); - torture_suite_add_simple_test(suite, "strlen_m_term", test_strlen_m_term); - torture_suite_add_simple_test(suite, "strhaslower", test_strhaslower); - torture_suite_add_simple_test(suite, "strhasupper", test_strhasupper); - torture_suite_add_simple_test(suite, "count_chars_w", test_count_chars_w); - - return suite; -} -- cgit From ab5bbd26029e8ae62256c454daee14852b940a6a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 17:41:46 +0100 Subject: r26259: Provide convert_string_talloc() variant that works directly with an iconv handle. (This used to be commit a3efdfc8e390c923156c101416eb929a13f1dab8) --- source4/lib/charset/charcnv.c | 87 ++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 39 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 9c794202b2..804358d06b 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -60,7 +60,7 @@ static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /** re-initialize iconv conversion descriptors **/ -_PUBLIC_ void init_iconv(void) +_PUBLIC_ void close_iconv(void) { unsigned c1, c2; for (c1=0;c1 Date: Mon, 3 Dec 2007 18:47:35 +0100 Subject: r26264: pass name resolve order explicitly, use torture context for settings in dssync tests. (This used to be commit c7eae1c7842f9ff8b70cce9e5d6f3ebbbe78e83b) --- source4/lib/charset/tests/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index 259769d60f..9080dda40e 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -34,7 +34,7 @@ static bool iconv_untestable(struct torture_context *tctx) { iconv_t cd; - if (!lp_parm_bool(global_loadparm, NULL, "iconv", "native", true)) + if (!lp_parm_bool(tctx->lp_ctx, NULL, "iconv", "native", true)) torture_skip(tctx, "system iconv disabled - skipping test"); cd = iconv_open("UTF-16LE", "UCS-4LE"); -- cgit From 509e82e402d64c79f27c9a10d75b100a1ac5fefa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 23:33:22 +0100 Subject: r26272: Remove global_loadparm in some more places. (This used to be commit 1ab76ecc5311fa863e5d04899b6f110899818f55) --- source4/lib/charset/charcnv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 804358d06b..6bb72af8e1 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -274,7 +274,8 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_ if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, return -1*/ DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n", - charset_name(global_loadparm, from), charset_name(global_loadparm, to))); + charset_name(global_loadparm, from), + charset_name(global_loadparm, to))); return -1; } -- cgit From 6901b3c64a65d9745efac13f071225d5d2949f4d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 4 Dec 2007 01:51:44 +0100 Subject: r26278: Tallocify convenience table for iconv handles. (This used to be commit ad64b3baa4a5383c603d17ae75c33083af4690bb) --- source4/lib/charset/charcnv.c | 106 ++++++++++++++++++++++++++++-------------- source4/lib/charset/charset.h | 2 + 2 files changed, 73 insertions(+), 35 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 6bb72af8e1..bbb8f05226 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -38,16 +38,26 @@ * @sa lib/iconv.c */ +struct smb_iconv_convenience { + const char *unix_charset; + const char *dos_charset; + const char *display_charset; + 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(). **/ -static const char *charset_name(struct loadparm_context *lp_ctx, charset_t ch) +static const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) { switch (ch) { case CH_UTF16: return "UTF-16LE"; - case CH_UNIX: return lp_unix_charset(lp_ctx); - case CH_DOS: return lp_dos_charset(lp_ctx); - case CH_DISPLAY: return lp_display_charset(lp_ctx); + case CH_UNIX: return ic->unix_charset; + case CH_DOS: return ic->dos_charset; + case CH_DISPLAY: return ic->display_charset; case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; default: @@ -55,31 +65,57 @@ static const char *charset_name(struct loadparm_context *lp_ctx, charset_t ch) } } -static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; - /** re-initialize iconv conversion descriptors **/ -_PUBLIC_ void close_iconv(void) +static int close_iconv(struct smb_iconv_convenience *data) { unsigned c1, c2; for (c1=0;c1conv_handles[c1][c2] != NULL) { + if (data->conv_handles[c1][c2] != (smb_iconv_t)-1) { + smb_iconv_close(data->conv_handles[c1][c2]); } - conv_handles[c1][c2] = NULL; + data->conv_handles[c1][c2] = NULL; } } } + return 0; +} + +struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, + struct loadparm_context *lp_ctx) +{ + struct smb_iconv_convenience *ret = talloc_zero(mem_ctx, + struct smb_iconv_convenience); + + talloc_set_destructor(ret, close_iconv); + + ret->display_charset = talloc_strdup(ret, lp_display_charset(lp_ctx)); + ret->dos_charset = talloc_strdup(ret, lp_dos_charset(lp_ctx)); + ret->unix_charset = talloc_strdup(ret, lp_unix_charset(lp_ctx)); + + 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 */ -static smb_iconv_t get_conv_handle(struct loadparm_context *lp_ctx, +static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, charset_t from, charset_t to) { const char *n1, *n2; @@ -98,34 +134,33 @@ static smb_iconv_t get_conv_handle(struct loadparm_context *lp_ctx, */ setlocale(LC_ALL, "C"); #endif - - atexit(close_iconv); + atexit(free_global_smb_iconv_convenience); } - if (conv_handles[from][to]) { - return conv_handles[from][to]; + if (ic->conv_handles[from][to]) { + return ic->conv_handles[from][to]; } - n1 = charset_name(lp_ctx, from); - n2 = charset_name(lp_ctx, to); + n1 = charset_name(ic, from); + n2 = charset_name(ic, to); - conv_handles[from][to] = smb_iconv_open(n2,n1); + ic->conv_handles[from][to] = smb_iconv_open(n2,n1); - if (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) && - strcasecmp(charset_name(lp_ctx, CH_DOS), "ASCII") != 0) { + strcasecmp(charset_name(ic, CH_DOS), "ASCII") != 0) { DEBUG(0,("dos charset '%s' unavailable - using ASCII\n", - charset_name(lp_ctx, CH_DOS))); - lp_set_cmdline(lp_ctx, "dos charset", "ASCII"); + charset_name(ic, CH_DOS))); + ic->dos_charset = "ASCII"; - n1 = charset_name(lp_ctx, from); - n2 = charset_name(lp_ctx, to); + n1 = charset_name(ic, from); + n2 = charset_name(ic, to); - conv_handles[from][to] = smb_iconv_open(n2,n1); + ic->conv_handles[from][to] = smb_iconv_open(n2,n1); } } - return conv_handles[from][to]; + return ic->conv_handles[from][to]; } @@ -151,7 +186,7 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, if (srclen == (size_t)-1) srclen = strlen(inbuf)+1; - descriptor = get_conv_handle(global_loadparm, from, to); + descriptor = get_conv_handle(global_smb_iconv_convenience, from, to); if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, use as is */ @@ -173,12 +208,12 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, reason="No more room"; if (from == CH_UNIX) { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n", - charset_name(global_loadparm, from), charset_name(global_loadparm, to), + charset_name(global_smb_iconv_convenience, from), charset_name(global_smb_iconv_convenience, to), (int)srclen, (int)destlen, (const char *)src)); } else { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n", - charset_name(global_loadparm, from), charset_name(global_loadparm, to), + charset_name(global_smb_iconv_convenience, from), charset_name(global_smb_iconv_convenience, to), (int)srclen, (int)destlen)); } return -1; @@ -269,13 +304,13 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_ if (src == NULL || srclen == (size_t)-1 || srclen == 0) return (size_t)-1; - descriptor = get_conv_handle(global_loadparm, from, to); + descriptor = get_conv_handle(global_smb_iconv_convenience, from, to); if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, return -1*/ DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n", - charset_name(global_loadparm, from), - charset_name(global_loadparm, to))); + charset_name(global_smb_iconv_convenience, from), + charset_name(global_smb_iconv_convenience, to))); return -1; } @@ -631,7 +666,7 @@ _PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) ilen_orig = strnlen(str, 5); ilen = ilen_orig; - descriptor = get_conv_handle(global_loadparm, CH_UNIX, CH_UTF16); + descriptor = get_conv_handle(global_smb_iconv_convenience, CH_UNIX, CH_UTF16); if (descriptor == (smb_iconv_t)-1) { *size = 1; return INVALID_CODEPOINT; @@ -694,7 +729,8 @@ _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) return 1; } - descriptor = get_conv_handle(global_loadparm, CH_UTF16, CH_UNIX); + descriptor = get_conv_handle(global_smb_iconv_convenience, + CH_UTF16, CH_UNIX); if (descriptor == (smb_iconv_t)-1) { return -1; } diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index be2705100a..96762af85a 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -70,6 +70,8 @@ typedef struct smb_iconv_s { #define STR_TERMINATE_ASCII 128 /* only terminate if ascii */ #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */ +struct loadparm_context; + #include "lib/charset/charset_proto.h" /* replace some string functions with multi-byte -- cgit From b440ed3df31b11d520c6d744cf53c54165f61b7a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:16:40 +0100 Subject: r26315: Avoid using lp_ functions in libcharset. (This used to be commit db6dd425e3526c04e96d778a736dbb5cf14ddc56) --- source4/lib/charset/charcnv.c | 42 +++++++++++++++++---------------------- source4/lib/charset/iconv.c | 5 +++-- source4/lib/charset/tests/iconv.c | 4 ++-- 3 files changed, 23 insertions(+), 28 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index bbb8f05226..bbc40e3e3b 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -42,11 +42,10 @@ struct smb_iconv_convenience { const char *unix_charset; const char *dos_charset; const char *display_charset; + bool native_iconv; 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(). @@ -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 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); + struct smb_iconv_convenience); + + if (ret == NULL) { + return NULL; + } talloc_set_destructor(ret, close_iconv); - ret->display_charset = talloc_strdup(ret, lp_display_charset(lp_ctx)); - ret->dos_charset = talloc_strdup(ret, lp_dos_charset(lp_ctx)); - ret->unix_charset = talloc_strdup(ret, lp_unix_charset(lp_ctx)); + ret->dos_charset = talloc_strdup(ret, dos_charset); + ret->unix_charset = talloc_strdup(ret, unix_charset); + ret->display_charset = talloc_strdup(ret, display_charset); + ret->native_iconv = native_iconv; 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 */ @@ -120,8 +115,7 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, { const char *n1, *n2; static int initialised; - /* auto-free iconv memory on exit so valgrind reports are easier - to look at */ + if (initialised == 0) { initialised = 1; @@ -134,7 +128,6 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, */ setlocale(LC_ALL, "C"); #endif - atexit(free_global_smb_iconv_convenience); } 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); 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 ((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); 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); } } diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 9b035cd1db..937b3ec8b5 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -157,7 +157,8 @@ static bool is_utf16(const char *name) /* 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; 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 - if ((!from || !to) && !lp_parm_bool(global_loadparm, NULL, "iconv", "native", true)) { + if ((!from || !to) && !native_iconv) { goto failed; } if (!from) { diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index 9080dda40e..bc5ae62dae 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -157,8 +157,8 @@ static bool test_buffer(struct torture_context *test, "failed to open %s to UTF-16LE", charset)); } - cd2 = smb_iconv_open(charset, "UTF-16LE"); - cd3 = smb_iconv_open("UTF-16LE", charset); + cd2 = smb_iconv_open(charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); + cd3 = smb_iconv_open("UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); last_charset = charset; } -- cgit From 39ee38d9c1aabf4db065b433d067d0da053d7d61 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:52:23 +0100 Subject: r26316: Use contexts for conversion functions. (This used to be commit f6420d933b5b011d428974f3a2a57edf19e6f482) --- source4/lib/charset/charcnv.c | 97 ++++++++++++++++++++++----------------- source4/lib/charset/charset.h | 2 + source4/lib/charset/tests/iconv.c | 4 +- source4/lib/charset/util_unistr.c | 38 +++++++-------- 4 files changed, 77 insertions(+), 64 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index bbc40e3e3b..83bd11563f 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -4,6 +4,7 @@ Copyright (C) Igor Vergeichik 2001 Copyright (C) Andrew Tridgell 2001 Copyright (C) Simo Sorce 2001 + Copyright (C) Jelmer Vernooij 2007 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 @@ -167,9 +168,10 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, * @param destlen maximal length allowed for string * @returns the number of bytes occupied in the destination **/ -_PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, - void const *src, size_t srclen, - void *dest, size_t destlen) +_PUBLIC_ ssize_t convert_string(struct smb_iconv_convenience *ic, + charset_t from, charset_t to, + void const *src, size_t srclen, + void *dest, size_t destlen) { size_t i_len, o_len; size_t retval; @@ -180,7 +182,7 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, if (srclen == (size_t)-1) srclen = strlen(inbuf)+1; - descriptor = get_conv_handle(global_smb_iconv_convenience, from, to); + descriptor = get_conv_handle(ic, from, to); if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, use as is */ @@ -202,12 +204,12 @@ _PUBLIC_ ssize_t convert_string(charset_t from, charset_t to, reason="No more room"; if (from == CH_UNIX) { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d - '%s'\n", - charset_name(global_smb_iconv_convenience, from), charset_name(global_smb_iconv_convenience, to), + charset_name(ic, from), charset_name(ic, to), (int)srclen, (int)destlen, (const char *)src)); } else { DEBUG(0,("E2BIG: convert_string(%s,%s): srclen=%d destlen=%d\n", - charset_name(global_smb_iconv_convenience, from), charset_name(global_smb_iconv_convenience, to), + charset_name(ic, from), charset_name(ic, to), (int)srclen, (int)destlen)); } return -1; @@ -288,8 +290,11 @@ convert: * @returns Size in bytes of the converted string; or -1 in case of error. **/ -_PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, - void const *src, size_t srclen, void **dest) +_PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, + struct smb_iconv_convenience *ic, + charset_t from, charset_t to, + void const *src, size_t srclen, + void **dest) { smb_iconv_t descriptor; @@ -298,13 +303,13 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_ if (src == NULL || srclen == (size_t)-1 || srclen == 0) return (size_t)-1; - descriptor = get_conv_handle(global_smb_iconv_convenience, from, to); + descriptor = get_conv_handle(ic, from, to); if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) { /* conversion not supported, return -1*/ DEBUG(3, ("convert_string_talloc: conversion from %s to %s not supported!\n", - charset_name(global_smb_iconv_convenience, from), - charset_name(global_smb_iconv_convenience, to))); + charset_name(ic, from), + charset_name(ic, to))); return -1; } @@ -325,7 +330,8 @@ _PUBLIC_ ssize_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_ * @param dest_len the maximum length in bytes allowed in the * destination. If @p dest_len is -1 then no maximum is used. **/ -static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flags) +static ssize_t push_ascii(struct smb_iconv_convenience *ic, + void *dest, const char *src, size_t dest_len, int flags) { size_t src_len; ssize_t ret; @@ -335,7 +341,7 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag if (tmpbuf == NULL) { return -1; } - ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + ret = push_ascii(ic, dest, tmpbuf, dest_len, flags & ~STR_UPPER); talloc_free(tmpbuf); return ret; } @@ -345,7 +351,7 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag if (flags & (STR_TERMINATE | STR_TERMINATE_ASCII)) src_len++; - return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len); + return convert_string(ic, CH_UNIX, CH_DOS, src, src_len, dest, dest_len); } /** @@ -357,11 +363,11 @@ static ssize_t push_ascii(void *dest, const char *src, size_t dest_len, int flag * @returns The number of bytes occupied by the string in the destination * or -1 in case of error. **/ -_PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +_PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest); + return convert_string_talloc(ctx, ic, CH_UNIX, CH_DOS, src, src_len, (void **)dest); } @@ -380,7 +386,7 @@ _PUBLIC_ ssize_t push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src * @param src_len is the length of the source area in bytes. * @returns the number of bytes occupied by the string in @p src. **/ -static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static ssize_t pull_ascii(struct smb_iconv_convenience *ic, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -395,7 +401,7 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s } } - ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); + ret = convert_string(ic, CH_DOS, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -419,7 +425,8 @@ static ssize_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t s * @param dest_len is the maximum length allowed in the * destination. If dest_len is -1 then no maxiumum is used. **/ -static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags) +static ssize_t push_ucs2(struct smb_iconv_convenience *ic, + void *dest, const char *src, size_t dest_len, int flags) { size_t len=0; size_t src_len = strlen(src); @@ -430,7 +437,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags if (tmpbuf == NULL) { return -1; } - ret = push_ucs2(dest, tmpbuf, dest_len, flags & ~STR_UPPER); + ret = push_ucs2(ic, dest, tmpbuf, dest_len, flags & ~STR_UPPER); talloc_free(tmpbuf); return ret; } @@ -448,7 +455,7 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags /* ucs2 is always a multiple of 2 bytes */ dest_len &= ~1; - ret = convert_string(CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); + ret = convert_string(ic, CH_UNIX, CH_UTF16, src, src_len, dest, dest_len); if (ret == (size_t)-1) { return 0; } @@ -468,11 +475,11 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags * @returns The number of bytes occupied by the string in the destination * or -1 in case of error. **/ -_PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) +_PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, void **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, dest); + return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF16, src, src_len, dest); } @@ -484,11 +491,11 @@ _PUBLIC_ ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, void **dest, const char *src) * @returns The number of bytes occupied by the string in the destination **/ -_PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +_PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); + return convert_string_talloc(ctx, ic, CH_UNIX, CH_UTF8, src, src_len, (void **)dest); } /** @@ -502,7 +509,7 @@ _PUBLIC_ ssize_t push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) The resulting string in "dest" is always null terminated. **/ -static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static size_t pull_ucs2(struct smb_iconv_convenience *ic, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -524,7 +531,7 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src if (src_len != (size_t)-1) src_len &= ~1; - ret = convert_string(CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); + ret = convert_string(ic, CH_UTF16, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -539,11 +546,11 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src * @returns The number of bytes occupied by the string in the destination **/ -_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +_PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, ic, CH_DOS, CH_UNIX, src, src_len, (void **)dest); } /** @@ -554,11 +561,11 @@ _PUBLIC_ ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src * @returns The number of bytes occupied by the string in the destination **/ -_PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) +_PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const void *src) { size_t src_len = utf16_len(src); *dest = NULL; - return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, ic, CH_UTF16, CH_UNIX, src, src_len, (void **)dest); } /** @@ -569,11 +576,11 @@ _PUBLIC_ ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const void *src) * @returns The number of bytes occupied by the string in the destination **/ -_PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) +_PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src) { size_t src_len = strlen(src)+1; *dest = NULL; - return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); + return convert_string_talloc(ctx, ic, CH_UTF8, CH_UNIX, src, src_len, (void **)dest); } /** @@ -590,12 +597,13 @@ _PUBLIC_ ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src) is -1 then no maxiumum is used. **/ -_PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags) +_PUBLIC_ ssize_t push_string(struct smb_iconv_convenience *ic, + void *dest, const char *src, size_t dest_len, int flags) { if (flags & STR_ASCII) { - return push_ascii(dest, src, dest_len, flags); + return push_ascii(ic, dest, src, dest_len, flags); } else if (flags & STR_UNICODE) { - return push_ucs2(dest, src, dest_len, flags); + return push_ucs2(ic, dest, src, dest_len, flags); } else { smb_panic("push_string requires either STR_ASCII or STR_UNICODE flag to be set"); return -1; @@ -617,12 +625,13 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f The resulting string in "dest" is always null terminated. **/ -_PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +_PUBLIC_ ssize_t pull_string(struct smb_iconv_convenience *ic, + char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { if (flags & STR_ASCII) { - return pull_ascii(dest, src, dest_len, src_len, flags); + return pull_ascii(ic, dest, src, dest_len, src_len, flags); } else if (flags & STR_UNICODE) { - return pull_ucs2(dest, src, dest_len, src_len, flags); + return pull_ucs2(ic, dest, src, dest_len, src_len, flags); } else { smb_panic("pull_string requires either STR_ASCII or STR_UNICODE flag to be set"); return -1; @@ -639,7 +648,8 @@ _PUBLIC_ ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_ return INVALID_CODEPOINT if the next character cannot be converted */ -_PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) +_PUBLIC_ codepoint_t next_codepoint(struct smb_iconv_convenience *ic, + const char *str, size_t *size) { /* it cannot occupy more than 4 bytes in UTF16 format */ uint8_t buf[4]; @@ -660,7 +670,7 @@ _PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) ilen_orig = strnlen(str, 5); ilen = ilen_orig; - descriptor = get_conv_handle(global_smb_iconv_convenience, CH_UNIX, CH_UTF16); + descriptor = get_conv_handle(ic, CH_UNIX, CH_UTF16); if (descriptor == (smb_iconv_t)-1) { *size = 1; return INVALID_CODEPOINT; @@ -711,7 +721,8 @@ _PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) return the number of bytes occupied by the CH_UNIX character, or -1 on failure */ -_PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) +_PUBLIC_ ssize_t push_codepoint(struct smb_iconv_convenience *ic, + char *str, codepoint_t c) { smb_iconv_t descriptor; uint8_t buf[4]; @@ -723,7 +734,7 @@ _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) return 1; } - descriptor = get_conv_handle(global_smb_iconv_convenience, + descriptor = get_conv_handle(ic, CH_UTF16, CH_UNIX); if (descriptor == (smb_iconv_t)-1) { return -1; diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 96762af85a..b1bb18a7c8 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -71,6 +71,8 @@ typedef struct smb_iconv_s { #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */ struct loadparm_context; +struct smb_iconv_convenience; +extern struct smb_iconv_convenience *global_smb_iconv_convenience; #include "lib/charset/charset_proto.h" diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index bc5ae62dae..ca13dc503a 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -288,7 +288,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) size_t size, size2; codepoint_t c; - size = push_codepoint((char *)buf, codepoint); + size = push_codepoint(global_smb_iconv_convenience, (char *)buf, codepoint); torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), "Invalid Codepoint range"); @@ -299,7 +299,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) buf[size+2] = random(); buf[size+3] = random(); - c = next_codepoint((char *)buf, &size2); + c = next_codepoint(global_smb_iconv_convenience, (char *)buf, &size2); torture_assert(tctx, c == codepoint, talloc_asprintf(tctx, diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index e9cca090cc..67a790c250 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -129,8 +129,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (s2 == NULL) return 1; while (*s1 && *s2) { - c1 = next_codepoint(s1, &size1); - c2 = next_codepoint(s2, &size2); + c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); + c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); s1 += size1; s2 += size2; @@ -215,8 +215,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) while (*s1 && *s2 && n) { n--; - c1 = next_codepoint(s1, &size1); - c2 = next_codepoint(s2, &size2); + c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); + c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); s1 += size1; s2 += size2; @@ -275,7 +275,7 @@ _PUBLIC_ void string_replace_w(char *s, char oldc, char newc) { while (s && *s) { size_t size; - codepoint_t c = next_codepoint(s, &size); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &size); if (c == oldc) { *s = newc; } @@ -353,7 +353,7 @@ _PUBLIC_ size_t strlen_m(const char *s) while (*s) { size_t c_size; - codepoint_t c = next_codepoint(s, &c_size); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); if (c < 0x10000) { count += 1; } else { @@ -391,7 +391,7 @@ _PUBLIC_ char *strchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(s, &size); + codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); if (c2 == c) { return discard_const_p(char, s); } @@ -416,7 +416,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(s, &size); + codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); if (c2 == c) { ret = discard_const_p(char, s); } @@ -436,7 +436,7 @@ _PUBLIC_ bool strhaslower(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(string, &c_size); + s = next_codepoint(global_smb_iconv_convenience, string, &c_size); string += c_size; t = toupper_w(s); @@ -459,7 +459,7 @@ _PUBLIC_ bool strhasupper(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(string, &c_size); + s = next_codepoint(global_smb_iconv_convenience, string, &c_size); string += c_size; t = tolower_w(s); @@ -489,12 +489,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(src, &c_size); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); src += c_size; c = tolower_w(c); - c_size = push_codepoint(dest+size, c); + c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -533,12 +533,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(src, &c_size); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); src += c_size; c = toupper_w(c); - c_size = push_codepoint(dest+size, c); + c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -579,8 +579,8 @@ _PUBLIC_ void strlower_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(s, &c_size); - c_size2 = push_codepoint(d, tolower_w(c)); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); + c_size2 = push_codepoint(global_smb_iconv_convenience, d, tolower_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", c, tolower_w(c), (int)c_size, (int)c_size2)); @@ -615,8 +615,8 @@ _PUBLIC_ void strupper_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(s, &c_size); - c_size2 = push_codepoint(d, toupper_w(c)); + codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); + c_size2 = push_codepoint(global_smb_iconv_convenience, d, toupper_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", c, toupper_w(c), (int)c_size, (int)c_size2)); @@ -638,7 +638,7 @@ _PUBLIC_ size_t count_chars_w(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(s, &size); + codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); if (c2 == c) count++; s += size; } -- cgit From b8850f326befab8a745e2b880214159908e7ec58 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Dec 2007 02:15:42 +0100 Subject: r26410: Remove unnecessary static. (This used to be commit 13ae3108dad2f9f0f7a421d672751fa594f4e3fb) --- source4/lib/charset/charcnv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 83bd11563f..5100a1b016 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -115,10 +115,10 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, charset_t from, charset_t to) { const char *n1, *n2; - static int initialised; + static bool initialised; - if (initialised == 0) { - initialised = 1; + if (initialised == false) { + initialised = true; #ifdef LC_ALL /* we set back the locale to C to get ASCII-compatible -- cgit From a5b8999f23d56b4a19b87fc17b22c96f88e487e8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 12:19:33 +0100 Subject: r26427: Avoid global_smb_iconv_convenience. (This used to be commit bf072c6fb37b3e6a71c0c747b9fbeaa01480229e) --- source4/lib/charset/tests/iconv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index ca13dc503a..d47390b814 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -288,7 +288,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) size_t size, size2; codepoint_t c; - size = push_codepoint(global_smb_iconv_convenience, (char *)buf, codepoint); + size = push_codepoint(lp_iconv_convenience(tctx->lp_ctx), (char *)buf, codepoint); torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), "Invalid Codepoint range"); @@ -299,7 +299,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) buf[size+2] = random(); buf[size+3] = random(); - c = next_codepoint(global_smb_iconv_convenience, (char *)buf, &size2); + c = next_codepoint(lp_iconv_convenience(tctx->lp_ctx), (char *)buf, &size2); torture_assert(tctx, c == codepoint, talloc_asprintf(tctx, -- cgit From d891c0c74a03d797aed1c5ac0329fd9d1d78da63 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:09 +0100 Subject: r26429: Avoid use of global_smb_iconv_convenience. (This used to be commit d37136b7abfbba75ef2e5ab855eb3382b9648b8c) --- source4/lib/charset/util_unistr.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 67a790c250..e0e1aed222 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -21,6 +21,7 @@ #include "includes.h" #include "system/locale.h" #include "dynconfig.h" +#include "param/param.h" /** * @file @@ -129,8 +130,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (s2 == NULL) return 1; while (*s1 && *s2) { - c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); - c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); + c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); s1 += size1; s2 += size2; @@ -215,8 +216,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) while (*s1 && *s2 && n) { n--; - c1 = next_codepoint(global_smb_iconv_convenience, s1, &size1); - c2 = next_codepoint(global_smb_iconv_convenience, s2, &size2); + c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); + c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); s1 += size1; s2 += size2; @@ -275,7 +276,7 @@ _PUBLIC_ void string_replace_w(char *s, char oldc, char newc) { while (s && *s) { size_t size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c == oldc) { *s = newc; } @@ -353,7 +354,7 @@ _PUBLIC_ size_t strlen_m(const char *s) while (*s) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); if (c < 0x10000) { count += 1; } else { @@ -391,7 +392,7 @@ _PUBLIC_ char *strchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) { return discard_const_p(char, s); } @@ -416,7 +417,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) { ret = discard_const_p(char, s); } @@ -436,7 +437,7 @@ _PUBLIC_ bool strhaslower(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(global_smb_iconv_convenience, string, &c_size); + s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); string += c_size; t = toupper_w(s); @@ -459,7 +460,7 @@ _PUBLIC_ bool strhasupper(const char *string) codepoint_t s; codepoint_t t; - s = next_codepoint(global_smb_iconv_convenience, string, &c_size); + s = next_codepoint(lp_iconv_convenience(global_loadparm), string, &c_size); string += c_size; t = tolower_w(s); @@ -489,12 +490,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); src += c_size; c = tolower_w(c); - c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); + c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -533,12 +534,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); src += c_size; c = toupper_w(c); - c_size = push_codepoint(global_smb_iconv_convenience, dest+size, c); + c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -579,8 +580,8 @@ _PUBLIC_ void strlower_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); - c_size2 = push_codepoint(global_smb_iconv_convenience, d, tolower_w(c)); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); + c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, tolower_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", c, tolower_w(c), (int)c_size, (int)c_size2)); @@ -615,8 +616,8 @@ _PUBLIC_ void strupper_m(char *s) while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(global_smb_iconv_convenience, s, &c_size); - c_size2 = push_codepoint(global_smb_iconv_convenience, d, toupper_w(c)); + codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); + c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, toupper_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", c, toupper_w(c), (int)c_size, (int)c_size2)); @@ -638,7 +639,7 @@ _PUBLIC_ size_t count_chars_w(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint(global_smb_iconv_convenience, s, &size); + codepoint_t c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s, &size); if (c2 == c) count++; s += size; } -- cgit From 2bf0cdd01cf399bf28125f9e2a0d419f4e94996c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:33 +0100 Subject: r26434: Remove display charset from iconv convenience context. (This used to be commit a76625994abf9906d54ae11f9c171f89063cf508) --- source4/lib/charset/charcnv.c | 4 ---- source4/lib/charset/charset.h | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 5100a1b016..9a4068a4a9 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -42,7 +42,6 @@ struct smb_iconv_convenience { const char *unix_charset; const char *dos_charset; - const char *display_charset; bool native_iconv; smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; }; @@ -57,7 +56,6 @@ static const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) case CH_UTF16: return "UTF-16LE"; case CH_UNIX: return ic->unix_charset; case CH_DOS: return ic->dos_charset; - case CH_DISPLAY: return ic->display_charset; case CH_UTF8: return "UTF8"; case CH_UTF16BE: return "UTF-16BE"; default: @@ -88,7 +86,6 @@ static int close_iconv(struct smb_iconv_convenience *data) struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_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, @@ -102,7 +99,6 @@ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, ret->dos_charset = talloc_strdup(ret, dos_charset); ret->unix_charset = talloc_strdup(ret, unix_charset); - ret->display_charset = talloc_strdup(ret, display_charset); ret->native_iconv = native_iconv; return ret; diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index b1bb18a7c8..1d42a0ad91 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -24,9 +24,9 @@ #include /* this defines the charset types used in samba */ -typedef enum {CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t; +typedef enum {CH_UTF16=0, CH_UNIX, CH_DOS, CH_UTF8, CH_UTF16BE} charset_t; -#define NUM_CHARSETS 6 +#define NUM_CHARSETS 5 /* * for each charset we have a function that pulls from that charset to -- cgit From 92d42862ddb6748a4fbd001bd8f7c785627cba74 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 16 Dec 2007 16:19:43 +0100 Subject: r26476: Remove unnecessary hack. (This used to be commit 827632ab6e00bacef45c15efc626a1ef587c0915) --- source4/lib/charset/config.mk | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index b2035672ba..4f0c80c79d 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -9,6 +9,5 @@ PUBLIC_HEADERS = charset.h PUBLIC_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG -LDFLAGS = bin/static/libsamba-config.a bin/static/libsamba-util.a # End SUBSYSTEM CHARSET ################################################ -- cgit From 01b96e47cd77c345ac27c4c882e353852e49f22b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 17 Dec 2007 08:32:00 +0100 Subject: r26498: Fix memory leak in iconv code. (This used to be commit 8795697db56e4ca6715950d68f5ec370604fcc76) --- source4/lib/charset/charcnv.c | 7 ++++--- source4/lib/charset/iconv.c | 20 ++++++++++++++------ source4/lib/charset/tests/iconv.c | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 9a4068a4a9..54a0676599 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -134,7 +134,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, n1 = charset_name(ic, from); n2 = charset_name(ic, to); - ic->conv_handles[from][to] = smb_iconv_open(n2, n1, ic->native_iconv); + ic->conv_handles[from][to] = smb_iconv_open_ex(ic, n2, n1, + ic->native_iconv); if (ic->conv_handles[from][to] == (smb_iconv_t)-1) { if ((from == CH_DOS || to == CH_DOS) && @@ -146,8 +147,8 @@ static smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, n1 = charset_name(ic, from); n2 = charset_name(ic, to); - ic->conv_handles[from][to] = smb_iconv_open(n2, n1, - ic->native_iconv); + ic->conv_handles[from][to] = + smb_iconv_open_ex(ic, n2, n1, ic->native_iconv); } } diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 937b3ec8b5..db212a83c4 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -154,17 +154,17 @@ static bool is_utf16(const char *name) strcasecmp(name, "UTF-16LE") == 0; } -/* - simple iconv_open() wrapper - */ -smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode, - bool native_iconv) + + +smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, + const char *fromcode, bool native_iconv) { smb_iconv_t ret; const struct charset_functions *from=NULL, *to=NULL; int i; - ret = (smb_iconv_t)talloc_named(NULL, sizeof(*ret), + ret = (smb_iconv_t)talloc_named(mem_ctx, + sizeof(*ret), "iconv(%s,%s)", tocode, fromcode); if (!ret) { errno = ENOMEM; @@ -260,6 +260,14 @@ failed: return (smb_iconv_t)-1; } +/* + simple iconv_open() wrapper + */ +smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) +{ + return smb_iconv_open_ex(NULL, tocode, fromcode, true); +} + /* simple iconv_close() wrapper */ diff --git a/source4/lib/charset/tests/iconv.c b/source4/lib/charset/tests/iconv.c index d47390b814..aeb42c2fa1 100644 --- a/source4/lib/charset/tests/iconv.c +++ b/source4/lib/charset/tests/iconv.c @@ -157,8 +157,8 @@ static bool test_buffer(struct torture_context *test, "failed to open %s to UTF-16LE", charset)); } - cd2 = smb_iconv_open(charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); - cd3 = smb_iconv_open("UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); + cd2 = smb_iconv_open_ex(test, charset, "UTF-16LE", lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); + cd3 = smb_iconv_open_ex(test, "UTF-16LE", charset, lp_parm_bool(test->lp_ctx, NULL, "iconv", "native", true)); last_charset = charset; } -- cgit From 426e7fef1f080f22a10e89cebae58a40db8bc77f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 16:10:07 +0100 Subject: Remove extra whitespace, use public variable in IDL. (This used to be commit bf08b682586f6b9a17d4ec3934836be957ef955c) --- source4/lib/charset/charcnv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 54a0676599..0465be689e 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -677,7 +677,7 @@ _PUBLIC_ codepoint_t next_codepoint(struct smb_iconv_convenience *ic, with codepoints above 64k */ olen = 2; outbuf = (char *)buf; - smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); + smb_iconv(descriptor, &str, &ilen, &outbuf, &olen); if (olen == 2) { olen = 4; outbuf = (char *)buf; -- cgit From f112578843bcc757bf0b2ee56d8bd8d318b53610 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Feb 2008 23:09:56 +0100 Subject: Remove public prototype headers. Generating both public and private prototype headers is tricky with gmake and it's easy to break backwards compatibility for the public API with them. (This used to be commit dee1cb6b08aa0a3e24372e052729121c11280971) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 4f0c80c79d..2dd5b05c94 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -6,7 +6,7 @@ OBJ_FILES = \ charcnv.o \ util_unistr.o PUBLIC_HEADERS = charset.h -PUBLIC_PROTO_HEADER = charset_proto.h +PRIVATE_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET -- cgit From c5d77a1c2414d930ccbedbe05e124df69242a144 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 26 Feb 2008 17:17:52 +0100 Subject: Move public header accumulation out of the perl code. (This used to be commit 89f7c74924965071981bbe7e05ff69847b0a3a03) --- source4/lib/charset/config.mk | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 2dd5b05c94..2766784c52 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -5,9 +5,11 @@ OBJ_FILES = \ iconv.o \ charcnv.o \ util_unistr.o -PUBLIC_HEADERS = charset.h PRIVATE_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ + + +PUBLIC_HEADERS += lib/charset/charset.h -- cgit From d70eafc5c635255feafc7121b381e7044ac11854 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 16:41:38 +0100 Subject: Cache iconv_convenience. (This used to be commit fe1d3e69990a71d7639ac8718f6ca51de4d7e6d2) --- source4/lib/charset/util_unistr.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index e0e1aed222..9b87f49800 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -123,6 +123,7 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) { codepoint_t c1=0, c2=0; size_t size1, size2; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -130,8 +131,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (s2 == NULL) return 1; while (*s1 && *s2) { - c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); - c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); + c1 = next_codepoint(iconv_convenience, s1, &size1); + c2 = next_codepoint(iconv_convenience, s2, &size2); s1 += size1; s2 += size2; @@ -207,6 +208,7 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) { codepoint_t c1=0, c2=0; size_t size1, size2; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -216,8 +218,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) while (*s1 && *s2 && n) { n--; - c1 = next_codepoint(lp_iconv_convenience(global_loadparm), s1, &size1); - c2 = next_codepoint(lp_iconv_convenience(global_loadparm), s2, &size2); + c1 = next_codepoint(iconv_convenience, s1, &size1); + c2 = next_codepoint(iconv_convenience, s2, &size2); s1 += size1; s2 += size2; @@ -480,6 +482,7 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) { size_t size=0; char *dest; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); /* this takes advantage of the fact that upper/lower can't change the length of a character by more than 1 byte */ @@ -490,12 +493,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); + codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); src += c_size; c = tolower_w(c); - c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); + c_size = push_codepoint(iconv_convenience, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -520,6 +523,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) { size_t size=0; char *dest; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); if (!src) { return NULL; @@ -534,12 +538,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), src, &c_size); + codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); src += c_size; c = toupper_w(c); - c_size = push_codepoint(lp_iconv_convenience(global_loadparm), dest+size, c); + c_size = push_codepoint(iconv_convenience, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -563,6 +567,7 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) _PUBLIC_ void strlower_m(char *s) { char *d; + struct smb_iconv_convenience *iconv_convenience; /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our @@ -576,12 +581,14 @@ _PUBLIC_ void strlower_m(char *s) if (!*s) return; + iconv_convenience = lp_iconv_convenience(global_loadparm); + d = s; while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); - c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, tolower_w(c)); + codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); + c_size2 = push_codepoint(iconv_convenience, d, tolower_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", c, tolower_w(c), (int)c_size, (int)c_size2)); @@ -599,6 +606,7 @@ _PUBLIC_ void strlower_m(char *s) _PUBLIC_ void strupper_m(char *s) { char *d; + struct smb_iconv_convenience *iconv_convenience; /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our @@ -612,12 +620,14 @@ _PUBLIC_ void strupper_m(char *s) if (!*s) return; + iconv_convenience = lp_iconv_convenience(global_loadparm); + d = s; while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint(lp_iconv_convenience(global_loadparm), s, &c_size); - c_size2 = push_codepoint(lp_iconv_convenience(global_loadparm), d, toupper_w(c)); + codepoint_t c = next_codepoint(iconv_convenience, s, &c_size); + c_size2 = push_codepoint(iconv_convenience, d, toupper_w(c)); if (c_size2 > c_size) { DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", c, toupper_w(c), (int)c_size, (int)c_size2)); -- cgit From 1ada7108408f567f61cfbf2b625730ba898452db Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 29 Feb 2008 14:23:38 +0100 Subject: Move public header accumulation out of the perl code. Never install generated prototype files. It's easier to break the API when using them and they're not easily readable for 3rd party users. Conflicts: source/auth/config.mk source/auth/credentials/config.mk source/auth/gensec/config.mk source/build/smb_build/config_mk.pm source/build/smb_build/main.pl source/build/smb_build/makefile.pm source/dsdb/config.mk source/lib/charset/config.mk source/lib/tdr/config.mk source/lib/util/config.mk source/libcli/config.mk source/libcli/ldap/config.mk source/librpc/config.mk source/param/config.mk source/rpc_server/config.mk source/torture/config.mk (This used to be commit 6c659689ed4081f1d7a6253c538c7f01784197ba) --- source4/lib/charset/config.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 4f0c80c79d..2766784c52 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -5,9 +5,11 @@ OBJ_FILES = \ iconv.o \ charcnv.o \ util_unistr.o -PUBLIC_HEADERS = charset.h -PUBLIC_PROTO_HEADER = charset_proto.h +PRIVATE_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ + + +PUBLIC_HEADERS += lib/charset/charset.h -- cgit From b29d47edcf2767d7f9e9f63332079c6e8e89946c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Mar 2008 18:25:28 +0100 Subject: Move object file lists to the Makefile. (This used to be commit a7e6d2a1832db388fdafa1279f84c9a8bbfc87d6) --- source4/lib/charset/config.mk | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 2766784c52..e5e5bd4560 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -1,15 +1,12 @@ ################################################ # Start SUBSYSTEM CHARSET [SUBSYSTEM::CHARSET] -OBJ_FILES = \ - iconv.o \ - charcnv.o \ - util_unistr.o PRIVATE_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ +CHARSET_OBJ_FILES = $(addprefix lib/charset/, iconv.o charcnv.o util_unistr.o) PUBLIC_HEADERS += lib/charset/charset.h -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/lib/charset/charcnv.c | 2 +- source4/lib/charset/charset.h | 68 +++++++++++++++++++++++++++++++++++++-- source4/lib/charset/iconv.c | 8 ++--- source4/lib/charset/util_unistr.c | 6 ++-- 4 files changed, 74 insertions(+), 10 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charcnv.c b/source4/lib/charset/charcnv.c index 0465be689e..3e384304cf 100644 --- a/source4/lib/charset/charcnv.c +++ b/source4/lib/charset/charcnv.c @@ -83,7 +83,7 @@ static int close_iconv(struct smb_iconv_convenience *data) return 0; } -struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, +_PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, const char *dos_charset, const char *unix_charset, bool native_iconv) diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index 1d42a0ad91..baa7df532b 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -18,6 +18,10 @@ along with this program. If not, see . */ +/* This is a public header file that is installed as part of Samba. + * If you remove any functions or change their signature, update + * the so version number. */ + #ifndef __CHARSET_H__ #define __CHARSET_H__ @@ -74,11 +78,71 @@ struct loadparm_context; struct smb_iconv_convenience; extern struct smb_iconv_convenience *global_smb_iconv_convenience; -#include "lib/charset/charset_proto.h" - /* replace some string functions with multi-byte versions */ #define strlower(s) strlower_m(s) #define strupper(s) strupper_m(s) +char *strchr_m(const char *s, char c); +size_t strlen_m_term(const char *s); +size_t strlen_m(const char *s); +char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength); +void string_replace_w(char *s, char oldc, char newc); +bool strcsequal_w(const char *s1,const char *s2); +bool strequal_w(const char *s1, const char *s2); +int strncasecmp_m(const char *s1, const char *s2, size_t n); +bool next_token(const char **ptr,char *buff, const char *sep, size_t bufsize); +int strcasecmp_m(const char *s1, const char *s2); +size_t count_chars_w(const char *s, char c); +void strupper_m(char *s); +void strlower_m(char *s); +char *strupper_talloc(TALLOC_CTX *ctx, const char *src); +char *strlower_talloc(TALLOC_CTX *ctx, const char *src); +bool strhasupper(const char *string); +bool strhaslower(const char *string); +char *strrchr_m(const char *s, char c); +char *strchr_m(const char *s, char c); + +/* codepoints */ +codepoint_t next_codepoint(struct smb_iconv_convenience *ic, + const char *str, size_t *size); +ssize_t push_codepoint(struct smb_iconv_convenience *ic, + char *str, codepoint_t c); +codepoint_t toupper_w(codepoint_t val); +codepoint_t tolower_w(codepoint_t val); +int codepoint_cmpi(codepoint_t c1, codepoint_t c2); +ssize_t push_string(struct smb_iconv_convenience *ic, void *dest, const char *src, size_t dest_len, int flags); +ssize_t pull_string(struct smb_iconv_convenience *ic, + char *dest, const void *src, size_t dest_len, size_t src_len, int flags); +ssize_t convert_string(struct smb_iconv_convenience *ic, + charset_t from, charset_t to, + void const *src, size_t srclen, + void *dest, size_t destlen); +ssize_t convert_string_talloc_descriptor(TALLOC_CTX *ctx, smb_iconv_t descriptor, void const *src, size_t srclen, void **dest); +ssize_t convert_string_talloc(TALLOC_CTX *ctx, + struct smb_iconv_convenience *ic, + charset_t from, charset_t to, + void const *src, size_t srclen, + void **dest); +ssize_t push_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); +ssize_t push_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, void **dest, const char *src); +ssize_t push_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); +ssize_t pull_ascii_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); +ssize_t pull_ucs2_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const void *src); +ssize_t pull_utf8_talloc(TALLOC_CTX *ctx, struct smb_iconv_convenience *ic, char **dest, const char *src); + +/* iconv */ +smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode); +int smb_iconv_close(smb_iconv_t cd); +size_t smb_iconv(smb_iconv_t cd, + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft); +smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, + const char *fromcode, bool native_iconv); + +/* iconv convenience */ +struct smb_iconv_convenience *smb_iconv_convenience_init(TALLOC_CTX *mem_ctx, + const char *dos_charset, + const char *unix_charset, + bool native_iconv); #endif /* __CHARSET_H__ */ diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index db212a83c4..4f4bc8fd2d 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -113,7 +113,7 @@ static size_t sys_iconv(void *cd, * It only knows about a very small number of character sets - just * enough that Samba works on systems that don't have iconv. **/ -size_t smb_iconv(smb_iconv_t cd, +_PUBLIC_ size_t smb_iconv(smb_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { @@ -156,7 +156,7 @@ static bool is_utf16(const char *name) -smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, +_PUBLIC_ smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, const char *fromcode, bool native_iconv) { smb_iconv_t ret; @@ -263,7 +263,7 @@ failed: /* simple iconv_open() wrapper */ -smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) +_PUBLIC_ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) { return smb_iconv_open_ex(NULL, tocode, fromcode, true); } @@ -271,7 +271,7 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode) /* simple iconv_close() wrapper */ -int smb_iconv_close(smb_iconv_t cd) +_PUBLIC_ int smb_iconv_close(smb_iconv_t cd) { #ifdef HAVE_NATIVE_ICONV if (cd->cd_direct) iconv_close((iconv_t)cd->cd_direct); diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 9b87f49800..c496c5d905 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -67,7 +67,7 @@ static void load_case_tables(void) /** Convert a codepoint_t to upper case. **/ -codepoint_t toupper_w(codepoint_t val) +_PUBLIC_ codepoint_t toupper_w(codepoint_t val) { if (val < 128) { return toupper(val); @@ -87,7 +87,7 @@ codepoint_t toupper_w(codepoint_t val) /** Convert a codepoint_t to lower case. **/ -codepoint_t tolower_w(codepoint_t val) +_PUBLIC_ codepoint_t tolower_w(codepoint_t val) { if (val < 128) { return tolower(val); @@ -107,7 +107,7 @@ codepoint_t tolower_w(codepoint_t val) /** compare two codepoints case insensitively */ -int codepoint_cmpi(codepoint_t c1, codepoint_t c2) +_PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) { if (c1 == c2 || toupper_w(c1) == toupper_w(c2)) { -- cgit From 333c169529a3f64a28fcaff1056069867fd56a90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 20:30:46 +0200 Subject: Use variables for source directory in remaining subsystems. (This used to be commit 6b6b2196a8a8d9e741f5c399185ded7a16938da0) --- source4/lib/charset/config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index e5e5bd4560..d5367beb25 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -7,6 +7,6 @@ PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET ################################################ -CHARSET_OBJ_FILES = $(addprefix lib/charset/, iconv.o charcnv.o util_unistr.o) +CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_unistr.o) -PUBLIC_HEADERS += lib/charset/charset.h +PUBLIC_HEADERS += $(libcharsetsrcdir)/charset.h -- cgit From dc114f8c5acbcffe2f7114083f3e058f17fb4fa2 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 21:09:04 +0200 Subject: Avoid smb_build for prototype headers in some places. (This used to be commit 4876c4efbbafb4e0afa3554cd9f748ab591a2927) --- source4/lib/charset/config.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index d5367beb25..64c240a46a 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -1,7 +1,6 @@ ################################################ # Start SUBSYSTEM CHARSET [SUBSYSTEM::CHARSET] -PRIVATE_PROTO_HEADER = charset_proto.h PUBLIC_DEPENDENCIES = ICONV PRIVATE_DEPENDENCIES = DYNCONFIG # End SUBSYSTEM CHARSET @@ -10,3 +9,5 @@ PRIVATE_DEPENDENCIES = DYNCONFIG CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_unistr.o) PUBLIC_HEADERS += $(libcharsetsrcdir)/charset.h + +PRIVATE_PROTO_HEADER = charset_proto.h -- cgit From 4c8756f147f8b9a2806fd76e4cb06bb99d391516 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 22:30:08 +0200 Subject: Create prototype headers from Makefile directory, without smb_build in the middle. (This used to be commit f4a77b96f9c17d853348b70794026e5b9e384942) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 64c240a46a..9e37b5f0a6 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -10,4 +10,4 @@ CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_uni PUBLIC_HEADERS += $(libcharsetsrcdir)/charset.h -PRIVATE_PROTO_HEADER = charset_proto.h +$(call proto_header_template,$(libcharsetsrcdir)/charset_proto.h,$(CHARSET_OBJ_FILES:.o=.c)) -- cgit From 4c70cda986c86fe536327321d04c29eca81b6409 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 18 May 2008 23:02:47 +0200 Subject: Fix a couple (well, little more than that..) of typos. (This used to be commit a6b52119940a900fb0de3864b8bca94e2965cc24) --- source4/lib/charset/config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/config.mk b/source4/lib/charset/config.mk index 9e37b5f0a6..12c2f5f321 100644 --- a/source4/lib/charset/config.mk +++ b/source4/lib/charset/config.mk @@ -10,4 +10,4 @@ CHARSET_OBJ_FILES = $(addprefix $(libcharsetsrcdir)/, iconv.o charcnv.o util_uni PUBLIC_HEADERS += $(libcharsetsrcdir)/charset.h -$(call proto_header_template,$(libcharsetsrcdir)/charset_proto.h,$(CHARSET_OBJ_FILES:.o=.c)) +$(eval $(call proto_header_template,$(libcharsetsrcdir)/charset_proto.h,$(CHARSET_OBJ_FILES:.o=.c))) -- cgit From 936b973acbc756cc3b6cb0d9df85ebc28ba76ae7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 27 May 2008 14:36:28 +0200 Subject: Use new dynconfig.h location. (This used to be commit c3f556915f09d078253e4c5539910a1cf420eeca) --- source4/lib/charset/util_unistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index c496c5d905..19a4f3236c 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -20,7 +20,7 @@ #include "includes.h" #include "system/locale.h" -#include "dynconfig.h" +#include "dynconfig/dynconfig.h" #include "param/param.h" /** -- cgit From e1188406fb1e42ac04abc46f8a09522a29b83178 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 19 Aug 2008 17:49:34 +1000 Subject: added some comments at the request of a frustrated abartlet (This used to be commit cad2e6c4c13ccd02587e47d13e897e0a327b58eb) --- source4/lib/charset/iconv.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/iconv.c b/source4/lib/charset/iconv.c index 4f4bc8fd2d..d4f930b462 100644 --- a/source4/lib/charset/iconv.c +++ b/source4/lib/charset/iconv.c @@ -469,6 +469,9 @@ static size_t iconv_copy(void *cd, const char **inbuf, size_t *inbytesleft, return 0; } +/* + this takes a UTF8 sequence and produces a UTF16 sequence + */ static size_t utf8_pull(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { @@ -586,6 +589,10 @@ error: return -1; } + +/* + this takes a UTF16 sequence and produces a UTF8 sequence + */ static size_t utf8_push(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { -- cgit From cc43037f19056ed24d7fffa54456d597c63ad105 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 22 Aug 2008 17:36:56 +1000 Subject: fixed a problem with length limited ldap values The core ldb code for string matching assumed NULL terminated strings, whereas the anr module used data_blob_const() to effectively truncate a ldb_val by changing its length. The ldb code is supposed to be based around length limited blobs, not NULL terminated strings, so the correct fix was to change the string comparison functions to be length limited (This used to be commit 26c6aa5a80ffaf06fc33f30a6533f8f16ef538bc) --- source4/lib/charset/charset.h | 1 + source4/lib/charset/util_unistr.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'source4/lib/charset') diff --git a/source4/lib/charset/charset.h b/source4/lib/charset/charset.h index baa7df532b..c49745cd7f 100644 --- a/source4/lib/charset/charset.h +++ b/source4/lib/charset/charset.h @@ -97,6 +97,7 @@ size_t count_chars_w(const char *s, char c); void strupper_m(char *s); void strlower_m(char *s); char *strupper_talloc(TALLOC_CTX *ctx, const char *src); +char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n); char *strlower_talloc(TALLOC_CTX *ctx, const char *src); bool strhasupper(const char *string); bool strhaslower(const char *string); diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 19a4f3236c..09ec7b0471 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -518,8 +518,9 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) /** Convert a string to UPPER case, allocated with talloc + source length limited to n bytes **/ -_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +_PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) { size_t size=0; char *dest; @@ -531,12 +532,12 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) /* this takes advantage of the fact that upper/lower can't change the length of a character by more than 1 byte */ - dest = talloc_array(ctx, char, 2*(strlen(src))+1); + dest = talloc_array(ctx, char, 2*(n+1)); if (dest == NULL) { return NULL; } - while (*src) { + while (*src && n--) { size_t c_size; codepoint_t c = next_codepoint(iconv_convenience, src, &c_size); src += c_size; @@ -561,6 +562,16 @@ _PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) return dest; } +/** + Convert a string to UPPER case, allocated with talloc +**/ +_PUBLIC_ char *strupper_talloc(TALLOC_CTX *ctx, const char *src) +{ + return strupper_talloc_n(ctx, src, src?strlen(src):0); +} + + + /** Convert a string to lower case. **/ -- cgit