lib/util/charset Use push_string and talloc_strupper/strlower from common code
authorAndrew Bartlett <abartlet@samba.org>
Tue, 3 May 2011 02:29:12 +0000 (12:29 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 May 2011 05:37:07 +0000 (07:37 +0200)
The only caller of push_string() (not to be confused with
push_string_check()) in the common code was encode_pw_buffer(), and it
didn't use the alignment or STR_UPPER flags.

The talloc_strupper() and talloc_strlower() functions are tested in
smbtorture, and are next_codepoint() based.

Andrew Bartlett

lib/util/charset/util_unistr.c
lib/util/charset/wscript_build
source3/Makefile.in
source3/include/proto.h
source3/lib/charcnv.c
source3/wscript_build

index 1915c73ad56b9a7c1c08fbf0f675e878d71c0d9c..e4ae65053c733245ad3d0ae792cc0c7679aa04ff 100644 (file)
@@ -194,7 +194,7 @@ _PUBLIC_ size_t count_chars_m(const char *s, char c)
  * @param dest_len the maximum length in bytes allowed in the
  * destination.  If @p dest_len is -1 then no maximum is used.
  **/
-static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size)
+static bool push_ascii_string(void *dest, const char *src, size_t dest_len, int flags, size_t *converted_size)
 {
        size_t src_len;
        bool ret;
@@ -204,7 +204,7 @@ static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags,
                if (tmpbuf == NULL) {
                        return false;
                }
-               ret = push_ascii(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size);
+               ret = push_ascii_string(dest, tmpbuf, dest_len, flags & ~STR_UPPER, converted_size);
                talloc_free(tmpbuf);
                return ret;
        }
@@ -232,7 +232,7 @@ static bool push_ascii(void *dest, const char *src, size_t dest_len, int flags,
  * @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_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags)
 {
        size_t size = 0;
 
@@ -373,7 +373,7 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f
 {
        if (flags & STR_ASCII) {
                size_t size = 0;
-               if (push_ascii(dest, src, dest_len, flags, &size)) {
+               if (push_ascii_string(dest, src, dest_len, flags, &size)) {
                        return (ssize_t)size;
                } else {
                        return (ssize_t)-1;
@@ -404,7 +404,7 @@ _PUBLIC_ ssize_t push_string(void *dest, const char *src, size_t dest_len, int f
 _PUBLIC_ 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);
+               return pull_ascii_string(dest, src, dest_len, src_len, flags);
        } else if (flags & STR_UNICODE) {
                return pull_ucs2(dest, src, dest_len, src_len, flags);
        } else {
index 771ff5dc24e1ba25050fae33c1636b1ccb4c1f42..762313114602201726d817cf1b51af4c4ea3da5d 100644 (file)
@@ -1,18 +1,11 @@
 #!/usr/bin/env python
 
-
-if bld.env._SAMBA_BUILD_ == 4:
-    bld.SAMBA_SUBSYSTEM('CHARSET',
-                        source='util_unistr.c',
-                        public_deps='CODEPOINTS',
-                        public_headers='charset.h',
-                        )
-
 bld.SAMBA_SUBSYSTEM('ICONV_WRAPPER',
                     source='iconv.c',
                     public_deps='iconv replace talloc')
 
-bld.SAMBA_SUBSYSTEM('CODEPOINTS',
-       source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c pull_push.c',
-       deps='DYNCONFIG ICONV_WRAPPER'
-       )
+bld.SAMBA_SUBSYSTEM('CHARSET',
+                    public_headers='charset.h',
+                    source='codepoints.c convert_string.c util_str.c util_unistr_w.c charcnv.c pull_push.c util_unistr.c',
+                    deps='DYNCONFIG ICONV_WRAPPER'
+                    )
index 6893e01f2cf7f012318bb3047367117aa5ceb175..5e7b63dae9deff5f763e7366cfe97c7189987082 100644 (file)
@@ -458,6 +458,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/wins_srv.o \
          lib/util_str.o ../lib/util/util_str_common.o \
          ../lib/util/base64.o lib/util_sid.o \
+         ../lib/util/charset/util_unistr.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 \
index 086ba6c55758ee9084a840129ed9874a3670686d..e8ce418ab28c8b7edb5ea6a4dd53cac71bb3abe1 100644 (file)
@@ -82,10 +82,6 @@ bool convert_string_error(charset_t from, charset_t to,
                            void const *src, size_t srclen,
                            void *dest, size_t destlen,
                            size_t *converted_size);
-char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s);
-char *strupper_talloc(TALLOC_CTX *ctx, const char *s);
-char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s);
-char *strlower_talloc(TALLOC_CTX *ctx, const char *s);
 size_t ucs2_align(const void *base_ptr, const void *p, int flags);
 size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags);
 size_t push_ascii_fstring(void *dest, const char *src);
index 6b667502da1ececd6b8f818d29bfe666a0977dcf..765e3943efdca75551752cee557ba14ca8301420 100644 (file)
@@ -44,98 +44,6 @@ void init_iconv(void)
                                                                true, global_iconv_handle);
 }
 
-/**
- talloc_strdup() a unix string to upper case.
-**/
-
-char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *s)
-{
-       char *out_buffer = talloc_strdup(ctx,s);
-       const unsigned char *p = (const unsigned char *)s;
-       unsigned char *q = (unsigned char *)out_buffer;
-
-       if (!q) {
-               return NULL;
-       }
-
-       /* 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 (*p) {
-               if (*p & 0x80)
-                       break;
-               *q++ = toupper_ascii_fast(*p);
-               p++;
-       }
-
-       if (*p) {
-               /* MB case. */
-               size_t converted_size, converted_size2;
-               smb_ucs2_t *ubuf = NULL;
-
-               /* We're not using the ascii buffer above. */
-               TALLOC_FREE(out_buffer);
-
-               if (!convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, s,
-                                          strlen(s)+1, (void *)&ubuf,
-                                          &converted_size))
-               {
-                       return NULL;
-               }
-
-               strupper_w(ubuf);
-
-               if (!convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, ubuf,
-                                          converted_size, (void *)&out_buffer,
-                                          &converted_size2))
-               {
-                       TALLOC_FREE(ubuf);
-                       return NULL;
-               }
-
-               /* Don't need the intermediate buffer
-                * anymore.
-                */
-               TALLOC_FREE(ubuf);
-       }
-
-       return out_buffer;
-}
-
-char *strupper_talloc(TALLOC_CTX *ctx, const char *s) {
-       return talloc_strdup_upper(ctx, s);
-}
-
-
-char *talloc_strdup_lower(TALLOC_CTX *ctx, const char *s)
-{
-       size_t converted_size;
-       smb_ucs2_t *buffer = NULL;
-       char *out_buffer;
-
-       if (!push_ucs2_talloc(ctx, &buffer, s, &converted_size)) {
-               return NULL;
-       }
-
-       strlower_w(buffer);
-
-       if (!pull_ucs2_talloc(ctx, &out_buffer, buffer, &converted_size)) {
-               TALLOC_FREE(buffer);
-               return NULL;
-       }
-
-       TALLOC_FREE(buffer);
-
-       return out_buffer;
-}
-
-char *strlower_talloc(TALLOC_CTX *ctx, const char *s) {
-       return talloc_strdup_lower(ctx, s);
-}
-
-
 /**
  * Copy a string from a char* unix src to a dos codepage string destination.
  *
@@ -626,36 +534,6 @@ size_t push_string_base(const char *base, uint16 flags2,
        return push_ascii(dest, src, dest_len, flags);
 }
 
-/**
- Copy a string from a char* src to a unicode or ascii
- dos codepage destination choosing unicode or ascii based on the 
- flags supplied
- 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)
-{
-       size_t ret;
-
-       if (!(flags & STR_ASCII) && \
-           (flags & STR_UNICODE)) {
-               ret = push_ucs2(NULL, dest, src, dest_len, flags);
-       } else {
-               ret = push_ascii(dest, src, dest_len, flags);
-       }
-       if (ret == (size_t)-1) {
-               return -1;
-       }
-       return ret;
-}
-
 /**
  Copy a string from a unicode or ascii source (depending on
  the packet flags) to a char* destination.
index 83cc39ebe72bf1c9d269a060304c87cfa7dc0e0d..fbc6693346121fcef0bc172c59dc72f9c43a5e59 100755 (executable)
@@ -964,7 +964,7 @@ bld.SAMBA3_SUBSYSTEM('tdb-wrap3',
 
 bld.SAMBA3_SUBSYSTEM('CHARSET3',
                     source='''lib/util_str.c lib/charcnv.c lib/fstring.c''',
-                    public_deps='ICONV_WRAPPER CODEPOINTS',
+                    public_deps='ICONV_WRAPPER CHARSET',
                     deps='samba-util')
 
 bld.SAMBA3_SUBSYSTEM('ldb3',
@@ -1317,7 +1317,6 @@ if not bld.env.toplevel_build:
     bld.SAMBA3_SUBSYSTEM('tdb-wrap', source='', deps='tdb-wrap3')
     bld.SAMBA3_SUBSYSTEM('errors', source='', deps='errors3')
     bld.SAMBA3_SUBSYSTEM('samba-util', source='', deps='DYNCONFIG')
-    bld.SAMBA3_SUBSYSTEM('CHARSET', source='', deps='CHARSET3')
     bld.SAMBA3_SUBSYSTEM('ldb', source='', deps='ldb3')
     bld.SAMBA3_SUBSYSTEM('dcerpc', '', deps='UTIL_TEVENT')
     bld.SAMBA3_SUBSYSTEM('cli-ldap', '', deps='UTIL_TEVENT')