From 265023fafa463c742f89510879acb2a830de8ab9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 May 2004 23:54:41 +0000 Subject: r574: - another attempt at const cleanliness in ldb - fixed a problem with searching for values containing an '=' sign - fixed the semantics of attempting an attribute deletion on an attribute that doesn't exist. - added some more ldb_msg_*() utilities (This used to be commit 62b4ec367d170330d837b0f1fe5cd13205a53b59) --- source4/lib/ldb/common/ldb_msg.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source4/lib/ldb/common/ldb_msg.c') diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 5976db81b6..01f32751e1 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -131,6 +131,53 @@ int ldb_msg_add(struct ldb_context *ldb, return 0; } +/* + add a value to a message +*/ +int ldb_msg_add_value(struct ldb_context *ldb, + struct ldb_message *msg, + char *attr_name, + struct ldb_val *val) +{ + struct ldb_message_element *el; + struct ldb_val *vals; + + el = ldb_msg_find_element(msg, attr_name); + if (!el) { + ldb_msg_add_empty(ldb, msg, attr_name, 0); + el = ldb_msg_find_element(msg, attr_name); + } + if (!el) { + return -1; + } + + vals = ldb_realloc_p(ldb, el->values, struct ldb_val, el->num_values+1); + if (!vals) { + errno = ENOMEM; + return -1; + } + el->values = vals; + el->values[el->num_values] = *val; + el->num_values++; + + return 0; +} + + +/* + add a string element to a message +*/ +int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg, + char *attr_name, char *str) +{ + struct ldb_val val; + + val.data = str; + val.length = strlen(str); + + return ldb_msg_add_value(ldb, msg, attr_name, &val); +} + /* compare two ldb_message_element structures assumes case senistive comparison -- cgit