lib/util/charset Merge talloc-based pull and push charset functions
authorAndrew Bartlett <abartlet@samba.org>
Thu, 28 Apr 2011 01:41:31 +0000 (11:41 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 28 Apr 2011 03:30:20 +0000 (05:30 +0200)
These were copied from source3/lib/charcnv.c

Andrew Bartlett

lib/util/charset/pull_push.c [new file with mode: 0644]
lib/util/charset/util_unistr.c
lib/util/charset/wscript_build
source3/Makefile.in
source3/include/proto.h
source3/lib/charcnv.c

diff --git a/lib/util/charset/pull_push.c b/lib/util/charset/pull_push.c
new file mode 100644 (file)
index 0000000..b7a5bcd
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+   Unix SMB/CIFS implementation.
+   Character set conversion Extensions
+   Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001
+   Copyright (C) Andrew Tridgell 2001
+   Copyright (C) Simo Sorce 2001
+   Copyright (C) Martin Pool 2003
+
+   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/>.
+
+*/
+
+#include "includes.h"
+#include "system/locale.h"
+
+/**
+ * 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
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ *
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ **/
+bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
+                     size_t *converted_size)
+{
+       size_t src_len = strlen(src)+1;
+
+       *dest = NULL;
+       return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len,
+                                    (void **)dest, converted_size);
+}
+
+/**
+ * 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
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ *
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ **/
+
+bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+                     size_t *converted_size)
+{
+       size_t src_len = strlen(src)+1;
+
+       *dest = NULL;
+       return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len,
+                                    (void**)dest, converted_size);
+}
+
+/**
+ * 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
+ *
+ * @param converted_size The number of bytes occupied by the string in the destination
+ * @returns boolean indicating if the conversion was successful
+ **/
+bool push_ascii_talloc(TALLOC_CTX *mem_ctx, char **dest, const char *src, size_t *converted_size)
+{
+       size_t src_len = strlen(src)+1;
+
+       *dest = NULL;
+       return convert_string_talloc(mem_ctx, CH_UNIX, CH_DOS, src, src_len,
+                                    (void **)dest, converted_size);
+}
+
+/**
+ * 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
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ *
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ **/
+
+bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
+                     size_t *converted_size)
+{
+       size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
+
+       *dest = NULL;
+       return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
+                                    (void **)dest, converted_size);
+}
+
+
+/**
+ * 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
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ *
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ **/
+
+bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+                     size_t *converted_size)
+{
+       size_t src_len = strlen(src)+1;
+
+       *dest = NULL;
+       return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len,
+                                    (void **)dest, converted_size);
+}
+
+
+/**
+ * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc
+ *
+ * @param dest always set at least to NULL
+ * @parm converted_size set to the number of bytes occupied by the string in
+ * the destination on success.
+ *
+ * @return true if new buffer was correctly allocated, and string was
+ * converted.
+ **/
+
+bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
+                      size_t *converted_size)
+{
+       size_t src_len = strlen(src)+1;
+
+       *dest = NULL;
+       return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len,
+                                    (void **)dest, converted_size);
+}
index 895d958deb8f5a5db821b56a7235242fb0584724..a585022e894e9f7ba60c8104ae98ae33172d0ddd 100644 (file)
@@ -296,23 +296,6 @@ static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags,
        return convert_string(CH_UNIX, CH_DOS, src, src_len, dest, dest_len, converted_size);
 }
 
-/**
- * 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.
- **/
-_PUBLIC_ bool push_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UNIX, CH_DOS, src, src_len, (void **)dest, converted_size);
-}
-
-
 /**
  * Copy a string from a dos codepage source to a unix char* destination.
  *
@@ -410,38 +393,6 @@ static ssize_t push_ucs2(void *dest, const char *src, size_t dest_len, int flags
 }
 
 
-/**
- * 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.
- **/
-_PUBLIC_ bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UNIX, CH_UTF16, src, src_len, (void **)dest, converted_size);
-}
-
-
-/**
- * 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
- **/
-
-_PUBLIC_ bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len, (void **)dest, converted_size);
-}
-
 /**
  Copy a string from a ucs2 source to a unix char* destination.
  Flags can have:
@@ -483,51 +434,6 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
        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_ bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len, (void **)dest, converted_size);
-}
-
-/**
- * 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
- **/
-
-_PUBLIC_ bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src, size_t *converted_size)
-{
-       size_t src_len = utf16_len(src);
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UTF16, CH_UNIX, src, src_len, (void **)dest, converted_size);
-}
-
-/**
- * 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
- **/
-
-_PUBLIC_ bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len, (void **)dest, converted_size);
-}
-
 /**
  Copy a string from a char* src to a unicode or ascii
  dos codepage destination choosing unicode or ascii based on the 
index 80a649976b8f0ce917aedc7b14c12e5ca9cfc088..771ff5dc24e1ba25050fae33c1636b1ccb4c1f42 100644 (file)
@@ -13,6 +13,6 @@ bld.SAMBA_SUBSYSTEM('ICONV_WRAPPER',
                     public_deps='iconv replace talloc')
 
 bld.SAMBA_SUBSYSTEM('CODEPOINTS',
-       source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c',
+       source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c pull_push.c',
        deps='DYNCONFIG ICONV_WRAPPER'
        )
index ae275f808c65ddc60f4bd78402d7bfedb4bd4461..4ec1868341f17377023eab031e066835d330066a 100644 (file)
@@ -446,7 +446,9 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/util_transfer_file.o ../lib/async_req/async_sock.o \
          lib/addrchange.o \
          $(TDB_LIB_OBJ) \
-         $(VERSION_OBJ) lib/charcnv.o ../lib/util/charset/convert_string.o lib/fstring.o ../lib/util/debug.o ../lib/util/debug_s3.o ../lib/util/fault.o \
+         $(VERSION_OBJ) lib/charcnv.o ../lib/util/charset/convert_string.o \
+         ../lib/util/charset/pull_push.o \
+         lib/fstring.o ../lib/util/debug.o ../lib/util/debug_s3.o ../lib/util/fault.o \
          lib/interface.o lib/pidfile.o lib/dumpcore.o \
          lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \
          lib/username.o \
index 2a1e1389a6e4ecd63f74bb8225ffeecdcda9b694..27a8990e20b00afe4954c6e878b28f1cd4652809 100644 (file)
@@ -94,16 +94,6 @@ size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len,
 size_t pull_ascii_fstring(char *dest, const void *src);
 size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src);
 size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags);
-bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                     size_t *converted_size);
-bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
-                     size_t *converted_size);
-bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                     size_t *converted_size);
-bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
-                     size_t *converted_size);
-bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                      size_t *converted_size);
 size_t push_string_check_fn(void *dest, const char *src,
                            size_t dest_len, int flags);
 size_t push_string_base(const char *base, uint16 flags2,
index f6fed8d1ec5d26b6ac5ec795fa68a026d707f55d..7bf8c1db2667be53964872beddd1c957797544b4 100644 (file)
@@ -189,15 +189,6 @@ size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags)
  Push and malloc an ascii string. src and dest null terminated.
 ********************************************************************/
 
-bool push_ascii_talloc(TALLOC_CTX *mem_ctx, char **dest, const char *src, size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-
-       *dest = NULL;
-       return convert_string_talloc(mem_ctx, CH_UNIX, CH_DOS, src, src_len,
-                                    (void **)dest, converted_size);
-}
-
 /**
  * Copy a string from a dos codepage source to a unix char* destination.
  *
@@ -413,48 +404,6 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
 }
 
 
-/**
- * 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 
- * @parm converted_size set to the number of bytes occupied by the string in
- * the destination on success.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-bool push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src,
-                     size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len,
-                                    (void **)dest, converted_size);
-}
-
-
-/**
- * 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 
- * @parm converted_size set to the number of bytes occupied by the string in
- * the destination on success.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-bool push_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                     size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UNIX, CH_UTF8, src, src_len,
-                                    (void**)dest, converted_size);
-}
 
 /**
  Copy a string from a ucs2 source to a unix char* destination.
@@ -626,70 +575,6 @@ static size_t pull_ucs2_base_talloc(TALLOC_CTX *ctx,
        return src_len + ucs2_align_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 
- * @parm converted_size set to the number of bytes occupied by the string in
- * the destination on success.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-bool pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src,
-                     size_t *converted_size)
-{
-       size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
-
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len,
-                                    (void **)dest, converted_size);
-}
-
-/**
- * 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 
- * @parm converted_size set to the number of bytes occupied by the string in
- * the destination on success.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                     size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_UTF8, CH_UNIX, src, src_len,
-                                    (void **)dest, converted_size);
-}
-
-/**
- * Copy a string from a DOS src to a unix char * destination, allocating a buffer using talloc
- *
- * @param dest always set at least to NULL 
- * @parm converted_size set to the number of bytes occupied by the string in
- * the destination on success.
- *
- * @return true if new buffer was correctly allocated, and string was
- * converted.
- **/
-
-bool pull_ascii_talloc(TALLOC_CTX *ctx, char **dest, const char *src,
-                      size_t *converted_size)
-{
-       size_t src_len = strlen(src)+1;
-
-       *dest = NULL;
-       return convert_string_talloc(ctx, CH_DOS, CH_UNIX, src, src_len,
-                                    (void **)dest, converted_size);
-}
-
 /**
  Copy a string from a char* src to a unicode or ascii
  dos codepage destination choosing unicode or ascii based on the