Back to index

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