1
// $OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPConnection.cpp,v 1.10.4.3 2008/04/14 23:28:11 quanah Exp $
3
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
4
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9
#include "LDAPResult.h"
10
#include "LDAPException.h"
11
#include "LDAPUrlList.h"
13
#include "LDAPConnection.h"
14
const int LDAPConnection::SEARCH_BASE = LDAPAsynConnection::SEARCH_BASE;
15
const int LDAPConnection::SEARCH_ONE = LDAPAsynConnection::SEARCH_ONE;
16
const int LDAPConnection::SEARCH_SUB = LDAPAsynConnection::SEARCH_SUB;
20
LDAPConnection::LDAPConnection(const string& hostname, int port,
21
LDAPConstraints* cons) :
22
LDAPAsynConnection(hostname, port, cons){
25
LDAPConnection::~LDAPConnection(){
28
void LDAPConnection::start_tls(){
29
LDAPAsynConnection::start_tls();
32
void LDAPConnection::bind(const string& dn, const string& passwd,
33
LDAPConstraints* cons){
34
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::bind" << endl);
35
LDAPMessageQueue* msg=0;
38
msg = LDAPAsynConnection::bind(dn,passwd,cons);
39
res = (LDAPResult*)msg->getNext();
40
}catch(LDAPException e){
45
int resCode=res->getResultCode();
46
if(resCode != LDAPResult::SUCCESS) {
47
if(resCode == LDAPResult::REFERRAL){
48
LDAPUrlList urls = res->getReferralUrls();
51
throw LDAPReferralException(urls);
53
string srvMsg = res->getErrMsg();
56
throw LDAPException(resCode, srvMsg);
60
delete msg; // memcheck
63
void LDAPConnection::saslInteractiveBind( const std::string &mech,
65
SaslInteractionHandler *sih,
66
const LDAPConstraints *cons)
68
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::bind" << endl);
69
LDAPMessageQueue* msg=0;
72
msg = LDAPAsynConnection::saslInteractiveBind(mech, flags, sih, cons);
73
res = (LDAPResult*)msg->getNext();
74
}catch(LDAPException e){
79
int resCode=res->getResultCode();
80
if(resCode != LDAPResult::SUCCESS) {
81
if(resCode == LDAPResult::REFERRAL){
82
LDAPUrlList urls = res->getReferralUrls();
85
throw LDAPReferralException(urls);
87
string srvMsg = res->getErrMsg();
90
throw LDAPException(resCode, srvMsg);
97
void LDAPConnection::unbind(){
98
LDAPAsynConnection::unbind();
101
bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr,
102
LDAPConstraints* cons){
103
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::compare" << endl);
104
LDAPMessageQueue* msg=0;
107
msg = LDAPAsynConnection::compare(dn,attr,cons);
108
res = (LDAPResult*)msg->getNext();
109
}catch(LDAPException e){
114
int resCode=res->getResultCode();
116
case LDAPResult::COMPARE_TRUE :
121
case LDAPResult::COMPARE_FALSE :
126
case LDAPResult::REFERRAL :
128
LDAPUrlList urls = res->getReferralUrls();
131
throw LDAPReferralException(urls);
135
string srvMsg = res->getErrMsg();
138
throw LDAPException(resCode, srvMsg);
142
void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){
143
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::del" << endl);
144
LDAPMessageQueue* msg=0;
147
msg = LDAPAsynConnection::del(dn,cons);
148
res = (LDAPResult*)msg->getNext();
149
}catch(LDAPException e){
154
int resCode=res->getResultCode();
156
case LDAPResult::SUCCESS :
160
case LDAPResult::REFERRAL :
162
LDAPUrlList urls = res->getReferralUrls();
165
throw LDAPReferralException(urls);
169
string srvMsg = res->getErrMsg();
172
throw LDAPException(resCode, srvMsg);
177
void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons){
178
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::add" << endl);
179
LDAPMessageQueue* msg=0;
182
msg = LDAPAsynConnection::add(le,cons);
183
res = (LDAPResult*)msg->getNext();
184
}catch(LDAPException e){
189
int resCode=res->getResultCode();
191
case LDAPResult::SUCCESS :
195
case LDAPResult::REFERRAL :
197
LDAPUrlList urls = res->getReferralUrls();
200
throw LDAPReferralException(urls);
204
string srvMsg = res->getErrMsg();
207
throw LDAPException(resCode, srvMsg);
211
void LDAPConnection::modify(const string& dn, const LDAPModList* mods,
212
const LDAPConstraints* cons){
213
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::modify" << endl);
214
LDAPMessageQueue* msg=0;
217
msg = LDAPAsynConnection::modify(dn,mods,cons);
218
res = (LDAPResult*)msg->getNext();
219
}catch(LDAPException e){
224
int resCode=res->getResultCode();
226
case LDAPResult::SUCCESS :
230
case LDAPResult::REFERRAL :
232
LDAPUrlList urls = res->getReferralUrls();
235
throw LDAPReferralException(urls);
239
string srvMsg = res->getErrMsg();
242
throw LDAPException(resCode, srvMsg);
247
void LDAPConnection::rename(const string& dn, const string& newRDN,
248
bool delOldRDN, const string& newParentDN,
249
const LDAPConstraints* cons){
250
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::rename" << endl);
251
LDAPMessageQueue* msg=0;
254
msg = LDAPAsynConnection::rename(dn,newRDN,delOldRDN, newParentDN,
256
res = (LDAPResult*)msg->getNext();
257
}catch(LDAPException e){
262
int resCode=res->getResultCode();
264
case LDAPResult::SUCCESS :
268
case LDAPResult::REFERRAL :
270
LDAPUrlList urls = res->getReferralUrls();
273
throw LDAPReferralException(urls);
277
string srvMsg = res->getErrMsg();
280
throw LDAPException(resCode, srvMsg);
284
LDAPSearchResults* LDAPConnection::search(const string& base, int scope,
285
const string& filter, const StringList& attrs, bool attrsOnly,
286
const LDAPConstraints* cons){
287
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::search" << endl);
288
LDAPMessageQueue* msgq=0;
290
LDAPSearchResults* results= 0;
293
results = new LDAPSearchResults();
294
msgq = LDAPAsynConnection::search(base,scope, filter, attrs, attrsOnly,
296
res = results->readMessageQueue(msgq);
297
}catch(LDAPException e){
298
delete results; // memcheck
303
int resCode=res->getResultCode();
305
case LDAPResult::SUCCESS :
310
case LDAPResult::REFERRAL :
312
LDAPUrlList urls = res->getReferralUrls();
313
delete results; // memcheck
316
throw LDAPReferralException(urls);
320
string srvMsg = res->getErrMsg();
321
delete results; // memcheck
324
throw LDAPException(resCode, srvMsg);
330
LDAPExtResult* LDAPConnection::extOperation(const string& oid,
331
const string& value, const LDAPConstraints *cons){
332
DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::extOperation" << endl);
333
LDAPMessageQueue* msg=0;
334
LDAPExtResult* res=0;
336
msg = LDAPAsynConnection::extOperation(oid,value,cons);
337
res = (LDAPExtResult*)msg->getNext();
338
}catch(LDAPException e){
343
int resCode=res->getResultCode();
345
case LDAPResult::SUCCESS :
348
case LDAPResult::REFERRAL :
350
LDAPUrlList urls = res->getReferralUrls();
353
throw LDAPReferralException(urls);
357
string srvMsg = res->getErrMsg();
360
throw LDAPException(resCode, srvMsg);
364
const string& LDAPConnection::getHost() const{
365
return LDAPAsynConnection::getHost();
368
int LDAPConnection::getPort() const{
369
return LDAPAsynConnection::getPort();
372
void LDAPConnection::setConstraints(LDAPConstraints* cons){
373
LDAPAsynConnection::setConstraints(cons);
376
const LDAPConstraints* LDAPConnection::getConstraints() const{
377
return LDAPAsynConnection::getConstraints();