summaryrefslogtreecommitdiffstats
path: root/source4/libads
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-08 08:13:00 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:39 -0500
commit7d32679e9683c81aca538f0267684332a28a286f (patch)
tree445aecfad24e8dab1fe7a200904a712212fa7091 /source4/libads
parent48f960ab47707ca24898834da4da440d1f7fb0d9 (diff)
downloadsamba-7d32679e9683c81aca538f0267684332a28a286f.tar.gz
samba-7d32679e9683c81aca538f0267684332a28a286f.tar.xz
samba-7d32679e9683c81aca538f0267684332a28a286f.zip
r2857: this commit gets rid of smb_ucs2_t, wpstring and fpstring, plus lots of associated functions.
The motivation for this change was to avoid having to convert to/from ucs2 strings for so many operations. Doing that was slow, used many static buffers, and was also incorrect as it didn't cope properly with unicode codepoints above 65536 (which could not be represented correctly as smb_ucs2_t chars) The two core functions that allowed this change are next_codepoint() and push_codepoint(). These functions allow you to correctly walk a arbitrary multi-byte string a character at a time without converting the whole string to ucs2. While doing this cleanup I also fixed several ucs2 string handling bugs. See the commit for details. The following code (which counts the number of occuraces of 'c' in a string) shows how to use the new interface: size_t count_chars(const char *s, char c) { size_t count = 0; while (*s) { size_t size; codepoint_t c2 = next_codepoint(s, &size); if (c2 == c) count++; s += size; } return count; } (This used to be commit 814881f0e50019196b3aa9fbe4aeadbb98172040)
Diffstat (limited to 'source4/libads')
-rw-r--r--source4/libads/ldap_printer.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/source4/libads/ldap_printer.c b/source4/libads/ldap_printer.c
index 005481cd97b..71cc8a531f3 100644
--- a/source4/libads/ldap_printer.c
+++ b/source4/libads/ldap_printer.c
@@ -98,8 +98,8 @@ static BOOL map_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
if (value->type != REG_SZ)
return False;
- if (value->size && *((smb_ucs2_t *) value->data_p)) {
- pull_ucs2_talloc(ctx, &str_value, (const smb_ucs2_t *) value->data_p);
+ if (value->size && SVAL(value->data_p, 0)) {
+ pull_ucs2_talloc(ctx, &str_value, value->data_p);
status = ads_mod_str(ctx, mods, value->valuename, str_value);
return ADS_ERR_OK(status);
}
@@ -147,29 +147,28 @@ static BOOL map_multi_sz(TALLOC_CTX *ctx, ADS_MODLIST *mods,
const REGISTRY_VALUE *value)
{
char **str_values = NULL;
- smb_ucs2_t *cur_str = (smb_ucs2_t *) value->data_p;
+ char *cur_str = value->data_p;
uint32_t size = 0, num_vals = 0, i=0;
ADS_STATUS status;
if (value->type != REG_MULTI_SZ)
return False;
- while(cur_str && *cur_str && (size < value->size)) {
- size += 2 * (strlen_w(cur_str) + 1);
- cur_str += strlen_w(cur_str) + 1;
+ while (cur_str && *cur_str && (size < value->size)) {
+ size_t this_size = utf16_len(cur_str);
+ cur_str += this_size;
+ size += this_size;
num_vals++;
};
if (num_vals) {
- str_values = talloc(ctx,
- (num_vals + 1) * sizeof(smb_ucs2_t *));
- memset(str_values, '\0',
- (num_vals + 1) * sizeof(smb_ucs2_t *));
-
- cur_str = (smb_ucs2_t *) value->data_p;
- for (i=0; i < num_vals; i++)
- cur_str += pull_ucs2_talloc(ctx, &str_values[i],
- cur_str);
+ str_values = talloc_array_p(ctx, char *, num_vals + 1);
+ cur_str = value->data_p;
+ for (i=0; i < num_vals; i++) {
+ pull_ucs2_talloc(ctx, &str_values[i], cur_str);
+ cur_str += utf16_len(cur_str);
+ }
+ str_values[i] = NULL;
status = ads_mod_strlist(ctx, mods, value->valuename,
(const char **) str_values);