2008-03-28 19:05:10 +08:00
|
|
|
// $OpenLDAP$
|
2000-09-02 02:46:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "LDAPControl.h"
|
2000-10-04 02:25:34 +08:00
|
|
|
#include "debug.h"
|
2001-09-29 00:39:58 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2000-10-04 02:25:34 +08:00
|
|
|
LDAPCtrl::LDAPCtrl(const char *oid, bool critical, const char* data,
|
|
|
|
int length){
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
|
|
|
|
" oid:" << oid << endl << " critical:" << critical << endl);
|
|
|
|
m_oid = oid;
|
|
|
|
m_isCritical=critical;
|
|
|
|
if (data != 0 && length !=0){
|
|
|
|
m_data.assign(data,length);
|
|
|
|
}else{
|
|
|
|
m_data=string();
|
2008-08-28 05:19:51 +08:00
|
|
|
m_noData=true;
|
2000-10-04 02:25:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LDAPCtrl::LDAPCtrl(const string& oid, bool critical, const string& data){
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
|
|
|
|
" oid:" << oid << endl << " critical:" << critical << endl);
|
|
|
|
m_oid=oid;
|
|
|
|
m_isCritical=critical;
|
|
|
|
m_data=data;
|
2008-08-28 05:19:51 +08:00
|
|
|
m_noData=false;
|
2000-10-04 02:25:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LDAPCtrl::LDAPCtrl(const LDAPControl* ctrl){
|
|
|
|
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
|
|
|
|
m_oid = string(ctrl->ldctl_oid);
|
|
|
|
m_oid = ctrl->ldctl_iscritical ? true : false;
|
|
|
|
m_oid = string(ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len );
|
|
|
|
}
|
|
|
|
|
|
|
|
LDAPCtrl::~LDAPCtrl(){
|
|
|
|
DEBUG(LDAP_DEBUG_DESTROY,"LDAPCtrl::~LDAPCtrl" << endl);
|
|
|
|
}
|
2000-09-02 02:46:32 +08:00
|
|
|
|
2000-10-04 02:25:34 +08:00
|
|
|
string LDAPCtrl::getOID() const{
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getOID()" << endl);
|
|
|
|
return m_oid;
|
|
|
|
}
|
2000-09-02 02:46:32 +08:00
|
|
|
|
2000-10-04 02:25:34 +08:00
|
|
|
bool LDAPCtrl::isCritical()const {
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::isCritical()" << endl);
|
|
|
|
return m_isCritical;
|
|
|
|
}
|
|
|
|
|
2008-08-28 05:19:51 +08:00
|
|
|
bool LDAPCtrl::hasData() const{
|
|
|
|
return !m_noData;
|
|
|
|
}
|
|
|
|
|
2000-10-04 02:25:34 +08:00
|
|
|
string LDAPCtrl::getData() const {
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getData()" << endl);
|
|
|
|
return m_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
LDAPControl* LDAPCtrl::getControlStruct() const {
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getControlStruct()" << endl);
|
|
|
|
LDAPControl* ret = new LDAPControl;
|
|
|
|
ret->ldctl_oid= new char[m_oid.size() + 1];
|
|
|
|
m_oid.copy(ret->ldctl_oid,string::npos);
|
|
|
|
ret->ldctl_oid[m_oid.size()]=0;
|
2008-08-28 05:19:51 +08:00
|
|
|
if ( m_noData ) {
|
|
|
|
ret->ldctl_value.bv_len = 0;
|
|
|
|
ret->ldctl_value.bv_val = NULL;
|
|
|
|
} else {
|
|
|
|
ret->ldctl_value.bv_len=m_data.size();
|
|
|
|
ret->ldctl_value.bv_val= new char[m_data.size()];
|
|
|
|
m_data.copy(ret->ldctl_value.bv_val,string::npos);
|
|
|
|
}
|
2000-10-04 02:25:34 +08:00
|
|
|
ret->ldctl_iscritical = ( m_isCritical ? 1:0);
|
|
|
|
return ret;
|
2000-09-02 02:46:32 +08:00
|
|
|
}
|
|
|
|
|
2001-11-15 01:33:54 +08:00
|
|
|
void LDAPCtrl::freeLDAPControlStruct(LDAPControl *ctrl){
|
|
|
|
DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::freeControlStruct()" << endl);
|
|
|
|
delete[] ctrl->ldctl_oid;
|
|
|
|
delete[] ctrl->ldctl_value.bv_val;
|
|
|
|
delete ctrl;
|
|
|
|
}
|
|
|
|
|