Back to index

openldap  2.4.31
LDAPEntry.cpp
Go to the documentation of this file.
00001 // $OpenLDAP$
00002 /*
00003  * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved.
00004  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00005  */
00006 
00007 
00008 #include "debug.h"
00009 #include "LDAPEntry.h"
00010 
00011 #include "LDAPAsynConnection.h"
00012 #include "LDAPException.h"
00013 
00014 using namespace std;
00015 
00016 LDAPEntry::LDAPEntry(const LDAPEntry& entry){
00017     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry(&)" << endl);
00018     m_dn=entry.m_dn;
00019     m_attrs=new LDAPAttributeList( *(entry.m_attrs));
00020 }
00021 
00022 
00023 LDAPEntry::LDAPEntry(const string& dn, const LDAPAttributeList *attrs){
00024     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
00025     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
00026             "   dn:" << dn << endl);
00027     if ( attrs )
00028         m_attrs=new LDAPAttributeList(*attrs);
00029     else
00030         m_attrs=new LDAPAttributeList();
00031     m_dn=dn;
00032 }
00033 
00034 LDAPEntry::LDAPEntry(const LDAPAsynConnection *ld, LDAPMessage *msg){
00035     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
00036     char* tmp=ldap_get_dn(ld->getSessionHandle(),msg);
00037     m_dn=string(tmp);
00038     ldap_memfree(tmp);
00039     m_attrs = new LDAPAttributeList(ld, msg);
00040 }
00041 
00042 LDAPEntry::~LDAPEntry(){
00043     DEBUG(LDAP_DEBUG_DESTROY,"LDAPEntry::~LDAPEntry()" << endl);
00044     delete m_attrs;
00045 }
00046 
00047 LDAPEntry& LDAPEntry::operator=(const LDAPEntry& from){
00048     m_dn = from.m_dn;
00049     delete m_attrs;
00050     m_attrs = new LDAPAttributeList( *(from.m_attrs));
00051     return *this;
00052 }
00053 
00054 void LDAPEntry::setDN(const string& dn){
00055     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setDN()" << endl);
00056     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
00057             "   dn:" << dn << endl);
00058     m_dn=dn;
00059 }
00060 
00061 void LDAPEntry::setAttributes(LDAPAttributeList *attrs){
00062     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::setAttributes()" << endl);
00063     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
00064             "   attrs:" << *attrs << endl);
00065     if (m_attrs != 0){
00066         delete m_attrs;
00067     }
00068     m_attrs=attrs;
00069 }
00070 
00071 const string& LDAPEntry::getDN() const{
00072     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getDN()" << endl);
00073     return m_dn;
00074 }
00075 
00076 const LDAPAttributeList* LDAPEntry::getAttributes() const{
00077     DEBUG(LDAP_DEBUG_TRACE,"LDAPEntry::getAttributes()" << endl);
00078     return m_attrs;
00079 }
00080 
00081 const LDAPAttribute* LDAPEntry::getAttributeByName(const std::string& name) const 
00082 {
00083     return m_attrs->getAttributeByName(name);
00084 }
00085 
00086 void LDAPEntry::addAttribute(const LDAPAttribute& attr)
00087 {
00088     m_attrs->addAttribute(attr);
00089 }
00090 
00091 void LDAPEntry::delAttribute(const std::string& type)
00092 {
00093     m_attrs->delAttribute(type);
00094 }
00095 
00096 void LDAPEntry::replaceAttribute(const LDAPAttribute& attr)
00097 {
00098     m_attrs->replaceAttribute(attr); 
00099 }
00100 
00101 ostream& operator << (ostream& s, const LDAPEntry& le){
00102     s << "DN: " << le.m_dn << ": " << *(le.m_attrs); 
00103     return s;
00104 }