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

metze at samba.org metze at samba.org
Thu Dec 14 10:03:22 GMT 2006


Author: metze
Date: 2006-12-14 10:03:21 +0000 (Thu, 14 Dec 2006)
New Revision: 20168

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

Log:
start separating attributes and syntaxes

metze
Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
   branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2006-12-14 08:25:24 UTC (rev 20167)
+++ branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2006-12-14 10:03:21 UTC (rev 20168)
@@ -336,50 +336,44 @@
 /*
   table of standard attribute handlers
 */
-static const struct ldb_attrib_handler ldb_standard_attribs[] = {
+static const struct ldb_schema_syntax ldb_standard_syntaxes[] = {
 	{ 
-		.attr            = LDB_SYNTAX_INTEGER,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_INTEGER,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_canonicalise_Integer,
 		.comparison_fn   = ldb_comparison_Integer
 	},
 	{ 
-		.attr            = LDB_SYNTAX_OCTET_STRING,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_OCTET_STRING,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_handler_copy,
 		.comparison_fn   = ldb_comparison_binary
 	},
 	{ 
-		.attr            = LDB_SYNTAX_DIRECTORY_STRING,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_DIRECTORY_STRING,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_handler_fold,
 		.comparison_fn   = ldb_comparison_fold
 	},
 	{ 
-		.attr            = LDB_SYNTAX_DN,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_DN,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_canonicalise_dn,
 		.comparison_fn   = ldb_comparison_dn
 	},
 	{ 
-		.attr            = LDB_SYNTAX_OBJECTCLASS,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_OBJECTCLASS,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_handler_fold,
 		.comparison_fn   = ldb_comparison_objectclass
 	},
 	{ 
-		.attr            = LDB_SYNTAX_UTC_TIME,
-		.flags           = 0,
+		.name            = LDB_SYNTAX_UTC_TIME,
 		.ldif_read_fn    = ldb_handler_copy,
 		.ldif_write_fn   = ldb_handler_copy,
 		.canonicalise_fn = ldb_canonicalise_utctime,
@@ -391,17 +385,16 @@
 /*
   return the attribute handlers for a given syntax name
 */
-const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb,
-							   const char *syntax)
+const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
+							    const char *syntax)
 {
 	int i;
-	unsigned num_handlers = sizeof(ldb_standard_attribs)/sizeof(ldb_standard_attribs[0]);
+	unsigned num_handlers = sizeof(ldb_standard_syntaxes)/sizeof(ldb_standard_syntaxes[0]);
 	/* TODO: should be replaced with a binary search */
 	for (i=0;i<num_handlers;i++) {
-		if (strcmp(ldb_standard_attribs[i].attr, syntax) == 0) {
-			return &ldb_standard_attribs[i];
+		if (strcmp(ldb_standard_syntaxes[i].name, syntax) == 0) {
+			return &ldb_standard_syntaxes[i];
 		}
 	}
 	return NULL;
 }
-

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2006-12-14 08:25:24 UTC (rev 20167)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2006-12-14 10:03:21 UTC (rev 20168)
@@ -149,15 +149,20 @@
 int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, 
 				  const char *attr, const char *syntax)
 {
-	const struct ldb_attrib_handler *h = ldb_attrib_handler_syntax(ldb, syntax);
-	struct ldb_attrib_handler h2;
-	if (h == NULL) {
-		ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", syntax);
+	const struct ldb_schema_syntax *s = ldb_standard_syntax_by_name(ldb, syntax);
+	struct ldb_attrib_handler h;
+	if (s == NULL) {
+       		ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", syntax);
 		return -1;
 	}
-	h2 = *h;
-	h2.attr = attr;
-	return ldb_set_attrib_handlers(ldb, &h2, 1);
+	h.attr = attr;
+	h.flags = 0;
+	h.ldif_read_fn = s->ldif_read_fn;
+	h.ldif_write_fn = s->ldif_write_fn;
+	h.canonicalise_fn = s->canonicalise_fn;
+	h.comparison_fn = s->comparison_fn;
+
+	return ldb_set_attrib_handlers(ldb, &h, 1);
 }
 
 /*

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-12-14 08:25:24 UTC (rev 20167)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2006-12-14 10:03:21 UTC (rev 20168)
@@ -340,6 +340,14 @@
 	ldb_attr_comparison_t comparison_fn;
 };
 
+struct ldb_schema_syntax {
+	const char *name;
+	ldb_attr_handler_t ldif_read_fn;
+	ldb_attr_handler_t ldif_write_fn;
+	ldb_attr_handler_t canonicalise_fn;
+	ldb_attr_comparison_t comparison_fn;
+};
+
 /**
    The attribute is not returned by default
 */

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-12-14 08:25:24 UTC (rev 20167)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb_private.h	2006-12-14 10:03:21 UTC (rev 20168)
@@ -184,8 +184,8 @@
 		  enum ldb_scope scope);
 
 void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib);
-const struct ldb_attrib_handler *ldb_attrib_handler_syntax(struct ldb_context *ldb,
-							   const char *syntax);
+const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
+							    const char *syntax);
 int ldb_set_attrib_handlers(struct ldb_context *ldb, 
 			    const struct ldb_attrib_handler *handlers, 
 			    unsigned num_handlers);

Modified: branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-12-14 08:25:24 UTC (rev 20167)
+++ branches/SAMBA_4_0/source/lib/ldb/ldb_tdb/ldb_cache.c	2006-12-14 10:03:21 UTC (rev 20168)
@@ -125,8 +125,8 @@
 	for (i=0;i<msg->num_elements;i++) {
 		unsigned flags;
 		const char *syntax;
-		const struct ldb_attrib_handler *h;
-		struct ldb_attrib_handler h2;
+		const struct ldb_schema_syntax *s;
+		struct ldb_attrib_handler h;
 
 		if (ltdb_attributes_flags(&msg->elements[i], &flags) != 0) {
 			ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Invalid @ATTRIBUTES element for '%s'\n", msg->elements[i].name);
@@ -149,17 +149,21 @@
 			goto failed;
 		}
 
-		h = ldb_attrib_handler_syntax(module->ldb, syntax);
-		if (h == NULL) {
+		s = ldb_standard_syntax_by_name(module->ldb, syntax);
+		if (s == NULL) {
 			ldb_debug(module->ldb, LDB_DEBUG_ERROR, 
 				  "Invalid attribute syntax '%s' for '%s' in @ATTRIBUTES\n",
 				  syntax, msg->elements[i].name);
 			goto failed;
 		}
-		h2 = *h;
-		h2.attr = msg->elements[i].name;
-		h2.flags |= LDB_ATTR_FLAG_ALLOCATED;
-		if (ldb_set_attrib_handlers(module->ldb, &h2, 1) != 0) {
+		h.attr = msg->elements[i].name;
+		h.flags |= LDB_ATTR_FLAG_ALLOCATED;
+		h.ldif_read_fn = s->ldif_read_fn;
+		h.ldif_write_fn = s->ldif_write_fn;
+		h.canonicalise_fn = s->canonicalise_fn;
+		h.comparison_fn = s->comparison_fn;
+
+		if (ldb_set_attrib_handlers(module->ldb, &h, 1) != 0) {
 			goto failed;
 		}
 	}



More information about the samba-cvs mailing list