svn commit: samba r13335 - in branches/SAMBA_4_0/source/lib: . ldb/common ldb/include ldb/ldb_tdb

idra at samba.org idra at samba.org
Sat Feb 4 07:57:57 GMT 2006


Author: idra
Date: 2006-02-04 07:57:57 +0000 (Sat, 04 Feb 2006)
New Revision: 13335

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=13335

Log:

Fix the build and add an utf8 safe ldb_hadler_fold function
based on ldb_casefold


Modified:
   branches/SAMBA_4_0/source/lib/db_wrap.c
   branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/db_wrap.c
===================================================================
--- branches/SAMBA_4_0/source/lib/db_wrap.c	2006-02-04 07:56:30 UTC (rev 13334)
+++ branches/SAMBA_4_0/source/lib/db_wrap.c	2006-02-04 07:57:57 UTC (rev 13335)
@@ -55,12 +55,12 @@
 	free(s);
 }
 
-static int wrap_caseless_cmp(void *context, const char *s1, const char *s2)
+int wrap_caseless_cmp(void *context, const char *s1, const char *s2)
 {
 	return strcasecmp_m(s1, s2);
 }
 
-static char *wrap_casefold(void *context, void *mem_ctx, const char *s)
+char *wrap_casefold(void *context, void *mem_ctx, const char *s)
 {
 	return strupper_talloc(mem_ctx, s);
 }

Modified: branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2006-02-04 07:56:30 UTC (rev 13334)
+++ branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2006-02-04 07:57:57 UTC (rev 13335)
@@ -46,32 +46,60 @@
 /*
   a case folding copy handler, removing leading and trailing spaces and
   multiple internal spaces
+
+  We exploit the fact that utf8 never uses the space octet except for
+  the space itself
 */
 static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx,
 			    const struct ldb_val *in, struct ldb_val *out)
 {
-	uint8_t *s1, *s2;
-	out->data = talloc_size(mem_ctx, strlen((char *)in->data)+1);
+	char *s, *t;
+	int l;
+	if (!in || !out || !(in->data)) {
+		return -1;
+	}
+
+	out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data));
 	if (out->data == NULL) {
-		ldb_oom(ldb);
+		ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_handler_fold: unable to casefold string [%s]", in->data);
 		return -1;
 	}
-	s1 = in->data;
-	s2 = out->data;
-	while (*s1 == ' ') s1++;
-	while (*s1) {
-		*s2 = toupper(*s1);
-		if (s1[0] == ' ') {
-			while (s1[0] == s1[1]) s1++;
+
+	s = (char *)(out->data);
+	
+	/* remove trailing spaces if any */
+	l = strlen(s);
+	while (s[l - 1] == ' ') l--;
+	s[l] = '\0';
+	
+	/* remove leading spaces if any */
+	if (*s == ' ') {
+		for (t = s; *s == ' '; s++) ;
+
+		/* remove leading spaces by moving down the string */
+		memmove(t, s, l);
+
+		s = t;
+	}
+
+	/* check middle spaces */
+	while ((t = strchr(s, ' ')) != NULL) {
+		for (s = t; *s == ' '; s++) ;
+
+		if ((s - t) > 1) {
+			l = strlen(s);
+
+			/* remove all spaces but one by moving down the string */
+			memmove(t + 1, s, l);
 		}
-		s2++; s1++;
 	}
-	*s2 = 0;
+
 	out->length = strlen((char *)out->data);
 	return 0;
 }
 
 
+
 /*
   canonicalise a ldap Integer
   rfc2252 specifies it should be in decimal form
@@ -114,8 +142,8 @@
 }
 
 /*
-  compare two case insensitive strings, ignoring multiple whitespace
-  and leading and trailing whitespace
+  compare two case insensitive strings, ignoring multiple whitespaces
+  and leading and trailing whitespaces
   see rfc2252 section 8.1
 */
 static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx,

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-02-04 07:56:30 UTC (rev 13334)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-02-04 07:57:57 UTC (rev 13335)
@@ -970,6 +970,7 @@
    case; non-zero if there are any differences
 */
 int ldb_attr_cmp(const char *attr1, const char *attr2);
+char *ldb_attr_casefold(void *mem_ctx, const char *s);
 int ldb_attr_dn(const char *attr);
 char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value);
 

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c	2006-02-04 07:56:30 UTC (rev 13334)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_index.c	2006-02-04 07:57:57 UTC (rev 13335)
@@ -106,7 +106,7 @@
 	const struct ldb_attrib_handler *h;
 	char *attr_folded;
 
-	attr_folded = ldb_attr_casefold(ldb, ldb, attr);
+	attr_folded = ldb_attr_casefold(ldb, attr);
 	if (!attr_folded) {
 		return NULL;
 	}



More information about the samba-cvs mailing list