]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPEntry.cpp
- Plugged memory leak default constructor
[openldap] / contrib / ldapc++ / src / LDAPEntry.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #include "debug.h"
8 #include "LDAPEntry.h"
9
10 #include "LDAPAsynConnection.h"
11 #include "LDAPException.h"
12
13 using namespace std;
14
15 LDAPEntry::LDAPEntry(const LDAPEntry& entry){
16     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry(&)" << endl);
17     m_dn=entry.m_dn;
18     m_attrs=new LDAPAttributeList( *(entry.m_attrs));
19 }
20
21
22 LDAPEntry::LDAPEntry(const string& dn, const LDAPAttributeList *attrs){
23     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
24     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
25             "   dn:" << dn << endl);
26     if ( attrs )
27         m_attrs=new LDAPAttributeList(*attrs);
28     else
29         m_attrs=new LDAPAttributeList();
30     m_dn=dn;
31 }
32
33 LDAPEntry::LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg){
34     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
35     char* tmp=ldap_get_dn(ld->getSessionHandle(),msg);
36     m_dn=string(tmp);
37     ldap_memfree(tmp);
38     m_attrs = new LDAPAttributeList(ld, msg);
39 }
40
41 LDAPEntry::~LDAPEntry(){
42     DEBUG(LDAP_DEBUG_DESTROY,"LDAPEntry::~LDAPEntry()" << endl);
43     delete m_attrs;
44 }
45
46 LDAPEntry& LDAPEntry::operator=(const LDAPEntry& from){
47     m_dn = from.m_dn;
48     delete m_attrs;
49     m_attrs = new LDAPAttributeList( *(from.m_attrs));
50     return *this;
51 }
52
53 void LDAPEntry::setDN(const string& dn){
54     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setDN()" << endl);
55     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
56             "   dn:" << dn << endl);
57     m_dn=dn;
58 }
59
60 void LDAPEntry::setAttributes(LDAPAttributeList *attrs){
61     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setAttributes()" << endl);
62     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
63             "   attrs:" << *attrs << endl);
64     if (m_attrs != 0){
65         delete m_attrs;
66     }
67     m_attrs=attrs;
68 }
69
70 const string& LDAPEntry::getDN() const{
71     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getDN()" << endl);
72     return m_dn;
73 }
74
75 const LDAPAttributeList* LDAPEntry::getAttributes() const{
76     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getAttributes()" << endl);
77     return m_attrs;
78 }
79
80 const LDAPAttribute* LDAPEntry::getAttributeByName(const std::string& name) const 
81 {
82     return m_attrs->getAttributeByName(name);
83 }
84
85 void LDAPEntry::addAttribute(const LDAPAttribute& attr)
86 {
87     m_attrs->addAttribute(attr);
88 }
89
90 void LDAPEntry::replaceAttribute(const LDAPAttribute& attr)
91 {
92     m_attrs->replaceAttribute(attr); 
93 }
94
95 ostream& operator << (ostream& s, const LDAPEntry& le){
96     s << "DN: " << le.m_dn << ": " << *(le.m_attrs); 
97     return s;
98 }