Back to index

openldap  2.4.31
LDAPModifyRequest.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 #include <ldap.h>
00008 
00009 #include "debug.h"
00010 
00011 #include "LDAPModifyRequest.h"
00012 #include "LDAPException.h"
00013 #include "LDAPMessageQueue.h"
00014 #include "LDAPResult.h"
00015 
00016 using namespace std;
00017 
00018 LDAPModifyRequest::LDAPModifyRequest(const LDAPModifyRequest& req) :
00019         LDAPRequest(req){
00020     DEBUG(LDAP_DEBUG_CONSTRUCT, 
00021             "LDAPModifyRequest::LDAPModifyRequest(&)" << endl);
00022     m_modList = new LDAPModList(*(req.m_modList));
00023     m_dn = req.m_dn;
00024 }
00025 
00026 LDAPModifyRequest::LDAPModifyRequest(const string& dn, 
00027         const LDAPModList *modList, LDAPAsynConnection *connect,
00028         const LDAPConstraints *cons, bool isReferral,
00029         const LDAPRequest* parent) :
00030         LDAPRequest(connect, cons, isReferral, parent){
00031     DEBUG(LDAP_DEBUG_CONSTRUCT, 
00032             "LDAPModifyRequest::LDAPModifyRequest(&)" << endl);            
00033     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
00034             "   dn:" << dn << endl);
00035     m_dn = dn;
00036     m_modList = new LDAPModList(*modList);
00037 }
00038 
00039 LDAPModifyRequest::~LDAPModifyRequest(){
00040     DEBUG(LDAP_DEBUG_DESTROY, 
00041             "LDAPModifyRequest::~LDAPModifyRequest()" << endl);
00042     delete m_modList;
00043 }
00044 
00045 LDAPMessageQueue* LDAPModifyRequest::sendRequest(){
00046     DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::sendRequest()" << endl);
00047     int msgID=0;
00048     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
00049     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
00050     LDAPMod** tmpMods=m_modList->toLDAPModArray();
00051     int err=ldap_modify_ext(m_connection->getSessionHandle(),m_dn.c_str(),
00052             tmpMods, tmpSrvCtrls, tmpClCtrls,&msgID);
00053     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
00054     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
00055     ldap_mods_free(tmpMods,1);
00056     if(err != LDAP_SUCCESS){
00057         throw LDAPException(err);
00058     }else{
00059         m_msgID=msgID;
00060         return new LDAPMessageQueue(this);
00061     }
00062 }
00063 
00064 LDAPRequest* LDAPModifyRequest::followReferral(LDAPMsg* ref){
00065     DEBUG(LDAP_DEBUG_TRACE, "LDAPModifyRequest::followReferral()" << endl);
00066     LDAPUrlList::const_iterator usedUrl;
00067     LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
00068     LDAPAsynConnection* con = 0;
00069     try {
00070         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
00071     } catch(LDAPException e){
00072         delete con;
00073         return 0;
00074     }
00075     if(con != 0){
00076         return new LDAPModifyRequest(m_dn, m_modList, con, m_cons,true,this);
00077     }
00078     return 0;
00079 }
00080 
00081