| 1 |
// $OpenLDAP$ |
| 2 |
/* |
| 3 |
* Copyright 2000-2024 The OpenLDAP Foundation, All Rights Reserved. |
| 4 |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "debug.h" |
| 8 |
#include "LDAPControlSet.h" |
| 9 |
|
| 10 |
using namespace std; |
| 11 |
|
| 12 |
LDAPControlSet::LDAPControlSet(){ |
| 13 |
} |
| 14 |
|
| 15 |
LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){ |
| 16 |
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl); |
| 17 |
data=cs.data; |
| 18 |
} |
| 19 |
|
| 20 |
LDAPControlSet::LDAPControlSet(LDAPControl** controls){ |
| 21 |
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet()" << endl); |
| 22 |
if(controls != 0){ |
| 23 |
LDAPControl** i; |
| 24 |
for( i=controls; *i!=0;i++) { |
| 25 |
add(LDAPCtrl(*i)); |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
LDAPControlSet::~LDAPControlSet(){ |
| 31 |
DEBUG(LDAP_DEBUG_DESTROY,"LDAPControlSet::~LDAPControlSet()" << endl); |
| 32 |
} |
| 33 |
|
| 34 |
size_t LDAPControlSet::size() const { |
| 35 |
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::size()" << endl); |
| 36 |
return data.size(); |
| 37 |
} |
| 38 |
|
| 39 |
bool LDAPControlSet::empty() const { |
| 40 |
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::empty()" << endl); |
| 41 |
return data.empty(); |
| 42 |
} |
| 43 |
|
| 44 |
LDAPControlSet::const_iterator LDAPControlSet::begin() const{ |
| 45 |
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::begin()" << endl); |
| 46 |
return data.begin(); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
LDAPControlSet::const_iterator LDAPControlSet::end() const{ |
| 51 |
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::end()" << endl); |
| 52 |
return data.end (); |
| 53 |
} |
| 54 |
|
| 55 |
void LDAPControlSet::add(const LDAPCtrl& ctrl){ |
| 56 |
DEBUG(LDAP_DEBUG_TRACE,"LDAPControlSet::add()" << endl); |
| 57 |
data.push_back(ctrl); |
| 58 |
} |
| 59 |
|
| 60 |
LDAPControl** LDAPControlSet::toLDAPControlArray() const{ |
| 61 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::toLDAPControlArray()" << endl); |
| 62 |
if(data.empty()){ |
| 63 |
return 0; |
| 64 |
}else{ |
| 65 |
LDAPControl** ret= new LDAPControl*[data.size()+1]; |
| 66 |
CtrlList::const_iterator i; |
| 67 |
int j=0; |
| 68 |
for(i=data.begin(); i!=data.end(); i++,j++){ |
| 69 |
ret[j] = i->getControlStruct(); |
| 70 |
} |
| 71 |
ret[data.size()]=0; |
| 72 |
return ret; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){ |
| 77 |
DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl); |
| 78 |
if( ctrl ){ |
| 79 |
for( LDAPControl **i = ctrl; *i != 0; ++i ){ |
| 80 |
LDAPCtrl::freeLDAPControlStruct(*i); |
| 81 |
} |
| 82 |
} |
| 83 |
delete[] ctrl; |
| 84 |
} |