Back to index

openldap  2.4.31
LDAPControl.cpp
Go to the documentation of this file.
00001 // $OpenLDAP$
00002 /*
00003  * Copyright 2000-2012 The OpenLDAP Foundation, All Rights Reserved.
00004  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
00005  */
00006 
00007 
00008 #include "LDAPControl.h"
00009 #include "debug.h"
00010 
00011 using namespace std;
00012 
00013 LDAPCtrl::LDAPCtrl(const char *oid, bool critical, const char* data,
00014         int length){
00015     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
00016     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
00017             "   oid:" << oid << endl << "   critical:" << critical << endl);
00018     m_oid = oid;
00019     m_isCritical=critical;
00020     if (data != 0 && length !=0){
00021         m_data.assign(data,length);
00022         m_noData=false;
00023     }else{
00024         m_data=string();
00025         m_noData=true;
00026     }
00027 }
00028 
00029 LDAPCtrl::LDAPCtrl(const string& oid, bool critical, const string& data){
00030     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
00031     DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
00032             "   oid:" << oid << endl << "   critical:" << critical << endl);
00033     m_oid=oid;
00034     m_isCritical=critical;
00035     m_data=data;
00036     m_noData=false;
00037 }
00038 
00039 LDAPCtrl::LDAPCtrl(const LDAPControl* ctrl){
00040     DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPCtrl::LDAPCtrl()" << endl);
00041     m_oid = string(ctrl->ldctl_oid);
00042     m_oid = ctrl->ldctl_iscritical ? true : false;
00043     m_oid = string(ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len );
00044 }
00045 
00046 LDAPCtrl::~LDAPCtrl(){
00047     DEBUG(LDAP_DEBUG_DESTROY,"LDAPCtrl::~LDAPCtrl" << endl);
00048 }
00049 
00050 string LDAPCtrl::getOID() const{
00051     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getOID()" << endl);
00052     return m_oid;
00053 }
00054 
00055 bool LDAPCtrl::isCritical()const {
00056     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::isCritical()" << endl);
00057     return m_isCritical;
00058 }
00059 
00060 bool LDAPCtrl::hasData() const{
00061     return !m_noData;
00062 }
00063  
00064 string LDAPCtrl::getData() const {
00065     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getData()" << endl);
00066     return m_data;
00067 }
00068          
00069 LDAPControl* LDAPCtrl::getControlStruct() const {
00070     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::getControlStruct()" << endl);
00071     LDAPControl* ret = new LDAPControl;
00072     ret->ldctl_oid= new char[m_oid.size() + 1];
00073     m_oid.copy(ret->ldctl_oid,string::npos);
00074     ret->ldctl_oid[m_oid.size()]=0;
00075     if ( m_noData ) {
00076         ret->ldctl_value.bv_len = 0;
00077         ret->ldctl_value.bv_val = NULL;
00078     } else {
00079         ret->ldctl_value.bv_len=m_data.size();
00080         ret->ldctl_value.bv_val= new char[m_data.size()];
00081         m_data.copy(ret->ldctl_value.bv_val,string::npos);
00082     }
00083     ret->ldctl_iscritical = ( m_isCritical ? 1:0);
00084     return ret;
00085 }
00086 
00087 void LDAPCtrl::freeLDAPControlStruct(LDAPControl *ctrl){
00088     DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::freeControlStruct()" << endl);
00089     delete[] ctrl->ldctl_oid;
00090     delete[] ctrl->ldctl_value.bv_val;
00091     delete ctrl;
00092 }
00093