]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPDeleteRequest.cpp
Added client side caching. (Commited by: Jeff Costlow <j.costlow@f5.com>)
[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 LDAPDeleteRequest::LDAPDeleteRequest( const LDAPDeleteRequest& req) :
16         LDAPRequest(req){
17         DEBUG(LDAP_DEBUG_CONSTRUCT, 
18                 "LDAPDeleteRequest::LDAPDeleteRequest(&)" << endl);
19     m_dn = req.m_dn;
20 }
21
22 LDAPDeleteRequest::LDAPDeleteRequest(const string& dn, 
23         LDAPAsynConnection *connect, const LDAPConstraints *cons,
24         bool isReferral, const LDAPRequest* parent) 
25         : LDAPRequest(connect, cons, isReferral, parent) {
26         DEBUG(LDAP_DEBUG_CONSTRUCT,
27             "LDAPDeleteRequest::LDAPDeleteRequest()" << endl);
28         DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER, "   dn:" << dn << endl);
29     m_requestType=LDAPRequest::DELETE;
30     m_dn=dn;
31 }
32
33 LDAPDeleteRequest::~LDAPDeleteRequest(){
34     DEBUG(LDAP_DEBUG_DESTROY,
35           "LDAPDeleteRequest::~LDAPDeleteRequest()" << endl);
36     // TODO -- flush the entire cache here?  or does this invalidate
37     // cached searches that may have found the deleted entry.
38     m_connection->uncache_entry(m_dn);
39 }
40
41 LDAPMessageQueue* LDAPDeleteRequest::sendRequest(){
42         DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::sendRequest()" << endl);
43     int msgID=0;
44     LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
45     LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
46     int err=ldap_delete_ext(m_connection->getSessionHandle(),m_dn.c_str(), 
47             tmpSrvCtrls, tmpClCtrls ,&msgID);
48     ldap_controls_free(tmpSrvCtrls);
49     ldap_controls_free(tmpClCtrls);
50     if(err != LDAP_SUCCESS){
51         throw LDAPException(err);
52     }else{
53         m_msgID=msgID;
54         return new LDAPMessageQueue(this);
55     }
56 }
57
58 LDAPRequest* LDAPDeleteRequest::followReferral(LDAPMsg* refs){
59         DEBUG(LDAP_DEBUG_TRACE, "LDAPDeleteRequest::followReferral()" << endl);
60     LDAPUrlList::const_iterator usedUrl;
61     LDAPUrlList urls= ((LDAPResult*)refs)->getReferralUrls();
62     LDAPAsynConnection* con=0;
63     try{
64         con = getConnection()->referralConnect(urls,usedUrl,m_cons);
65     }catch (LDAPException e){
66         delete con;
67         return 0;
68     }
69     if(con != 0){
70         return new LDAPDeleteRequest(m_dn, con, m_cons, true, this);
71     }
72     return 0;
73 }
74
75