ldb: Add helper function ldb_schema_attribute_fill_with_syntax()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 20 Oct 2016 03:01:42 +0000 (16:01 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 1 Dec 2016 04:54:23 +0000 (05:54 +0100)
This will allow us to avoid calling ldb_schema_attribute_add_with_syntax()
in a tight loop.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/common/ldb_attributes.c
lib/ldb/include/ldb_private.h

index ca6707edf65af1548bd4cbe803426599e831da67..2021a0bf64aac5f7fda0090280bcf8cf622ffa43 100644 (file)
 #include "ldb_private.h"
 #include "ldb_handlers.h"
 
+/*
+  fill in an attribute to the ldb_schema into the supplied buffer
+
+  if flags contains LDB_ATTR_FLAG_ALLOCATED
+  the attribute name string will be copied using
+  talloc_strdup(), otherwise it needs to be a static const
+  string at least with a lifetime longer than the ldb struct!
+
+  the ldb_schema_syntax structure should be a pointer
+  to a static const struct or at least it needs to be
+  a struct with a longer lifetime than the ldb context!
+
+*/
+int ldb_schema_attribute_fill_with_syntax(struct ldb_context *ldb,
+                                         TALLOC_CTX *mem_ctx,
+                                         const char *attribute,
+                                         unsigned flags,
+                                         const struct ldb_schema_syntax *syntax,
+                                         struct ldb_schema_attribute *a)
+{
+       a->name = attribute;
+       a->flags        = flags;
+       a->syntax       = syntax;
+
+       if (a->flags & LDB_ATTR_FLAG_ALLOCATED) {
+               a->name = talloc_strdup(mem_ctx, a->name);
+               if (a->name == NULL) {
+                       ldb_oom(ldb);
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
 /*
   add a attribute to the ldb_schema
 
index ef0b69715810834b37d90fb365b588584760c4fb..644d49cd23f6ad747cdd8310c1538dc9b5837dfa 100644 (file)
@@ -169,6 +169,12 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb);
   This is to permit correct reloads
 */
 void ldb_schema_attribute_remove_flagged(struct ldb_context *ldb, unsigned int flag);
+int ldb_schema_attribute_fill_with_syntax(struct ldb_context *ldb,
+                                         TALLOC_CTX *mem_ctx,
+                                         const char *attribute,
+                                         unsigned flags,
+                                         const struct ldb_schema_syntax *syntax,
+                                         struct ldb_schema_attribute *a);
 
 const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname);
 void ldb_subclass_remove(struct ldb_context *ldb, const char *classname);