LDAPControl** tmpClCtrls = m_cons->getClCtrlsArray();
int err=ldap_add_ext(m_connection->getSessionHandle(),
m_entry->getDN().c_str(),attrs,tmpSrvCtrls,tmpClCtrls,&msgID);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ldap_mods_free(attrs,1);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
LDAPControl** tmpClCtrls=m_constr->getClCtrlsArray();
int err=ldap_unbind_ext(cur_session, tmpSrvCtrls, tmpClCtrls);
cur_session=0;
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}
BerValue** LDAPAttribute::getBerValues() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getBerValues()" << endl);
- size_t size=m_values.size();
+ size_t size=m_values.size();
if (size == 0){
return 0;
}else{
- BerValue **temp = new BerValue*[size+1];
+ BerValue **temp = (BerValue**) malloc(sizeof(BerValue*) * (size+1));
StringList::const_iterator i;
int p=0;
for(i=m_values.begin(), p=0; i!=m_values.end(); i++,p++){
- temp[p]=new BerValue;
+ temp[p]=(BerValue*) malloc(sizeof(BerValue));
temp[p]->bv_len= i->size();
- temp[p]->bv_val= new char[i->size()+1];
+ temp[p]->bv_val= (char*) malloc(sizeof(char) * (i->size()+1));
i->copy(temp[p]->bv_val,string::npos);
}
temp[size]=0;
// The bin-FLAG of the mod_op is always set to LDAP_MOD_BVALUES (0x80)
LDAPMod* LDAPAttribute::toLDAPMod() const {
DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::toLDAPMod()" << endl);
- LDAPMod* ret=new LDAPMod();
- ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
- ret->mod_type= new char[m_name.size()+1];
+ LDAPMod* ret= (LDAPMod*) malloc(sizeof(LDAPMod));
+ ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
+ ret->mod_type= (char*) malloc(sizeof(char) * (m_name.size()+1));
m_name.copy(ret->mod_type,string::npos);
ret->mod_type[m_name.size()]=0;
- ret->mod_bvalues=this->getBerValues();
- return ret;
+ ret->mod_bvalues=this->getBerValues();
+ return ret;
}
bool LDAPAttribute::isNotPrintable() const {
- StringList::const_iterator i;
- for(i=m_values.begin(); i!=m_values.end(); i++){
- size_t len = i->size();
- for(size_t j=0; j<len; j++){
- if (! isprint( (i->data())[j] ) ){
- return true;
- }
- }
+ StringList::const_iterator i;
+ for(i=m_values.begin(); i!=m_values.end(); i++){
+ size_t len = i->size();
+ for(size_t j=0; j<len; j++){
+ if (! isprint( (i->data())[j] ) ){
+ return true;
+ }
}
- return false;
+ }
+ return false;
}
ostream& operator << (ostream& s, const LDAPAttribute& attr){
- s << attr.m_name << "=";
- StringList::const_iterator i;
- if (attr.isNotPrintable()){
- s << "NOT_PRINTABLE" ;
- }else{
- for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){
- s << *i << " ";
- }
+ s << attr.m_name << "=";
+ StringList::const_iterator i;
+ if (attr.isNotPrintable()){
+ s << "NOT_PRINTABLE" ;
+ }else{
+ for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){
+ s << *i << " ";
}
+ }
return s;
}
LDAPMod** LDAPAttributeList::toLDAPModArray() const{
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
- LDAPMod **ret = new LDAPMod*[m_attrs.size()+1];
+ LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
AttrList::const_iterator i;
int j=0;
for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
const char* mech = (m_mech == "" ? 0 : m_mech.c_str());
BerValue* tmpcred=0;
if(m_cred != ""){
- char* tmppwd = new char[m_cred.size()+1];
+ char* tmppwd = (char*) malloc( (m_cred.size()+1) * sizeof(char));
m_cred.copy(tmppwd,string::npos);
tmppwd[m_cred.size()]=0;
tmpcred=ber_bvstr(tmppwd);
}else{
- tmpcred=new BerValue;
+ tmpcred=(BerValue*) malloc(sizeof(BerValue));
tmpcred->bv_len=0;
tmpcred->bv_val=0;
}
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_sasl_bind(m_connection->getSessionHandle(),dn,
mech, tmpcred, tmpSrvCtrls, tmpClCtrls, &msgID);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ber_bvfree(tmpcred);
if(err != LDAP_SUCCESS){
m_attr.getName().c_str(), val[0], tmpSrvCtrls,
tmpClCtrls, &msgID);
ber_bvecfree(val);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
return ret;
}
+void LDAPCtrl::freeLDAPControlStruct(LDAPControl *ctrl){
+ DEBUG(LDAP_DEBUG_TRACE,"LDAPCtrl::freeControlStruct()" << endl);
+ delete[] ctrl->ldctl_oid;
+ delete[] ctrl->ldctl_value.bv_val;
+ delete ctrl;
+}
+
* the C-API
*/
LDAPControl* getControlStruct() const;
-
+ static void freeLDAPControlStruct(LDAPControl *ctrl);
+
private :
std::string m_oid;
std::string m_data;
}
}
+void LDAPControlSet::freeLDAPControlArray(LDAPControl **ctrl){
+ DEBUG(LDAP_DEBUG_TRACE, "LDAPControlSet::freeLDAPControlArray()" << endl);
+ if( ctrl ){
+ for( LDAPControl **i = ctrl; *i != 0; ++i ){
+ LDAPCtrl::freeLDAPControlStruct(*i);
+ }
+ }
+ delete[] ctrl;
+}
* LDAPControl-structures as needed by the C-API
*/
LDAPControl** toLDAPControlArray()const ;
-
+ static void freeLDAPControlArray(LDAPControl **ctrl);
private :
CtrlList data;
} ;
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_delete_ext(m_connection->getSessionHandle(),m_dn.c_str(),
tmpSrvCtrls, tmpClCtrls ,&msgID);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPEntry::LDAPEntry()" << endl);
char* tmp=ldap_get_dn(ld->getSessionHandle(),msg);
m_dn=string(tmp);
- delete[] tmp;
+ free(tmp);
m_attrs = new LDAPAttributeList(ld, msg);
}
int msgID=0;
BerValue* tmpdata=0;
if(m_data != ""){
- tmpdata=new BerValue;
+ tmpdata=(BerValue*) malloc(sizeof(BerValue));
tmpdata->bv_len = m_data.size();
- tmpdata->bv_val = new char[m_data.size()];
+ tmpdata->bv_val = (char*) malloc(sizeof(char) * (m_data.size()) );
m_data.copy(tmpdata->bv_val, string::npos);
}
LDAPControl** tmpSrvCtrls=m_cons->getSrvCtrlsArray();
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_extended_operation(m_connection->getSessionHandle(),
m_oid.c_str(), tmpdata, tmpSrvCtrls, tmpClCtrls, &msgID);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
ber_bvfree(tmpdata);
if(err != LDAP_SUCCESS){
delete this;
LDAPMsg *LDAPMessageQueue::getNext(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPMessageQueue::getNext()" << endl);
- LDAPMessage *msg;
+ LDAPMessage *msg;
LDAPRequest *req=m_activeReq.top();
int msg_id = req->getMsgID();
- int res;
+ int res;
const LDAPAsynConnection *con=req->getConnection();
res=ldap_result(con->getSessionHandle(),msg_id,0,0,&msg);
if (res <= 0){
if(msg != 0){
ldap_msgfree(msg);
}
- throw LDAPException(con);
- }else{
+ throw LDAPException(con);
+ }else{
const LDAPConstraints *constr=req->getConstraints();
LDAPMsg *ret=0;
//this can throw an exception (Decoding Error)
}
break;
}
- }
+ }
}
// TODO Maybe moved to LDAPRequest::followReferral seems more reasonable
LDAPControl** tmpClCtrls=m_cons->getClCtrlsArray();
int err=ldap_rename(m_connection->getSessionHandle(),m_dn.c_str(),newRDN,
newParentDN,m_deleteOld ? 1 : 0, tmpSrvCtrls, tmpClCtrls,&msg_id);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
if(err!=LDAP_SUCCESS){
throw LDAPException(err);
}else{
LDAPMod** LDAPModList::toLDAPModArray(){
DEBUG(LDAP_DEBUG_TRACE,"LDAPModList::toLDAPModArray()" << endl);
- LDAPMod **ret = new LDAPMod*[m_modList.size()+1];
- ret[m_modList.size()]=0;
- ModList::const_iterator i;
- int j=0;
- for (i=m_modList.begin(); i != m_modList.end(); i++ , j++){
- ret[j]=i->toLDAPMod();
- }
- return ret;
+ LDAPMod **ret = (LDAPMod**) malloc(
+ (m_modList.size()+1) * sizeof(LDAPMod*));
+ ret[m_modList.size()]=0;
+ ModList::const_iterator i;
+ int j=0;
+ for (i=m_modList.begin(); i != m_modList.end(); i++ , j++){
+ ret[j]=i->toLDAPMod();
+ }
+ return ret;
}
DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPModification::LDAPModification()" << endl);
DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
" attr:" << attr << endl);
- m_attr = attr;
- m_mod_op = op;
+ m_attr = attr;
+ m_mod_op = op;
}
LDAPMod* LDAPModification::toLDAPMod() const {
DEBUG(LDAP_DEBUG_TRACE,"LDAPModification::toLDAPMod()" << endl);
- LDAPMod* ret=m_attr.toLDAPMod();
+ LDAPMod* ret=m_attr.toLDAPMod();
- //The mod_op value of the LDAPMod-struct needs to be ORed with the right
- // LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
+ //The mod_op value of the LDAPMod-struct needs to be ORed with the right
+ // LDAP_MOD_* constant to preserve the BIN-flag (see CAPI-draft for
// explanation of the LDAPMod struct)
- switch (m_mod_op){
- case OP_ADD :
- ret->mod_op |= LDAP_MOD_ADD;
- break;
- case OP_DELETE :
- ret->mod_op |= LDAP_MOD_DELETE;
- break;
- case OP_REPLACE :
- ret->mod_op |= LDAP_MOD_REPLACE;
- break;
- }
- return ret;
+ switch (m_mod_op){
+ case OP_ADD :
+ ret->mod_op |= LDAP_MOD_ADD;
+ break;
+ case OP_DELETE :
+ ret->mod_op |= LDAP_MOD_DELETE;
+ break;
+ case OP_REPLACE :
+ ret->mod_op |= LDAP_MOD_REPLACE;
+ break;
+ }
+ return ret;
}
LDAPMod** tmpMods=m_modList->toLDAPModArray();
int err=ldap_modify_ext(m_connection->getSessionHandle(),m_dn.c_str(),
tmpMods, tmpSrvCtrls, tmpClCtrls,&msgID);
- ldap_controls_free(tmpSrvCtrls);
- ldap_controls_free(tmpClCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrls);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrls);
+ ldap_mods_free(tmpMods,1);
if(err != LDAP_SUCCESS){
throw LDAPException(err);
}else{
}
if(matchedDN != 0){
m_matchedDN=string(matchedDN);
- delete[] matchedDN;
+ free(matchedDN);
}
if(errMsg != 0){
m_errMsg=string(errMsg);
- delete[] errMsg;
+ free(errMsg);
}
}
}
tmpClCtrl, tmptime, m_cons->getSizeLimit(), &msgID );
delete tmptime;
ldap_value_free(tmpattrs);
- ldap_controls_free(tmpSrvCtrl);
- ldap_controls_free(tmpClCtrl);
+ LDAPControlSet::freeLDAPControlArray(tmpSrvCtrl);
+ LDAPControlSet::freeLDAPControlArray(tmpClCtrl);
if (err != LDAP_SUCCESS){
throw LDAPException(err);
char** StringList::toCharArray() const{
if(!empty()){
- char** ret = new char*[size()+1];
+ char** ret = (char**) malloc(sizeof(char*) * (size()+1));
StringList::const_iterator i;
int j=0;
for(i=begin(); i != end(); i++,j++){
- ret[j]=new char[i->size()+1];
+ ret[j]=(char*) malloc(sizeof(char) * (i->size()+1));
i->copy(ret[j],string::npos);
ret[j][i->size()]=0;
}