summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-03-01 22:24:34 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-03-01 22:24:34 +0100
commit7ab8f373c84c328b197f923287163e83371e7ccb (patch)
tree8a009647735ccc1cf181d98b01c1084f45e0d711 /source3
parent94069bd2747a8397308c0b0b384f7bb4edd8f68b (diff)
downloadsamba-7ab8f373c84c328b197f923287163e83371e7ccb.tar.gz
samba-7ab8f373c84c328b197f923287163e83371e7ccb.tar.bz2
samba-7ab8f373c84c328b197f923287163e83371e7ccb.zip
Use common header file for character set handling in Samba 3 and Samba 4.
Diffstat (limited to 'source3')
-rw-r--r--source3/Makefile.in4
-rw-r--r--source3/include/charset.h128
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/include/smb.h2
-rw-r--r--source3/lib/charcnv.c2
-rw-r--r--source3/lib/iconv.c4
6 files changed, 6 insertions, 135 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index d957d70edb..8723b4f63f 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -366,8 +366,8 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
lib/substitute.o lib/dbwrap_util.o \
lib/ms_fnmatch.o lib/select.o lib/errmap_unix.o \
lib/tallocmsg.o lib/dmallocmsg.o libsmb/smb_signing.o \
- lib/iconv.o lib/pam_errors.o intl/lang_tdb.o lib/conn_tdb.o \
- lib/adt_tree.o lib/gencache.o \
+ ../lib/util/charset/iconv.o lib/pam_errors.o intl/lang_tdb.o \
+ lib/conn_tdb.o lib/adt_tree.o lib/gencache.o \
lib/module.o lib/events.o @LIBTEVENT_OBJ0@ \
lib/ldap_escape.o @CHARSET_STATIC@ \
lib/secdesc.o lib/util_seaccess.o lib/secace.o lib/secacl.o \
diff --git a/source3/include/charset.h b/source3/include/charset.h
deleted file mode 100644
index 1c2a5fb5f0..0000000000
--- a/source3/include/charset.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- 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 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 <http://www.gnu.org/licenses/>.
-*/
-
-struct smb_iconv_convenience;
-
-/* this defines the charset types used in samba */
-typedef enum {CH_UTF16LE=0, 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 pushes from that charset to a ucs2
- * buffer, and a function that pulls from ucs2 buffer to that charset.
- * */
-
-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 is auxiliary struct used by source/script/gen-8-bit-gap.sh script
- * during generation of an encoding table for charset module
- * */
-
-struct charset_gap_table {
- uint16 start;
- uint16 end;
- int32 idx;
-};
-
-/*
- * Define stub for charset module which implements 8-bit encoding with gaps.
- * Encoding tables for such module should be produced from glibc's CHARMAPs
- * using script source/script/gen-8bit-gap.sh
- * CHARSETNAME is CAPITALIZED charset name
- *
- * */
-#define SMB_GENERATE_CHARSET_MODULE_8_BIT_GAP(CHARSETNAME) \
-static size_t CHARSETNAME ## _push(void *cd, const char **inbuf, size_t *inbytesleft, \
- char **outbuf, size_t *outbytesleft) \
-{ \
- while (*inbytesleft >= 2 && *outbytesleft >= 1) { \
- int i; \
- int done = 0; \
- \
- uint16 ch = SVAL(*inbuf,0); \
- \
- for (i=0; from_idx[i].start != 0xffff; i++) { \
- if ((from_idx[i].start <= ch) && (from_idx[i].end >= ch)) { \
- ((unsigned char*)(*outbuf))[0] = from_ucs2[from_idx[i].idx+ch]; \
- (*inbytesleft) -= 2; \
- (*outbytesleft) -= 1; \
- (*inbuf) += 2; \
- (*outbuf) += 1; \
- done = 1; \
- break; \
- } \
- } \
- if (!done) { \
- errno = EINVAL; \
- return -1; \
- } \
- \
- } \
- \
- if (*inbytesleft == 1) { \
- errno = EINVAL; \
- return -1; \
- } \
- \
- if (*inbytesleft > 1) { \
- errno = E2BIG; \
- return -1; \
- } \
- \
- return 0; \
-} \
- \
-static size_t CHARSETNAME ## _pull(void *cd, const char **inbuf, size_t *inbytesleft, \
- char **outbuf, size_t *outbytesleft) \
-{ \
- while (*inbytesleft >= 1 && *outbytesleft >= 2) { \
- *(uint16*)(*outbuf) = to_ucs2[((unsigned char*)(*inbuf))[0]]; \
- (*inbytesleft) -= 1; \
- (*outbytesleft) -= 2; \
- (*inbuf) += 1; \
- (*outbuf) += 2; \
- } \
- \
- if (*inbytesleft > 0) { \
- errno = E2BIG; \
- return -1; \
- } \
- \
- return 0; \
-} \
- \
-struct charset_functions CHARSETNAME ## _functions = \
- {#CHARSETNAME, CHARSETNAME ## _pull, CHARSETNAME ## _push}; \
- \
-NTSTATUS charset_ ## CHARSETNAME ## _init(void); \
-NTSTATUS charset_ ## CHARSETNAME ## _init(void) \
-{ \
- return smb_register_charset(& CHARSETNAME ## _functions); \
-} \
-
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 626e67f653..0e6446be84 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -336,6 +336,7 @@ int bitmap_find(struct bitmap *bm, unsigned ofs);
/* The following definitions come from lib/charcnv.c */
+NTSTATUS smb_register_charset(struct charset_functions *funcs);
char lp_failed_convert_char(void);
void lazy_initialize_conv(void);
void gfree_charcnv(void);
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 189e370496..59c3c32346 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -149,8 +149,6 @@ typedef union unid_t {
* smb_ucs2_t is *always* in little endian format.
*/
-typedef uint16 smb_ucs2_t;
-
#ifdef WORDS_BIGENDIAN
#define UCS2_SHIFT 8
#else
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index c3b345142f..81cb9a5094 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -763,7 +763,7 @@ bool convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
* converted.
*/
bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
- void const *src, size_t srclen, void *dst,
+ void const *src, size_t srclen, void **dst,
size_t *converted_size, bool allow_bad_conv)
{
void **dest = (void **)dst;
diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c
index 3ceb637b8e..fa213a37c0 100644
--- a/source3/lib/iconv.c
+++ b/source3/lib/iconv.c
@@ -207,12 +207,12 @@ smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode)
from = charsets;
to = charsets;
- ret = SMB_MALLOC_P(struct _smb_iconv_t);
+ ret = SMB_MALLOC_P(smb_iconv_t);
if (!ret) {
errno = ENOMEM;
return (smb_iconv_t)-1;
}
- memset(ret, 0, sizeof(struct _smb_iconv_t));
+ memset(ret, 0, sizeof(smb_iconv_t));
ret->from_name = SMB_STRDUP(fromcode);
ret->to_name = SMB_STRDUP(tocode);