s4-ldb: Add separate function to add empty element into ldb_msg
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 16 Jul 2010 10:44:13 +0000 (13:44 +0300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 19 Jul 2010 07:33:34 +0000 (17:33 +1000)
It just adds another element, nothing more.
Caller is responsible to fill-in the added element and
determine how to handle data allocation contexts.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
source4/lib/ldb/common/ldb_msg.c

index ca7b9619538a137105621987eb70826515b065e9..444ba0a7f472569cb36dc1cae8498d215a491f7d 100644 (file)
@@ -114,6 +114,36 @@ 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
 */