void strnorm_w(smb_ucs2_t *s, int case_default) { if (case_default == CASE_UPPER) { strupper_w(s); } else { strlower_w(s); } }
/******************************************************************* convert a string to "normal" form ********************************************************************/ void strnorm_w(smb_ucs2_t *s) { extern int case_default; if (case_default == CASE_UPPER) strupper_w(s); else strlower_w(s); }
/* * FIXME the size is a mess we really need a malloc/free logic *`dest size must be dest_len +2 */ size_t convert_charset ( charset_t from_set, charset_t to_set, charset_t cap_charset, const char *src, size_t src_len, char *dest, size_t dest_len, uint16_t *flags) { size_t i_len, o_len; ucs2_t *u; ucs2_t buffer[MAXPATHLEN +2]; ucs2_t buffer2[MAXPATHLEN +2]; lazy_initialize_conv(); /* convert from_set to UCS2 */ if ((size_t)(-1) == ( o_len = pull_charset_flags( from_set, to_set, cap_charset, src, src_len, (char *) buffer, sizeof(buffer) -2, flags)) ) { LOG(log_error, logtype_default, "Conversion failed ( %s to CH_UCS2 )", charset_name(from_set)); return (size_t) -1; } if ( o_len == 0) return o_len; /* Do pre/decomposition */ i_len = sizeof(buffer2) -2; u = buffer2; if (CHECK_FLAGS(flags, CONV_DECOMPOSE) || (charsets[to_set] && (charsets[to_set]->flags & CHARSET_DECOMPOSED)) ) { if ( (size_t)-1 == (i_len = decompose_w(buffer, o_len, u, &i_len)) ) return (size_t)(-1); } else if (CHECK_FLAGS(flags, CONV_PRECOMPOSE) || !charsets[from_set] || (charsets[from_set]->flags & CHARSET_DECOMPOSED)) { if ( (size_t)-1 == (i_len = precompose_w(buffer, o_len, u, &i_len)) ) return (size_t)(-1); } else { u = buffer; i_len = o_len; } /* null terminate */ u[i_len] = 0; u[i_len +1] = 0; /* Do case conversions */ if (CHECK_FLAGS(flags, CONV_TOUPPER)) { strupper_w(u); } else if (CHECK_FLAGS(flags, CONV_TOLOWER)) { strlower_w(u); } /* Convert UCS2 to to_set */ if ((size_t)(-1) == ( o_len = push_charset_flags( to_set, cap_charset, (char *)u, i_len, dest, dest_len, flags )) ) { LOG(log_error, logtype_default, "Conversion failed (CH_UCS2 to %s):%s", charset_name(to_set), strerror(errno)); return (size_t) -1; } /* null terminate */ dest[o_len] = 0; dest[o_len +1] = 0; return o_len; }
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; smb_ucs2_t *buffer = NULL; size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen, (void **)(void *)&buffer, True); if (size == (size_t)-1 || !buffer) { smb_panic("failed to create UCS2 buffer"); } if (!strlower_w(buffer) && (dest == src)) { SAFE_FREE(buffer); return srclen; } size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True); SAFE_FREE(buffer); return size; }
size_t charset_strlower(charset_t ch, const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; char *buffer; size = convert_string_allocate_internal(ch, CH_UCS2, src, srclen, (char **) &buffer); if (size == (size_t)-1) { SAFE_FREE(buffer); return size; } if (!strlower_w((ucs2_t *)buffer) && (dest == src)) { free(buffer); return srclen; } size = convert_string_internal(CH_UCS2, ch, buffer, size, dest, destlen); free(buffer); return size; }
char *strdup_lower(const char *s) { size_t size; smb_ucs2_t *buffer = NULL; char *out_buffer; size = push_ucs2_allocate(&buffer, s); if (size == -1 || !buffer) { return NULL; } strlower_w(buffer); size = pull_ucs2_allocate(&out_buffer, buffer); SAFE_FREE(buffer); if (size == (size_t)-1) { return NULL; } return out_buffer; }