Skip to content
Snippets Groups Projects
Commit fc575a10 authored by Quanah Gibson-Mount's avatar Quanah Gibson-Mount
Browse files

add wrapper methods to add/replace Attributes

parent 8f8e1524
No related branches found
No related tags found
No related merge requests found
...@@ -139,6 +139,24 @@ void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){ ...@@ -139,6 +139,24 @@ void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){
} }
} }
void LDAPAttributeList::replaceAttribute(const LDAPAttribute& attr)
{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
" 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;
}
}
}
m_attrs.push_back(attr);
}
LDAPMod** LDAPAttributeList::toLDAPModArray() const{ LDAPMod** LDAPAttributeList::toLDAPModArray() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl); DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
......
...@@ -84,13 +84,18 @@ class LDAPAttributeList{ ...@@ -84,13 +84,18 @@ class LDAPAttributeList{
*/ */
const LDAPAttribute* getAttributeByName(const std::string& name) const; const LDAPAttribute* getAttributeByName(const std::string& name) const;
/** /**
* Adds one element to the end of the list. * Adds one element to the end of the list.
* @param attr The attribute to add to the list. * @param attr The attribute to add to the list.
*/ */
void addAttribute(const LDAPAttribute& attr); void addAttribute(const LDAPAttribute& attr);
/**
* Replace an Attribute in the List
* @param attr The attribute to add to the list.
*/
void replaceAttribute(const LDAPAttribute& attr);
/** /**
* Translates the list of Attributes to a 0-terminated array of * Translates the list of Attributes to a 0-terminated array of
* LDAPMod-structures as needed by the C-API * LDAPMod-structures as needed by the C-API
......
...@@ -67,6 +67,21 @@ const LDAPAttributeList* LDAPEntry::getAttributes() const{ ...@@ -67,6 +67,21 @@ const LDAPAttributeList* LDAPEntry::getAttributes() const{
return m_attrs; return m_attrs;
} }
const LDAPAttribute* LDAPEntry::getAttributeByName(const std::string& name) const
{
return m_attrs->getAttributeByName(name);
}
void LDAPEntry::addAttribute(const LDAPAttribute& attr)
{
m_attrs->addAttribute(attr);
}
void LDAPEntry::replaceAttribute(const LDAPAttribute& attr)
{
m_attrs->replaceAttribute(attr);
}
ostream& operator << (ostream& s, const LDAPEntry& le){ ostream& operator << (ostream& s, const LDAPEntry& le){
s << "DN: " << le.m_dn << ": " << *(le.m_attrs); s << "DN: " << le.m_dn << ": " << *(le.m_attrs);
return s; return s;
......
...@@ -17,11 +17,11 @@ class LDAPAsynConnection; ...@@ -17,11 +17,11 @@ class LDAPAsynConnection;
*/ */
class LDAPEntry{ class LDAPEntry{
public : public :
/** /**
* Copy-constructor * Copy-constructor
*/ */
LDAPEntry(const LDAPEntry& entry); LDAPEntry(const LDAPEntry& entry);
/** /**
* Constructs a new entry (also used as standard constructor). * Constructs a new entry (also used as standard constructor).
...@@ -29,7 +29,7 @@ class LDAPEntry{ ...@@ -29,7 +29,7 @@ class LDAPEntry{
* @param dn The Distinguished Name for the new entry. * @param dn The Distinguished Name for the new entry.
* @param attrs The attributes for the new entry. * @param attrs The attributes for the new entry.
*/ */
LDAPEntry(const std::string& dn=std::string(), LDAPEntry(const std::string& dn=std::string(),
const LDAPAttributeList *attrs=new LDAPAttributeList()); const LDAPAttributeList *attrs=new LDAPAttributeList());
/** /**
...@@ -38,44 +38,66 @@ class LDAPEntry{ ...@@ -38,44 +38,66 @@ class LDAPEntry{
* The constructor is used internally to create a LDAPEntry from * The constructor is used internally to create a LDAPEntry from
* the C-API's data structurs. * the C-API's data structurs.
*/ */
LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg); LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg);
/** /**
* Destructor * Destructor
*/ */
~LDAPEntry(); ~LDAPEntry();
/** /**
* Sets the DN-attribute. * Sets the DN-attribute.
* @param dn: The new DN for the entry. * @param dn: The new DN for the entry.
*/ */
void setDN(const std::string& dn); void setDN(const std::string& dn);
/** /**
* Sets the attributes of the entry. * Sets the attributes of the entry.
* @param attr: A pointer to a std::list of the new attributes. * @param attr: A pointer to a std::list of the new attributes.
*/ */
void setAttributes(LDAPAttributeList *attrs); void setAttributes(LDAPAttributeList *attrs);
/**
* Get an Attribute by its AttributeType (simple wrapper around
* LDAPAttributeList::getAttributeByName() )
* @param name The name of the Attribute to look for
* @return a pointer to the LDAPAttribute with the AttributeType
* "name" or 0, if there is no Attribute of that Type
*/
const LDAPAttribute* getAttributeByName(const std::string& name) const;
/**
* Adds one Attribute to the List of Attributes (simple wrapper around
* LDAPAttributeList::addAttribute() ).
* @param attr The attribute to add to the list.
*/
void addAttribute(const LDAPAttribute& attr);
/**
* Replace an Attribute in the List of Attributes (simple wrapper
* around LDAPAttributeList::replaceAttribute() ).
* @param attr The attribute to add to the list.
*/
void replaceAttribute(const LDAPAttribute& attr);
/** /**
* @returns The current DN of the entry. * @returns The current DN of the entry.
*/ */
const std::string& getDN() const ; const std::string& getDN() const ;
/** /**
* @returns A const pointer to the attributes of the entry. * @returns A const pointer to the attributes of the entry.
*/ */
const LDAPAttributeList* getAttributes() const; const LDAPAttributeList* getAttributes() const;
/** /**
* This method can be used to dump the data of a LDAPResult-Object. * This method can be used to dump the data of a LDAPResult-Object.
* It is only useful for debugging purposes at the moment * It is only useful for debugging purposes at the moment
*/ */
friend std::ostream& operator << (std::ostream& s, const LDAPEntry& le); friend std::ostream& operator << (std::ostream& s, const LDAPEntry& le);
private : private :
LDAPAttributeList *m_attrs;
LDAPAttributeList *m_attrs; std::string m_dn;
std::string m_dn;
}; };
#endif //LDAP_ENTRY_H #endif //LDAP_ENTRY_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment