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