s4:ldb: add ldb_parse_tree_copy_shallow() and change version to 0.9.7
authorStefan Metzmacher <metze@samba.org>
Sun, 20 Sep 2009 03:41:42 +0000 (05:41 +0200)
committerStefan Metzmacher <metze@samba.org>
Sun, 20 Sep 2009 04:44:16 +0000 (06:44 +0200)
metze

source4/lib/ldb/common/ldb_parse.c
source4/lib/ldb/configure.ac
source4/lib/ldb/include/ldb.h

index 0fab0026f39bbcd1ae97938865e1f08f0489df73..7f347c51df564d05a49704a76155f4b0b107b36a 100644 (file)
@@ -818,3 +818,61 @@ void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
                break;
        }
 }
+
+/*
+  shallow copy a tree - copying only the elements array so that the caller
+  can safely add new elements without changing the message
+*/
+struct ldb_parse_tree *ldb_parse_tree_copy_shallow(TALLOC_CTX *mem_ctx,
+                                                  const struct ldb_parse_tree *ot)
+{
+       int i;
+       struct ldb_parse_tree *nt;
+
+       nt = talloc(mem_ctx, struct ldb_parse_tree);
+       if (!nt) {
+               return NULL;
+       }
+
+       *nt = *ot;
+
+       switch (ot->operation) {
+       case LDB_OP_AND:
+       case LDB_OP_OR:
+               nt->u.list.elements = talloc_array(nt, struct ldb_parse_tree,
+                                                  ot->u.list.num_elements);
+               if (!nt->u.list.elements) {
+                       talloc_free(nt);
+                       return NULL;
+               }
+
+               for (i=0;i<ot->u.list.num_elements;i++) {
+                       nt->u.list.elements[i] =
+                               ldb_parse_tree_copy_shallow(nt->u.list.elements,
+                                               ot->u.list.elements[i]);
+                       if (!nt->u.list.elements[i]) {
+                               talloc_free(nt);
+                               return NULL;
+                       }
+               }
+               break;
+       case LDB_OP_NOT:
+               nt->u.isnot.child = ldb_parse_tree_copy_shallow(nt,
+                                                       ot->u.isnot.child);
+               if (!nt->u.isnot.child) {
+                       talloc_free(nt);
+                       return NULL;
+               }
+               break;
+       case LDB_OP_EQUALITY:
+       case LDB_OP_GREATER:
+       case LDB_OP_LESS:
+       case LDB_OP_APPROX:
+       case LDB_OP_SUBSTRING:
+       case LDB_OP_PRESENT:
+       case LDB_OP_EXTENDED:
+               break;
+       }
+
+       return nt;
+}
index f33d8303576d07ccb5a404e1985c18448e369b60..a0fab6d786159a58f048c768aa1098f3b5ade42e 100644 (file)
@@ -11,7 +11,7 @@ AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""])
 AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
 AC_DEFUN([SMB_EXT_LIB], [echo -n ""])
 AC_DEFUN([SMB_ENABLE], [echo -n ""])
-AC_INIT(ldb, 0.9.6)
+AC_INIT(ldb, 0.9.7)
 AC_CONFIG_SRCDIR([common/ldb.c])
 
 AC_LIBREPLACE_ALL_CHECKS
index 2c890319192bf9cb633172557cf46cc5cd2fbd1e..047e66c8b768a87d656595b3cd3934e460ae4a5a 100644 (file)
@@ -1835,6 +1835,12 @@ void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
                                 const char *attr, 
                                 const char *replace);
 
+/*
+  shallow copy a tree - copying only the elements array so that the caller
+  can safely add new elements without changing the message
+*/
+struct ldb_parse_tree *ldb_parse_tree_copy_shallow(TALLOC_CTX *mem_ctx,
+                                                  const struct ldb_parse_tree *ot);
 
 /**
    Convert a time structure to a string