Back to index

openldap  2.4.31
LDAPExtRequest.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved.
00003  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00004  */
00005 
00006 #include <ldap.h>
00007 #include <lber.h>
00008 
00009 #include "debug.h"
00010 
00011 #include "LDAPExtRequest.h"
00012 #include "LDAPException.h"
00013 #include "LDAPResult.h"
00014 
00015 #include <cstdlib>
00016 
00017 using namespace std;
00018 
00019 LDAPExtRequest::LDAPExtRequest(const LDAPExtRequest& req) :
00020         LDAPRequest(req){
00021     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPExtRequest::LDAPExtRequest(&)" << endl);
00022     m_data=req.m_data;
00023     m_oid=req.m_oid;
00024 }
00025 
00026 LDAPExtRequest::LDAPExtRequest(const string& oid, const string& data, 
00027         LDAPAsynConnection *connect, const LDAPConstraints *cons,
00028         bool isReferral, const LDAPRequest* parent) 
00029         : LDAPRequest(connect, cons, isReferral, parent){
00030     DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPExtRequest::LDAPExtRequest()" << endl);
00031     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, 
00032             "   oid:" << oid << endl);
00033     m_oid=oid;
00034     m_data=data;
00035 }
00036 
00037 LDAPExtRequest::~LDAPExtRequest(){
00038     DEBUG(LDAP_DEBUG_DESTROY, "LDAPExtRequest::~LDAPExtRequest()" << endl);
00039 }
00040 
00041 LDAPMessageQueue* LDAPExtRequest::sendRequest(){
00042     DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::sendRequest()" << endl);
00043     int msgID=0;
00044     BerValue* tmpdata=0;
00045     if(m_data != ""){
00046         tmpdata=(BerValue*) malloc(sizeof(BerValue));
00047         tmpdata->bv_len = m_data.size();
00048         tmpdata->bv_val = (char*) malloc(sizeof(char) * (m_data.size()) );
00049         m_data.copy(tmpdata->bv_val, string::npos);
00050     }
00051     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
00052     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
00053     int err=ldap_extended_operation(m_connection->getSessionHandle(),
00054             m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
00055     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
00056     LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
00057     ber_bvfree(tmpdata);
00058     if(err != LDAP_SUCCESS){
00059         delete this;
00060         throw LDAPException(err);
00061     }else{
00062         m_msgID=msgID;
00063         return new LDAPMessageQueue(this);
00064     }
00065 }
00066 
00067 LDAPRequest* LDAPExtRequest::followReferral(LDAPMsg* ref){
00068     DEBUG(LDAP_DEBUG_TRACE, "LDAPExtRequest::followReferral()" << endl);
00069     LDAPUrlList::const_iterator usedUrl;
00070     LDAPUrlList urls = ((LDAPResult*)ref)->getReferralUrls();
00071     LDAPAsynConnection* con = 0;
00072     try {
00073         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
00074     } catch(LDAPException e){
00075         delete con;
00076         return 0;
00077     }
00078     if(con != 0){
00079         return new LDAPExtRequest(m_oid, m_data, con, m_cons,true,this);
00080     }
00081     return 0;
00082 }
00083 
00084