ldap/servers/slapd/entry.c | 14 ++++++++++++--
ldap/servers/slapd/slapi-plugin.h | 21 +++++++++++++++++++--
2 files changed, 31 insertions(+), 4 deletions(-)
New commits:
commit 57af5622333165360d9e2b5764a8375e4c2ccb7f
Author: Noriko Hosoi <nhosoi(a)redhat.com>
Date: Tue Feb 11 10:28:46 2014 -0800
Ticket #47608 - change slapi_entry_attr_get_bool to handle
"on"/"off" values, support default value
Description: Adding an API slapi_entry_attr_get_bool_ext, which is an
extension of slapi_entry_attr_get_bool. The difference is slapi_
entry_attr_get_bool_ext returns the given default value if the type
is not found in the entry.
https://fedorahosted.org/389/ticket/47608
Reviewed by rmeggins(a)redhat.com (Thank you, Rich!!)
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index 3de05ad..9dc94b3 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -2973,9 +2973,9 @@ slapi_entry_attr_get_ulonglong( const Slapi_Entry* e, const char
*type)
/* returned value: attribute value as a boolean type */
PRBool
-slapi_entry_attr_get_bool( const Slapi_Entry* e, const char *type)
+slapi_entry_attr_get_bool_ext(const Slapi_Entry* e, const char *type, PRBool
default_value)
{
- PRBool r = PR_FALSE; /* default if no attr */
+ PRBool r = default_value; /* default if no attr */
Slapi_Attr* attr = NULL;
if ((0 == slapi_entry_attr_find(e, type, &attr)) && attr) {
Slapi_Value *v;
@@ -2997,6 +2997,10 @@ slapi_entry_attr_get_bool( const Slapi_Entry* e, const char *type)
r = PR_TRUE;
} else if (!PL_strncasecmp(bvp->bv_val, "no", bvp->bv_len)) {
r = PR_FALSE;
+ } else if (!PL_strncmp(bvp->bv_val, "1", bvp->bv_len)) {
+ r = PR_TRUE;
+ } else if (!PL_strncmp(bvp->bv_val, "0", bvp->bv_len)) {
+ r = PR_FALSE;
} else { /* assume numeric: 0 - false: non-zero - true */
r = (PRBool)slapi_value_get_ulong(v);
}
@@ -3004,6 +3008,12 @@ slapi_entry_attr_get_bool( const Slapi_Entry* e, const char *type)
return r;
}
+PRBool
+slapi_entry_attr_get_bool(const Slapi_Entry* e, const char *type)
+{
+ return slapi_entry_attr_get_bool_ext(e, type, PR_FALSE);
+}
+
void
slapi_entry_attr_set_charptr( Slapi_Entry* e, const char *type, const char *value)
{
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index a4682b5..2f24251 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -1872,14 +1872,31 @@ unsigned long long slapi_entry_attr_get_ulonglong( const
Slapi_Entry* e, const c
*
* Comparisons are case-insensitive (\c TRUE, \c trUe, and \c true are all the
* same), and unique substrings can be matched (\c t and \c tr will be interpreted
- * as \c true). If the attribute value is a number, then non-zero numbers are
+ * as \c true). In addition, \c on, \c off, \c yes, \c no are supported.
+ * If the attribute value is a number, then non-zero numbers are
* interpreted as \c true, and \c 0 is interpreted as \c false.
*
* \param e Entry from which you want to get the boolean value.
* \param type Attribute type from which you want to get the value.
* \return \c PR_TRUE | \c PR_FALSE
*/
-PRBool slapi_entry_attr_get_bool( const Slapi_Entry* e, const char *type);
+PRBool slapi_entry_attr_get_bool(const Slapi_Entry* e, const char *type);
+
+/**
+ * Gets the value of a given attribute of a given entry as a boolean value.
+ *
+ * Comparisons are case-insensitive (\c TRUE, \c trUe, and \c true are all the
+ * same), and unique substrings can be matched (\c t and \c tr will be interpreted
+ * as \c true). In addition, \c on, \c off, \c yes, \c no are supported.
+ * If the attribute value is a number, then non-zero numbers are
+ * interpreted as \c true, and \c 0 is interpreted as \c false.
+ * If the attribute type is not found in the entry, the given default value is returned.
+ *
+ * \param e Entry from which you want to get the boolean value.
+ * \param type Attribute type from which you want to get the value.
+ * \return \c PR_TRUE | \c PR_FALSE
+ */
+PRBool slapi_entry_attr_get_bool_ext(const Slapi_Entry* e, const char *type, PRBool
default_value);
/**
* Replaces the value or values of an attribute in an entry with a specified string