lib/util/charset Move source3/lib/util_unistr.c to the common code.
authorAndrew Bartlett <abartlet@samba.org>
Tue, 12 Apr 2011 06:31:08 +0000 (16:31 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Apr 2011 04:47:07 +0000 (14:47 +1000)
This file (largely) contains functions to deal with UTF16 strings.

Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
lib/util/charset/charset.h
lib/util/charset/util_unistr_w.c [moved from source3/lib/util_unistr.c with 86% similarity]
lib/util/charset/wscript_build
source3/Makefile.in
source3/include/proto.h
source3/lib/charcnv.c
source3/wscript_build

index 16bb9c62fbf014e34f7ad8797db0da25ce0c6813..3a6e6a321666347a0cc90ec1d6662e75c78494ee 100644 (file)
@@ -240,6 +240,26 @@ void load_case_tables(void);
 void load_case_tables_library(void);
 bool smb_register_charset(const struct charset_functions *funcs_in);
 
+/* The following definitions come from util_unistr_w.c  */
+
+size_t strlen_w(const smb_ucs2_t *src);
+size_t strnlen_w(const smb_ucs2_t *src, size_t max);
+smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strchr_wa(const smb_ucs2_t *s, char c);
+smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strnrchr_w(const smb_ucs2_t *s, smb_ucs2_t c, unsigned int n);
+smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins);
+bool strlower_w(smb_ucs2_t *s);
+bool strupper_w(smb_ucs2_t *s);
+int strcmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
+int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
+int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len);
+int strcmp_wa(const smb_ucs2_t *a, const char *b);
+int toupper_ascii(int c);
+int tolower_ascii(int c);
+int isupper_ascii(int c);
+int islower_ascii(int c);
+
 /*
  *   Define stub for charset module which implements 8-bit encoding with gaps.
  *   Encoding tables for such module should be produced from glibc's CHARMAPs
similarity index 86%
rename from source3/lib/util_unistr.c
rename to lib/util/charset/util_unistr_w.c
index 26450e319b68365ec27c321ee93a861ff1aff611..a550e527763b4dd94fc0a9cd8b1a2869e0c91849 100644 (file)
@@ -1,20 +1,20 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Samba utility functions
    Copyright (C) Andrew Tridgell 1992-2001
    Copyright (C) Simo Sorce 2001
    Copyright (C) Jeremy Allison 2005
-   
+
    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/>.
 */
 
 static int strncmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len);
 
-/*******************************************************************
- Write a string in (little-endian) unicode format. src is in
- the current DOS codepage. len is the length in bytes of the
- string pointed to by dst.
-
- if null_terminate is True then null terminate the packet (adds 2 bytes)
-
- the return value is the length in bytes consumed by the string, including the
- null termination if applied
-********************************************************************/
-
-size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate)
-{
-       int flags = null_terminate ? STR_UNICODE|STR_NOALIGN|STR_TERMINATE
-                                  : STR_UNICODE|STR_NOALIGN;
-       return push_ucs2(NULL, dst, src, len, flags);
-}
-
-
-/* Converts a string from internal samba format to unicode
- */
-
-int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags)
-{
-       return push_ucs2(NULL, dest, src, dest_len, flags|STR_UNICODE|STR_NOALIGN);
-}
-
-/* Converts a string from internal samba format to unicode. Always terminates.
- * Actually just a wrapper round push_ucs2_talloc().
- */
-
-int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
-{
-       size_t size;
-       if (push_ucs2_talloc(ctx, dest, src, &size))
-               return size;
-       else
-               return -1;
-}
-
 /*******************************************************************
  Count the number of two-byte pairs in a UTF16 string.
 ********************************************************************/
@@ -212,13 +172,13 @@ smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins)
 bool strlower_w(smb_ucs2_t *s)
 {
        smb_ucs2_t cp;
-       bool ret = False;
+       bool ret = false;
 
        while (*(COPY_UCS2_CHAR(&cp,s))) {
                smb_ucs2_t v = tolower_m(cp);
                if (v != cp) {
                        COPY_UCS2_CHAR(s,&v);
-                       ret = True;
+                       ret = true;
                }
                s++;
        }
@@ -235,12 +195,12 @@ bool strlower_w(smb_ucs2_t *s)
 bool strupper_w(smb_ucs2_t *s)
 {
        smb_ucs2_t cp;
-       bool ret = False;
+       bool ret = false;
        while (*(COPY_UCS2_CHAR(&cp,s))) {
                smb_ucs2_t v = toupper_m(cp);
                if (v != cp) {
                        COPY_UCS2_CHAR(s,&v);
-                       ret = True;
+                       ret = true;
                }
                s++;
        }
index a245ef1b0c0c1f95fc47a803b974af691de133b5..29e168dce1b3aa91cd92f18313a3083cb67db11c 100644 (file)
@@ -13,6 +13,6 @@ bld.SAMBA_SUBSYSTEM('ICONV_WRAPPER',
                     public_deps='iconv replace talloc')
 
 bld.SAMBA_SUBSYSTEM('CODEPOINTS',
-       source='codepoints.c util_str.c',
+       source='codepoints.c util_str.c util_unistr_w.c',
        deps='DYNCONFIG ICONV_WRAPPER'
        )
index b3b1de48c50a67c669e6f9cafb3d0c5fcbca62cc..a0503278b99c00da8872bf94fa53a3d17367caac 100644 (file)
@@ -451,7 +451,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
          lib/wins_srv.o \
          lib/util_str.o ../lib/util/base64.o lib/util_sid.o \
-         lib/util_unistr.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
+         ../lib/util/charset/util_unistr_w.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
          lib/util.o lib/util_cmdline.o lib/util_names.o \
          lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
          lib/substitute.o lib/dbwrap_util.o \
index 48b94aacce4d0b45468f72a573d13f4552020d60..3f44b949f2e7441a8e44040af2ab4a8e6d631f5f 100644 (file)
@@ -126,6 +126,9 @@ size_t pull_string_talloc(TALLOC_CTX *ctx,
                        size_t src_len,
                        int flags);
 size_t align_string(const void *base_ptr, const char *p, int flags);
+size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate);
+int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags);
+int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src);
 
 /* The following definitions come from lib/conn_tdb.c  */
 
@@ -1046,29 +1049,6 @@ char *escape_shell_string(const char *src);
 char **str_list_make_v3(TALLOC_CTX *mem_ctx, const char *string, const char *sep);
 char *sanitize_username(TALLOC_CTX *mem_ctx, const char *username);
 
-/* The following definitions come from lib/util_unistr.c  */
-
-size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate);
-int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags);
-int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src);
-size_t strlen_w(const smb_ucs2_t *src);
-size_t strnlen_w(const smb_ucs2_t *src, size_t max);
-smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
-smb_ucs2_t *strchr_wa(const smb_ucs2_t *s, char c);
-smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
-smb_ucs2_t *strnrchr_w(const smb_ucs2_t *s, smb_ucs2_t c, unsigned int n);
-smb_ucs2_t *strstr_w(const smb_ucs2_t *s, const smb_ucs2_t *ins);
-bool strlower_w(smb_ucs2_t *s);
-bool strupper_w(smb_ucs2_t *s);
-int strcmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
-int strcasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b);
-int strncasecmp_w(const smb_ucs2_t *a, const smb_ucs2_t *b, size_t len);
-int strcmp_wa(const smb_ucs2_t *a, const char *b);
-int toupper_ascii(int c);
-int tolower_ascii(int c);
-int isupper_ascii(int c);
-int islower_ascii(int c);
-
 /* The following definitions come from lib/version.c  */
 
 const char *samba_version_string(void);
index 6e5b606e64dda15254422ece9aa3904d00fe31ad..edcccc25e71c157169955c15d6ac513d87508523 100644 (file)
@@ -1366,3 +1366,42 @@ size_t align_string(const void *base_ptr, const char *p, int flags)
        return 0;
 }
 
+/*******************************************************************
+ Write a string in (little-endian) unicode format. src is in
+ the current DOS codepage. len is the length in bytes of the
+ string pointed to by dst.
+
+ if null_terminate is True then null terminate the packet (adds 2 bytes)
+
+ the return value is the length in bytes consumed by the string, including the
+ null termination if applied
+********************************************************************/
+
+size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate)
+{
+       int flags = null_terminate ? STR_UNICODE|STR_NOALIGN|STR_TERMINATE
+                                  : STR_UNICODE|STR_NOALIGN;
+       return push_ucs2(NULL, dst, src, len, flags);
+}
+
+
+/* Converts a string from internal samba format to unicode
+ */
+
+int rpcstr_push(void *dest, const char *src, size_t dest_len, int flags)
+{
+       return push_ucs2(NULL, dest, src, dest_len, flags|STR_UNICODE|STR_NOALIGN);
+}
+
+/* Converts a string from internal samba format to unicode. Always terminates.
+ * Actually just a wrapper round push_ucs2_talloc().
+ */
+
+int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
+{
+       size_t size;
+       if (push_ucs2_talloc(ctx, dest, src, &size))
+               return size;
+       else
+               return -1;
+}
index 300f5b386384ed43d09724253ecbfe07a849395b..71d91388dd81966a5e36d245b41a2bf84a2302b3 100755 (executable)
@@ -963,7 +963,7 @@ bld.SAMBA3_SUBSYSTEM('tdb-wrap3',
                     vars=locals())
 
 bld.SAMBA3_SUBSYSTEM('CHARSET3',
-                    source='''lib/util_str.c lib/util_unistr.c lib/charcnv.c lib/fstring.c''',
+                    source='''lib/util_str.c lib/charcnv.c lib/fstring.c''',
                     public_deps='ICONV_WRAPPER CODEPOINTS',
                     deps='DYNCONFIG')