s4-ldb: Separate function to add empty element into ldb_msg
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 9 Jul 2010 18:36:39 +0000 (21:36 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Sat, 10 Jul 2010 20:03:14 +0000 (23:03 +0300)
It just adds another element, nothing more.
Caller is responsible to fill-in the added element and
determine how to handle data allocation contexts.

source4/lib/ldb/common/ldb_msg.c

index 719373ea3be1cece7ad2b39f2d487f68a32308c4..678fbcd00d28305ea34a0d98c49fba963151f6ca 100644 (file)
@@ -114,6 +114,35 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v)
        return v2;
 }
 
+/**
+ * Adds new empty element to msg->elements
+ */
+static int _ldb_msg_add_el(struct ldb_message *msg,
+                          struct ldb_message_element **return_el)
+{
+       struct ldb_message_element *els;
+
+       /* TODO: Find out a way to assert
+        * on input parameters.
+        * msg and return_el must be valid */
+
+       els = talloc_realloc(msg, msg->elements,
+                            struct ldb_message_element, msg->num_elements + 1);
+       if (!els) {
+               errno = ENOMEM;
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
+       ZERO_STRUCT(els[msg->num_elements]);
+
+       msg->elements = els;
+       msg->num_elements++;
+
+       *return_el = &els[msg->num_elements-1];
+
+       return LDB_SUCCESS;
+}
+
 /*
   add an empty element to a message
 */