]> git.sur5r.net Git - openldap/blobdiff - contrib/ldapc++/src/LDAPEntry.cpp
Happy New Year
[openldap] / contrib / ldapc++ / src / LDAPEntry.cpp
index 795a5f1832b3c6d66c7e84beb8bc9a6873808be8..08d7514b1c9cb8e4a726fd2aebcebf69e61e28bb 100644 (file)
@@ -1,5 +1,6 @@
+// $OpenLDAP$
 /*
- * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 2000-2013 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -7,8 +8,11 @@
 #include "debug.h"
 #include "LDAPEntry.h"
 
+#include "LDAPAsynConnection.h"
 #include "LDAPException.h"
 
+using namespace std;
+
 LDAPEntry::LDAPEntry(const LDAPEntry& entry){
     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry(&)" << endl);
     m_dn=entry.m_dn;
@@ -19,8 +23,11 @@ LDAPEntry::LDAPEntry(const LDAPEntry& entry){
 LDAPEntry::LDAPEntry(const string& dn, const LDAPAttributeList *attrs){
     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
-            "   dn:" << dn << endl << " attrs:" << *attrs << endl);
-    m_attrs=new LDAPAttributeList(*attrs);
+            "   dn:" << dn << endl);
+    if ( attrs )
+        m_attrs=new LDAPAttributeList(*attrs);
+    else
+        m_attrs=new LDAPAttributeList();
     m_dn=dn;
 }
 
@@ -28,7 +35,7 @@ LDAPEntry::LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg){
     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
     char* tmp=ldap_get_dn(ld->getSessionHandle(),msg);
     m_dn=string(tmp);
-    delete[] tmp;
+    ldap_memfree(tmp);
     m_attrs = new LDAPAttributeList(ld, msg);
 }
 
@@ -37,6 +44,13 @@ LDAPEntry::~LDAPEntry(){
     delete m_attrs;
 }
 
+LDAPEntry& LDAPEntry::operator=(const LDAPEntry& from){
+    m_dn = from.m_dn;
+    delete m_attrs;
+    m_attrs = new LDAPAttributeList( *(from.m_attrs));
+    return *this;
+}
+
 void LDAPEntry::setDN(const string& dn){
     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setDN()" << endl);
     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
@@ -54,7 +68,7 @@ void LDAPEntry::setAttributes(LDAPAttributeList *attrs){
     m_attrs=attrs;
 }
 
-const string LDAPEntry::getDN() const{
+const string& LDAPEntry::getDN() const{
     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getDN()" << endl);
     return m_dn;
 }
@@ -64,6 +78,26 @@ const LDAPAttributeList* LDAPEntry::getAttributes() const{
     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::delAttribute(const std::string& type)
+{
+    m_attrs->delAttribute(type);
+}
+
+void LDAPEntry::replaceAttribute(const LDAPAttribute& attr)
+{
+    m_attrs->replaceAttribute(attr); 
+}
+
 ostream& operator << (ostream& s, const LDAPEntry& le){
     s << "DN: " << le.m_dn << ": " << *(le.m_attrs); 
     return s;