]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPDeleteRequest.cpp
some changes to make the library working with gcc 3.0 (mostly namespace
[openldap] / contrib / ldapc++ / src / LDAPDeleteRequest.cpp
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6 #include <ldap.h>
7
8 #include "debug.h"
9
10 #include "LDAPDeleteRequest.h"
11 #include "LDAPException.h"
12 #include "LDAPMessageQueue.h"
13 #include "LDAPResult.h"
14
15 using namespace std;
16
17 LDAPDeleteRequest::LDAPDeleteRequest( const LDAPDeleteRequest& req) :
18         LDAPRequest(req){
19         DEBUG(LDAP_DEBUG_CONSTRUCT, 
20                 "LDAPDeleteRequest::LDAPDeleteRequest(&)" << endl);
21     m_dn = req.m_dn;
22 }
23
24 LDAPDeleteRequest::LDAPDeleteRequest(const string& dn, 
25         LDAPAsynConnection *connect, const LDAPConstraints *cons,
26         bool isReferral, const LDAPRequest* parent) 
27         : LDAPRequest(connect, cons, isReferral, parent) {
28         DEBUG(LDAP_DEBUG_CONSTRUCT,
29             "LDAPDeleteRequest::LDAPDeleteRequest()" << endl);
30         DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, "   dn:" << dn << endl);
31     m_requestType=LDAPRequest::DELETE;
32     m_dn=dn;
33 }
34
35 LDAPDeleteRequest::~LDAPDeleteRequest(){
36     DEBUG(LDAP_DEBUG_DESTROY,
37           "LDAPDeleteRequest::~LDAPDeleteRequest()" << endl);
38     // TODO -- flush the entire cache here?  or does this invalidate
39     // cached searches that may have found the deleted entry.
40     m_connection->uncache_entry(m_dn);
41 }
42
43 LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){
44         DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::sendRequest()" << endl);
45     int msgID=0;
46     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
47     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
48     int err=ldap_delete_ext(m_connection->getSessionHandle(),m_dn.c_str(), 
49             tmpSrvCtrls, tmpClCtrls ,&msgID);
50     ldap_controls_free(tmpSrvCtrls);
51     ldap_controls_free(tmpClCtrls);
52     if(err != LDAP_SUCCESS){
53         throw LDAPException(err);
54     }else{
55         m_msgID=msgID;
56         return new LDAPMessageQueue(this);
57     }
58 }
59
60 LDAPRequest* LDAPDeleteRequest::followReferral(LDAPMsg* refs){
61         DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::followReferral()" << endl);
62     LDAPUrlList::const_iterator usedUrl;
63     LDAPUrlList urls= ((LDAPResult*)refs)->getReferralUrls();
64     LDAPAsynConnection* con=0;
65     try{
66         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
67     }catch (LDAPException e){
68         delete con;
69         return 0;
70     }
71     if(con != 0){
72         return new LDAPDeleteRequest(m_dn, con, m_cons, true, this);
73     }
74     return 0;
75 }
76
77