From b5616adc8adbcee61bb670378f9c066225d9dcf3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 25 Mar 2011 08:37:00 +1100 Subject: lib/util/charset rename iconv_convenience to iconv_handle This better reflects what this structure is Andrew Bartlett --- lib/util/charset/charcnv.c | 8 +++---- lib/util/charset/charset.h | 26 +++++++++++------------ lib/util/charset/codepoints.c | 48 +++++++++++++++++++++--------------------- lib/util/charset/tests/iconv.c | 4 ++-- lib/util/charset/util_str.c | 32 ++++++++++++++-------------- lib/util/charset/util_unistr.c | 40 +++++++++++++++++------------------ 6 files changed, 79 insertions(+), 79 deletions(-) (limited to 'lib/util') diff --git a/lib/util/charset/charcnv.c b/lib/util/charset/charcnv.c index 88f464c2c2..887cc9d989 100644 --- a/lib/util/charset/charcnv.c +++ b/lib/util/charset/charcnv.c @@ -124,7 +124,7 @@ convert: * @returns the number of bytes occupied in the destination * on error, returns -1, and sets errno **/ -_PUBLIC_ ssize_t convert_string_error(struct smb_iconv_convenience *ic, +_PUBLIC_ ssize_t convert_string_error(struct smb_iconv_handle *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen, size_t *converted_size) @@ -167,7 +167,7 @@ _PUBLIC_ ssize_t convert_string_error(struct smb_iconv_convenience *ic, * @param destlen maximal length allowed for string * @returns the number of bytes occupied in the destination **/ -_PUBLIC_ bool convert_string_convenience(struct smb_iconv_convenience *ic, +_PUBLIC_ bool convert_string_handle(struct smb_iconv_handle *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen, size_t *converted_size) @@ -214,8 +214,8 @@ _PUBLIC_ bool convert_string_convenience(struct smb_iconv_convenience *ic, * @returns Size in bytes of the converted string; or -1 in case of error. **/ -_PUBLIC_ bool convert_string_talloc_convenience(TALLOC_CTX *ctx, - struct smb_iconv_convenience *ic, +_PUBLIC_ bool convert_string_talloc_handle(TALLOC_CTX *ctx, + struct smb_iconv_handle *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dst, size_t *converted_size) diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h index 141fbea7be..30ebcd5595 100644 --- a/lib/util/charset/charset.h +++ b/lib/util/charset/charset.h @@ -103,7 +103,7 @@ typedef struct smb_iconv_s { #define STR_LEN_NOTERM 256 /* the length field is the unterminated length */ struct loadparm_context; -struct smb_iconv_convenience; +struct smb_iconv_handle; /* replace some string functions with multi-byte versions */ @@ -159,11 +159,11 @@ ssize_t iconv_talloc(TALLOC_CTX *mem_ctx, void const *src, size_t srclen, void *dest); -extern struct smb_iconv_convenience *global_iconv_convenience; -struct smb_iconv_convenience *get_iconv_convenience(void); -smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, +extern struct smb_iconv_handle *global_iconv_handle; +struct smb_iconv_handle *get_iconv_handle(void); +smb_iconv_t get_conv_handle(struct smb_iconv_handle *ic, charset_t from, charset_t to); -const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch); +const char *charset_name(struct smb_iconv_handle *ic, charset_t ch); codepoint_t next_codepoint_ext(const char *str, charset_t src_charset, size_t *size); @@ -171,12 +171,12 @@ codepoint_t next_codepoint(const char *str, size_t *size); ssize_t push_codepoint(char *str, codepoint_t c); /* codepoints */ -codepoint_t next_codepoint_convenience_ext(struct smb_iconv_convenience *ic, +codepoint_t next_codepoint_handle_ext(struct smb_iconv_handle *ic, const char *str, charset_t src_charset, size_t *size); -codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic, +codepoint_t next_codepoint_handle(struct smb_iconv_handle *ic, const char *str, size_t *size); -ssize_t push_codepoint_convenience(struct smb_iconv_convenience *ic, +ssize_t push_codepoint_handle(struct smb_iconv_handle *ic, char *str, codepoint_t c); codepoint_t toupper_m(codepoint_t val); @@ -186,19 +186,19 @@ bool isupper_m(codepoint_t val); int codepoint_cmpi(codepoint_t c1, codepoint_t c2); /* Iconv convenience functions */ -struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX *mem_ctx, +struct smb_iconv_handle *smb_iconv_handle_reinit(TALLOC_CTX *mem_ctx, const char *dos_charset, const char *unix_charset, const char *display_charset, bool native_iconv, - struct smb_iconv_convenience *old_ic); + struct smb_iconv_handle *old_ic); -bool convert_string_convenience(struct smb_iconv_convenience *ic, +bool convert_string_handle(struct smb_iconv_handle *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t destlen, size_t *converted_size); -bool convert_string_talloc_convenience(TALLOC_CTX *ctx, - struct smb_iconv_convenience *ic, +bool convert_string_talloc_handle(TALLOC_CTX *ctx, + struct smb_iconv_handle *ic, charset_t from, charset_t to, void const *src, size_t srclen, void *dest, size_t *converted_size); diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c index 5ee95a8af5..62a80a35d4 100644 --- a/lib/util/charset/codepoints.c +++ b/lib/util/charset/codepoints.c @@ -153,7 +153,7 @@ _PUBLIC_ int codepoint_cmpi(codepoint_t c1, codepoint_t c2) } -struct smb_iconv_convenience { +struct smb_iconv_handle { TALLOC_CTX *child_ctx; const char *unix_charset; const char *dos_charset; @@ -162,20 +162,20 @@ struct smb_iconv_convenience { smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; }; -struct smb_iconv_convenience *global_iconv_convenience = NULL; +struct smb_iconv_handle *global_iconv_handle = NULL; -struct smb_iconv_convenience *get_iconv_convenience(void) +struct smb_iconv_handle *get_iconv_handle(void) { - if (global_iconv_convenience == NULL) - global_iconv_convenience = smb_iconv_convenience_reinit(talloc_autofree_context(), + if (global_iconv_handle == NULL) + global_iconv_handle = smb_iconv_handle_reinit(talloc_autofree_context(), "ASCII", "UTF-8", "ASCII", true, NULL); - return global_iconv_convenience; + return global_iconv_handle; } /** * Return the name of a charset to give to iconv(). **/ -const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) +const char *charset_name(struct smb_iconv_handle *ic, charset_t ch) { switch (ch) { case CH_UTF16: return "UTF-16LE"; @@ -193,7 +193,7 @@ const char *charset_name(struct smb_iconv_convenience *ic, charset_t ch) /** re-initialize iconv conversion descriptors **/ -static int close_iconv_convenience(struct smb_iconv_convenience *data) +static int close_iconv_handle(struct smb_iconv_handle *data) { unsigned c1, c2; for (c1=0;c1child_ctx); ZERO_STRUCTP(ret); } else { - ret = talloc_zero(mem_ctx, struct smb_iconv_convenience); + ret = talloc_zero(mem_ctx, struct smb_iconv_handle); } if (ret == NULL) { return NULL; @@ -279,7 +279,7 @@ _PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX * return NULL; } - talloc_set_destructor(ret, close_iconv_convenience); + talloc_set_destructor(ret, close_iconv_handle); ret->dos_charset = talloc_strdup(ret->child_ctx, dos_charset); ret->unix_charset = talloc_strdup(ret->child_ctx, unix_charset); @@ -292,7 +292,7 @@ _PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX * /* on-demand initialisation of conversion handles */ -smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, +smb_iconv_t get_conv_handle(struct smb_iconv_handle *ic, charset_t from, charset_t to) { const char *n1, *n2; @@ -344,8 +344,8 @@ smb_iconv_t get_conv_handle(struct smb_iconv_convenience *ic, * * Return INVALID_CODEPOINT if the next character cannot be converted. */ -_PUBLIC_ codepoint_t next_codepoint_convenience_ext( - struct smb_iconv_convenience *ic, +_PUBLIC_ codepoint_t next_codepoint_handle_ext( + struct smb_iconv_handle *ic, const char *str, charset_t src_charset, size_t *bytes_consumed) { @@ -421,10 +421,10 @@ _PUBLIC_ codepoint_t next_codepoint_convenience_ext( return INVALID_CODEPOINT if the next character cannot be converted */ -_PUBLIC_ codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic, +_PUBLIC_ codepoint_t next_codepoint_handle(struct smb_iconv_handle *ic, const char *str, size_t *size) { - return next_codepoint_convenience_ext(ic, str, CH_UNIX, size); + return next_codepoint_handle_ext(ic, str, CH_UNIX, size); } /* @@ -437,7 +437,7 @@ _PUBLIC_ codepoint_t next_codepoint_convenience(struct smb_iconv_convenience *ic return the number of bytes occupied by the CH_UNIX character, or -1 on failure */ -_PUBLIC_ ssize_t push_codepoint_convenience(struct smb_iconv_convenience *ic, +_PUBLIC_ ssize_t push_codepoint_handle(struct smb_iconv_handle *ic, char *str, codepoint_t c) { smb_iconv_t descriptor; @@ -489,16 +489,16 @@ _PUBLIC_ ssize_t push_codepoint_convenience(struct smb_iconv_convenience *ic, _PUBLIC_ codepoint_t next_codepoint_ext(const char *str, charset_t src_charset, size_t *size) { - return next_codepoint_convenience_ext(get_iconv_convenience(), str, + return next_codepoint_handle_ext(get_iconv_handle(), str, src_charset, size); } _PUBLIC_ codepoint_t next_codepoint(const char *str, size_t *size) { - return next_codepoint_convenience(get_iconv_convenience(), str, size); + return next_codepoint_handle(get_iconv_handle(), str, size); } _PUBLIC_ ssize_t push_codepoint(char *str, codepoint_t c) { - return push_codepoint_convenience(get_iconv_convenience(), str, c); + return push_codepoint_handle(get_iconv_handle(), str, c); } diff --git a/lib/util/charset/tests/iconv.c b/lib/util/charset/tests/iconv.c index 9b48771b16..c27c263cfc 100644 --- a/lib/util/charset/tests/iconv.c +++ b/lib/util/charset/tests/iconv.c @@ -289,7 +289,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) size_t size, size2; codepoint_t c; - size = push_codepoint_convenience(lpcfg_iconv_convenience(tctx->lp_ctx), (char *)buf, codepoint); + size = push_codepoint_handle(lpcfg_iconv_handle(tctx->lp_ctx), (char *)buf, codepoint); torture_assert(tctx, size != -1 || (codepoint >= 0xd800 && codepoint <= 0x10000), "Invalid Codepoint range"); @@ -300,7 +300,7 @@ static bool test_codepoint(struct torture_context *tctx, unsigned int codepoint) buf[size+2] = random(); buf[size+3] = random(); - c = next_codepoint_convenience(lpcfg_iconv_convenience(tctx->lp_ctx), (char *)buf, &size2); + c = next_codepoint_handle(lpcfg_iconv_handle(tctx->lp_ctx), (char *)buf, &size2); torture_assert(tctx, c == codepoint, talloc_asprintf(tctx, diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c index 597b031675..30961d068a 100644 --- a/lib/util/charset/util_str.c +++ b/lib/util/charset/util_str.c @@ -34,7 +34,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 = get_iconv_convenience(); + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -42,8 +42,8 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) if (s2 == NULL) return 1; while (*s1 && *s2) { - c1 = next_codepoint_convenience(iconv_convenience, s1, &size1); - c2 = next_codepoint_convenience(iconv_convenience, s2, &size2); + c1 = next_codepoint_handle(iconv_handle, s1, &size1); + c2 = next_codepoint_handle(iconv_handle, s2, &size2); s1 += size1; s2 += size2; @@ -73,7 +73,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 = get_iconv_convenience(); + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); /* handle null ptr comparisons to simplify the use in qsort */ if (s1 == s2) return 0; @@ -83,8 +83,8 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) while (*s1 && *s2 && n) { n--; - c1 = next_codepoint_convenience(iconv_convenience, s1, &size1); - c2 = next_codepoint_convenience(iconv_convenience, s2, &size2); + c1 = next_codepoint_handle(iconv_handle, s1, &size1); + c2 = next_codepoint_handle(iconv_handle, s2, &size2); s1 += size1; s2 += size2; @@ -143,7 +143,7 @@ _PUBLIC_ bool strcsequal(const char *s1,const char *s2) _PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst_charset) { size_t count = 0; - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); if (!s) { return 0; @@ -160,7 +160,7 @@ _PUBLIC_ size_t strlen_m_ext(const char *s, charset_t src_charset, charset_t dst while (*s) { size_t c_size; - codepoint_t c = next_codepoint_convenience_ext(ic, s, src_charset, &c_size); + codepoint_t c = next_codepoint_handle_ext(ic, s, src_charset, &c_size); s += c_size; switch (dst_charset) { @@ -262,7 +262,7 @@ _PUBLIC_ size_t strlen_m_term_null(const char *s) _PUBLIC_ char *strchr_m(const char *src, char c) { const char *s; - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); if (src == NULL) { return NULL; } @@ -292,7 +292,7 @@ _PUBLIC_ char *strchr_m(const char *src, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint_convenience(ic, s, &size); + codepoint_t c2 = next_codepoint_handle(ic, s, &size); if (c2 == c) { return discard_const_p(char, s); } @@ -307,7 +307,7 @@ _PUBLIC_ char *strchr_m(const char *src, char c) */ _PUBLIC_ char *strrchr_m(const char *s, char c) { - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); char *ret = NULL; if (s == NULL) { @@ -356,7 +356,7 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) while (*s) { size_t size; - codepoint_t c2 = next_codepoint_convenience(ic, s, &size); + codepoint_t c2 = next_codepoint_handle(ic, s, &size); if (c2 == c) { ret = discard_const_p(char, s); } @@ -371,13 +371,13 @@ _PUBLIC_ char *strrchr_m(const char *s, char c) */ _PUBLIC_ bool strhaslower(const char *string) { - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); while (*string) { size_t c_size; codepoint_t s; codepoint_t t; - s = next_codepoint_convenience(ic, string, &c_size); + s = next_codepoint_handle(ic, string, &c_size); string += c_size; t = toupper_m(s); @@ -395,13 +395,13 @@ _PUBLIC_ bool strhaslower(const char *string) */ _PUBLIC_ bool strhasupper(const char *string) { - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); while (*string) { size_t c_size; codepoint_t s; codepoint_t t; - s = next_codepoint_convenience(ic, string, &c_size); + s = next_codepoint_handle(ic, string, &c_size); string += c_size; t = tolower_m(s); diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index c59620ed32..f761613ba8 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -74,10 +74,10 @@ _PUBLIC_ bool next_token(const char **ptr,char *buff, const char *sep, size_t bu **/ _PUBLIC_ void string_replace_m(char *s, char oldc, char newc) { - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); while (s && *s) { size_t size; - codepoint_t c = next_codepoint_convenience(ic, s, &size); + codepoint_t c = next_codepoint_handle(ic, s, &size); if (c == oldc) { *s = newc; } @@ -138,7 +138,7 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) { size_t size=0; char *dest; - struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); if(src == NULL) { return NULL; @@ -153,12 +153,12 @@ _PUBLIC_ char *strlower_talloc(TALLOC_CTX *ctx, const char *src) while (*src) { size_t c_size; - codepoint_t c = next_codepoint_convenience(iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint_handle(iconv_handle, src, &c_size); src += c_size; c = tolower_m(c); - c_size = push_codepoint_convenience(iconv_convenience, dest+size, c); + c_size = push_codepoint_handle(iconv_handle, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -184,7 +184,7 @@ _PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) { size_t size=0; char *dest; - struct smb_iconv_convenience *iconv_convenience = get_iconv_convenience(); + struct smb_iconv_handle *iconv_handle = get_iconv_handle(); if (!src) { return NULL; @@ -199,12 +199,12 @@ _PUBLIC_ char *strupper_talloc_n(TALLOC_CTX *ctx, const char *src, size_t n) while (n-- && *src) { size_t c_size; - codepoint_t c = next_codepoint_convenience(iconv_convenience, src, &c_size); + codepoint_t c = next_codepoint_handle(iconv_handle, src, &c_size); src += c_size; c = toupper_m(c); - c_size = push_codepoint_convenience(iconv_convenience, dest+size, c); + c_size = push_codepoint_handle(iconv_handle, dest+size, c); if (c_size == -1) { talloc_free(dest); return NULL; @@ -244,7 +244,7 @@ _PUBLIC_ char *talloc_strdup_upper(TALLOC_CTX *ctx, const char *src) _PUBLIC_ void strlower_m(char *s) { char *d; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_handle *iconv_handle; /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our @@ -258,14 +258,14 @@ _PUBLIC_ void strlower_m(char *s) if (!*s) return; - iconv_convenience = get_iconv_convenience(); + iconv_handle = get_iconv_handle(); d = s; while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint_convenience(iconv_convenience, s, &c_size); - c_size2 = push_codepoint_convenience(iconv_convenience, d, tolower_m(c)); + codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); + c_size2 = push_codepoint_handle(iconv_handle, d, tolower_m(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_m(c), (int)c_size, (int)c_size2)); @@ -283,7 +283,7 @@ _PUBLIC_ void strlower_m(char *s) _PUBLIC_ void strupper_m(char *s) { char *d; - struct smb_iconv_convenience *iconv_convenience; + struct smb_iconv_handle *iconv_handle; /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our @@ -297,14 +297,14 @@ _PUBLIC_ void strupper_m(char *s) if (!*s) return; - iconv_convenience = get_iconv_convenience(); + iconv_handle = get_iconv_handle(); d = s; while (*s) { size_t c_size, c_size2; - codepoint_t c = next_codepoint_convenience(iconv_convenience, s, &c_size); - c_size2 = push_codepoint_convenience(iconv_convenience, d, toupper_m(c)); + codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); + c_size2 = push_codepoint_handle(iconv_handle, d, toupper_m(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_m(c), (int)c_size, (int)c_size2)); @@ -322,12 +322,12 @@ _PUBLIC_ void strupper_m(char *s) **/ _PUBLIC_ size_t count_chars_m(const char *s, char c) { - struct smb_iconv_convenience *ic = get_iconv_convenience(); + struct smb_iconv_handle *ic = get_iconv_handle(); size_t count = 0; while (*s) { size_t size; - codepoint_t c2 = next_codepoint_convenience(ic, s, &size); + codepoint_t c2 = next_codepoint_handle(ic, s, &size); if (c2 == c) count++; s += size; } @@ -669,7 +669,7 @@ _PUBLIC_ size_t convert_string(charset_t from, charset_t to, void *dest, size_t destlen) { size_t ret; - if (!convert_string_convenience(get_iconv_convenience(), from, to, + if (!convert_string_handle(get_iconv_handle(), from, to, src, srclen, dest, destlen, &ret)) return -1; @@ -692,7 +692,7 @@ _PUBLIC_ bool convert_string_talloc(TALLOC_CTX *ctx, void const *src, size_t srclen, void *dest, size_t *converted_size) { - return convert_string_talloc_convenience(ctx, get_iconv_convenience(), + return convert_string_talloc_handle(ctx, get_iconv_handle(), from, to, src, srclen, dest, converted_size); } -- cgit