-/*
+/*
ldb database library
Copyright (C) Andrew Tridgell 2004
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
** under the LGPL
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
/*
find an element in a message by attribute name
*/
-struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg,
+struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg,
const char *attr_name)
{
unsigned int i;
find a value in an element
assumes case sensitive comparison
*/
-struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
+struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el,
struct ldb_val *val)
{
unsigned int i;
* is invalidated for some reason, this will
* corrupt *msg contents also
*/
-int ldb_msg_add(struct ldb_message *msg,
- const struct ldb_message_element *el,
+int ldb_msg_add(struct ldb_message *msg,
+ const struct ldb_message_element *el,
int flags)
{
int ret;
/*
add a value to a message
*/
-int ldb_msg_add_value(struct ldb_message *msg,
+int ldb_msg_add_value(struct ldb_message *msg,
const char *attr_name,
const struct ldb_val *val,
struct ldb_message_element **return_el)
/*
add a value to a message, stealing it into the 'right' place
*/
-int ldb_msg_add_steal_value(struct ldb_message *msg,
+int ldb_msg_add_steal_value(struct ldb_message *msg,
const char *attr_name,
struct ldb_val *val)
{
/*
add a string element to a message
*/
-int ldb_msg_add_string(struct ldb_message *msg,
+int ldb_msg_add_string(struct ldb_message *msg,
const char *attr_name, const char *str)
{
struct ldb_val val;
/*
add a string element to a message, stealing it into the 'right' place
*/
-int ldb_msg_add_steal_string(struct ldb_message *msg,
+int ldb_msg_add_steal_string(struct ldb_message *msg,
const char *attr_name, char *str)
{
struct ldb_val val;
/*
add a printf formatted element to a message
*/
-int ldb_msg_add_fmt(struct ldb_message *msg,
+int ldb_msg_add_fmt(struct ldb_message *msg,
const char *attr_name, const char *fmt, ...)
{
struct ldb_val val;
compare two ldb_message_element structures
assumes case sensitive comparison
*/
-int ldb_msg_element_compare(struct ldb_message_element *el1,
+int ldb_msg_element_compare(struct ldb_message_element *el1,
struct ldb_message_element *el2)
{
unsigned int i;
compare two ldb_message_element structures
comparing by element name
*/
-int ldb_msg_element_compare_name(struct ldb_message_element *el1,
+int ldb_msg_element_compare_name(struct ldb_message_element *el1,
struct ldb_message_element *el2)
{
return ldb_attr_cmp(el1->name, el2->name);
convenience functions to return common types from a message
these return the first value if the attribute is multi-valued
*/
-const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg,
+const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg,
const char *attr_name)
{
struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name);
return &el->values[0];
}
-int ldb_msg_find_attr_as_int(const struct ldb_message *msg,
+int ldb_msg_find_attr_as_int(const struct ldb_message *msg,
const char *attr_name,
int default_value)
{
return ret;
}
-int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg,
+int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg,
const char *attr_name,
int64_t default_value)
{
return ret;
}
-double ldb_msg_find_attr_as_double(const struct ldb_message *msg,
+double ldb_msg_find_attr_as_double(const struct ldb_message *msg,
const char *attr_name,
double default_value)
{
return ret;
}
-int ldb_msg_find_attr_as_bool(const struct ldb_message *msg,
+int ldb_msg_find_attr_as_bool(const struct ldb_message *msg,
const char *attr_name,
int default_value)
{
return default_value;
}
-const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg,
+const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg,
const char *attr_name,
const char *default_value)
{
shallow copy a message - copying only the elements array so that the caller
can safely add new elements without changing the message
*/
-struct ldb_message *ldb_msg_copy_shallow(TALLOC_CTX *mem_ctx,
+struct ldb_message *ldb_msg_copy_shallow(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg)
{
struct ldb_message *msg2;
*msg2 = *msg;
- msg2->elements = talloc_array(msg2, struct ldb_message_element,
+ msg2->elements = talloc_array(msg2, struct ldb_message_element,
msg2->num_elements);
if (msg2->elements == NULL) goto failed;
/*
copy a message, allocating new memory for all parts
*/
-struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx,
+struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx,
const struct ldb_message *msg)
{
struct ldb_message *msg2;
/**
* Canonicalize a message, merging elements of the same name
*/
-struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb,
+struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb,
const struct ldb_message *msg)
{
int ret;
* If you then use this in a ldb_modify() call,
* it can be used to save edits to a message
*/
-struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
+struct ldb_message *ldb_msg_diff(struct ldb_context *ldb,
struct ldb_message *msg1,
struct ldb_message *msg2)
{
}
-int ldb_msg_sanity_check(struct ldb_context *ldb,
+int ldb_msg_sanity_check(struct ldb_context *ldb,
const struct ldb_message *msg)
{
unsigned int i, j;
if (msg->elements[i].values[j].length == 0) {
/* an attribute cannot be empty */
ldb_asprintf_errstring(ldb, "Element %s has empty attribute in ldb message (%s)!",
- msg->elements[i].name,
+ msg->elements[i].name,
ldb_dn_get_linearized(msg->dn));
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
time_t ldb_string_to_time(const char *s)
{
struct tm tm;
-
+
if (s == NULL) return 0;
-
+
memset(&tm, 0, sizeof(tm));
if (sscanf(s, "%04u%02u%02u%02u%02u%02u.0Z",
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
return 0;
}
tm.tm_year -= 1900;
tm.tm_mon -= 1;
-
+
return timegm(&tm);
}
time_t ldb_string_utc_to_time(const char *s)
{
struct tm tm;
-
+
if (s == NULL) return 0;
-
+
memset(&tm, 0, sizeof(tm));
if (sscanf(s, "%02u%02u%02u%02u%02u%02uZ",
- &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
return 0;
}
tm.tm_year += 100;
}
tm.tm_mon -= 1;
-
+
return timegm(&tm);
}
{
struct ldb_message_element *el;
struct ldb_val val;
-
+
el = ldb_msg_find_element(msg, name);
if (el == NULL) {
return 0;