2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 #include "LDAPResult.h"
9 #include "LDAPException.h"
10 #include "LDAPReferralException.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 int LDAPConnection::start_tls(){
29 return 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);
55 throw LDAPException(resCode);
59 delete msg; // memcheck
62 void LDAPConnection::unbind(){
63 LDAPAsynConnection::unbind();
66 bool LDAPConnection::compare(const string& dn, const LDAPAttribute& attr,
67 LDAPConstraints* cons){
68 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::compare" << endl);
69 LDAPMessageQueue* msg=0;
72 msg = LDAPAsynConnection::compare(dn,attr,cons);
73 res = (LDAPResult*)msg->getNext();
74 }catch(LDAPException e){
79 int resCode=res->getResultCode();
81 case LDAPResult::COMPARE_TRUE :
86 case LDAPResult::COMPARE_FALSE :
91 case LDAPResult::REFERRAL :
93 LDAPUrlList urls = res->getReferralUrls();
96 throw LDAPReferralException(urls);
102 throw LDAPException(resCode);
106 void LDAPConnection::del(const string& dn, const LDAPConstraints* cons){
107 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::del" << endl);
108 LDAPMessageQueue* msg=0;
111 msg = LDAPAsynConnection::del(dn,cons);
112 res = (LDAPResult*)msg->getNext();
113 }catch(LDAPException e){
118 int resCode=res->getResultCode();
120 case LDAPResult::SUCCESS :
124 case LDAPResult::REFERRAL :
126 LDAPUrlList urls = res->getReferralUrls();
129 throw LDAPReferralException(urls);
135 throw LDAPException(resCode);
140 void LDAPConnection::add(const LDAPEntry* le, const LDAPConstraints* cons){
141 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::add" << endl);
142 LDAPMessageQueue* msg=0;
145 msg = LDAPAsynConnection::add(le,cons);
146 res = (LDAPResult*)msg->getNext();
147 }catch(LDAPException e){
152 int resCode=res->getResultCode();
154 case LDAPResult::SUCCESS :
158 case LDAPResult::REFERRAL :
160 LDAPUrlList urls = res->getReferralUrls();
163 throw LDAPReferralException(urls);
169 throw LDAPException(resCode);
173 void LDAPConnection::modify(const string& dn, const LDAPModList* mods,
174 const LDAPConstraints* cons){
175 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::modify" << endl);
176 LDAPMessageQueue* msg=0;
179 msg = LDAPAsynConnection::modify(dn,mods,cons);
180 res = (LDAPResult*)msg->getNext();
181 }catch(LDAPException e){
186 int resCode=res->getResultCode();
188 case LDAPResult::SUCCESS :
192 case LDAPResult::REFERRAL :
194 LDAPUrlList urls = res->getReferralUrls();
197 throw LDAPReferralException(urls);
201 string srvMsg = res->getErrMsg();
204 throw LDAPException(resCode,srvMsg);
209 void LDAPConnection::rename(const string& dn, const string& newRDN,
210 bool delOldRDN, const string& newParentDN,
211 const LDAPConstraints* cons){
212 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::rename" << endl);
213 LDAPMessageQueue* msg=0;
216 msg = LDAPAsynConnection::rename(dn,newRDN,delOldRDN, newParentDN,
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);
241 throw LDAPException(resCode);
245 LDAPSearchResults* LDAPConnection::search(const string& base, int scope,
246 const string& filter, const StringList& attrs, bool attrsOnly,
247 const LDAPConstraints* cons){
248 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::search" << endl);
249 LDAPMessageQueue* msgq=0;
251 LDAPSearchResults* results= 0;
254 results = new LDAPSearchResults();
255 msgq = LDAPAsynConnection::search(base,scope, filter, attrs, attrsOnly,
257 res = results->readMessageQueue(msgq);
258 }catch(LDAPException e){
259 delete results; // memcheck
264 int resCode=res->getResultCode();
266 case LDAPResult::SUCCESS :
271 case LDAPResult::REFERRAL :
273 LDAPUrlList urls = res->getReferralUrls();
274 delete results; // memcheck
277 throw LDAPReferralException(urls);
281 delete results; // memcheck
284 throw LDAPException(resCode);
290 LDAPExtResult* LDAPConnection::extOperation(const string& oid,
291 const string& value, const LDAPConstraints *cons){
292 DEBUG(LDAP_DEBUG_TRACE,"LDAPConnection::extOperation" << endl);
293 LDAPMessageQueue* msg=0;
294 LDAPExtResult* res=0;
296 msg = LDAPAsynConnection::extOperation(oid,value,cons);
297 res = (LDAPExtResult*)msg->getNext();
298 }catch(LDAPException e){
303 int resCode=res->getResultCode();
305 case LDAPResult::SUCCESS :
308 case LDAPResult::REFERRAL :
310 LDAPUrlList urls = res->getReferralUrls();
313 throw LDAPReferralException(urls);
319 throw LDAPException(resCode);
323 const string& LDAPConnection::getHost() const{
324 return LDAPAsynConnection::getHost();
327 int LDAPConnection::getPort() const{
328 return LDAPAsynConnection::getPort();
331 void LDAPConnection::setConstraints(LDAPConstraints* cons){
332 LDAPAsynConnection::setConstraints(cons);
335 const LDAPConstraints* LDAPConnection::getConstraints() const{
336 return LDAPAsynConnection::getConstraints();