1// OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPEntry.cpp,v 1.5.8.5 2008/07/08 19:31:00 quanah Exp
2/*
3 * Copyright 2000, 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
14using namespace std;
15
16LDAPEntry::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
23LDAPEntry::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
34LDAPEntry::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
42LDAPEntry::~LDAPEntry(){
43    DEBUG(LDAP_DEBUG_DESTROY,"LDAPEntry::~LDAPEntry()" << endl);
44    delete m_attrs;
45}
46
47LDAPEntry& 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
54void 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
61void 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
71const string& LDAPEntry::getDN() const{
72    DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getDN()" << endl);
73    return m_dn;
74}
75
76const LDAPAttributeList* LDAPEntry::getAttributes() const{
77    DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getAttributes()" << endl);
78    return m_attrs;
79}
80
81const LDAPAttribute* LDAPEntry::getAttributeByName(const std::string& name) const
82{
83    return m_attrs->getAttributeByName(name);
84}
85
86void LDAPEntry::addAttribute(const LDAPAttribute& attr)
87{
88    m_attrs->addAttribute(attr);
89}
90
91void LDAPEntry::delAttribute(const std::string& type)
92{
93    m_attrs->delAttribute(type);
94}
95
96void LDAPEntry::replaceAttribute(const LDAPAttribute& attr)
97{
98    m_attrs->replaceAttribute(attr);
99}
100
101ostream& operator << (ostream& s, const LDAPEntry& le){
102    s << "DN: " << le.m_dn << ": " << *(le.m_attrs);
103    return s;
104}
105