Skip to content

Commit

Permalink
lib/util/charset rename iconv_convenience to iconv_handle
Browse files Browse the repository at this point in the history
This better reflects what this structure is

Andrew Bartlett
  • Loading branch information
abartlet authored and Andrew Tridgell committed Mar 25, 2011
1 parent 7824111 commit b5616ad
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 108 deletions.
8 changes: 4 additions & 4 deletions lib/util/charset/charcnv.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ _PUBLIC_ ssize_t iconv_talloc(TALLOC_CTX *ctx,
* @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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions lib/util/charset/charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -159,24 +159,24 @@ 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);
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);
Expand All @@ -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);
Expand Down
48 changes: 24 additions & 24 deletions lib/util/charset/codepoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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;c1<NUM_CHARSETS;c1++) {
Expand Down Expand Up @@ -242,31 +242,31 @@ static const char *map_locale(const char *charset)
}

/*
the old_ic is passed in here as the smb_iconv_convenience structure
the old_ic is passed in here as the smb_iconv_handle structure
is used as a global pointer in some places (eg. python modules). We
don't want to invalidate those global pointers, but we do want to
update them with the right charset information when loadparm
runs. To do that we need to re-use the structure pointer, but
re-fill the elements in the structure with the updated values
*/
_PUBLIC_ struct smb_iconv_convenience *smb_iconv_convenience_reinit(TALLOC_CTX *mem_ctx,
_PUBLIC_ 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)
{
struct smb_iconv_convenience *ret;
struct smb_iconv_handle *ret;

display_charset = map_locale(display_charset);

if (old_ic != NULL) {
ret = old_ic;
close_iconv_convenience(ret);
close_iconv_handle(ret);
talloc_free(ret->child_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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}

/*
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions lib/util/charset/tests/iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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,
Expand Down
32 changes: 16 additions & 16 deletions lib/util/charset/util_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ _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;
if (s1 == NULL) return -1;
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit b5616ad

Please sign in to comment.