From 31780c2add620f84fe0d10c83c33057f06fe1d25 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 12 Jun 2008 14:47:55 +0000 Subject: [PATCH] added support for deleting attribute type from the list of attributes --- contrib/ldapc++/src/LDAPAttributeList.cpp | 26 +++++++++++++++-------- contrib/ldapc++/src/LDAPAttributeList.h | 6 ++++++ contrib/ldapc++/src/LDAPEntry.cpp | 5 +++++ contrib/ldapc++/src/LDAPEntry.h | 7 ++++++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/contrib/ldapc++/src/LDAPAttributeList.cpp b/contrib/ldapc++/src/LDAPAttributeList.cpp index a8dbc184eb..de17579a55 100644 --- a/contrib/ldapc++/src/LDAPAttributeList.cpp +++ b/contrib/ldapc++/src/LDAPAttributeList.cpp @@ -140,6 +140,22 @@ void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){ } } +void LDAPAttributeList::delAttribute(const std::string& type) +{ + DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl); + DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER, " type: " << type << endl); + LDAPAttributeList::iterator i; + for( i = m_attrs.begin(); i != m_attrs.end(); i++){ + if(type.size() == i->getName().size()){ + if(equal(type.begin(), type.end(), i->getName().begin(), + nocase_compare)){ + m_attrs.erase(i); + break; + } + } + } +} + void LDAPAttributeList::replaceAttribute(const LDAPAttribute& attr) { DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl); @@ -147,15 +163,7 @@ void LDAPAttributeList::replaceAttribute(const LDAPAttribute& attr) " attr:" << attr << endl); LDAPAttributeList::iterator i; - for( i = m_attrs.begin(); i != m_attrs.end(); i++){ - if(attr.getName().size() == i->getName().size()){ - if(equal(attr.getName().begin(), attr.getName().end(), i->getName().begin(), - nocase_compare)){ - m_attrs.erase(i); - break; - } - } - } + this->delAttribute( attr.getName() ); m_attrs.push_back(attr); } diff --git a/contrib/ldapc++/src/LDAPAttributeList.h b/contrib/ldapc++/src/LDAPAttributeList.h index 7f9161ae80..1e6ba6d51e 100644 --- a/contrib/ldapc++/src/LDAPAttributeList.h +++ b/contrib/ldapc++/src/LDAPAttributeList.h @@ -90,6 +90,12 @@ class LDAPAttributeList{ * @param attr The attribute to add to the list. */ void addAttribute(const LDAPAttribute& attr); + + /** + * Deletes all values of an Attribute for the list + * @param type The attribute type to be deleted. + */ + void delAttribute(const std::string& type); /** * Replace an Attribute in the List diff --git a/contrib/ldapc++/src/LDAPEntry.cpp b/contrib/ldapc++/src/LDAPEntry.cpp index 19b99a1e94..bdf7fa8f2e 100644 --- a/contrib/ldapc++/src/LDAPEntry.cpp +++ b/contrib/ldapc++/src/LDAPEntry.cpp @@ -88,6 +88,11 @@ void LDAPEntry::addAttribute(const LDAPAttribute& attr) m_attrs->addAttribute(attr); } +void LDAPEntry::delAttribute(const std::string& type) +{ + m_attrs->delAttribute(type); +} + void LDAPEntry::replaceAttribute(const LDAPAttribute& attr) { m_attrs->replaceAttribute(attr); diff --git a/contrib/ldapc++/src/LDAPEntry.h b/contrib/ldapc++/src/LDAPEntry.h index bb16fe8c6b..9f2aaf0257 100644 --- a/contrib/ldapc++/src/LDAPEntry.h +++ b/contrib/ldapc++/src/LDAPEntry.h @@ -78,6 +78,13 @@ class LDAPEntry{ * @param attr The attribute to add to the list. */ void addAttribute(const LDAPAttribute& attr); + + /** + * Deletes all values of an Attribute from the list of Attributes + * (simple wrapper around LDAPAttributeList::delAttribute() ). + * @param type The attribute to delete. + */ + void delAttribute(const std::string& type); /** * Replace an Attribute in the List of Attributes (simple wrapper