1
// $OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPAttributeList.cpp,v 1.7.6.3 2008/04/14 23:09:26 quanah Exp $
3
* Copyright 2000-2007, OpenLDAP Foundation, All Rights Reserved.
4
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10
#include "LDAPAttributeList.h"
12
#include "LDAPException.h"
13
#include "LDAPAttribute.h"
14
#include "LDAPAsynConnection.h"
15
#include "LDAPMessage.h"
21
// little helper function for doing case insensitve string comparison
22
bool nocase_compare(char c1, char c2);
24
LDAPAttributeList::LDAPAttributeList(){
25
DEBUG(LDAP_DEBUG_CONSTRUCT,
26
"LDAPAttributeList::LDAPAttributList( )" << endl);
29
LDAPAttributeList::LDAPAttributeList(const LDAPAttributeList& al){
30
DEBUG(LDAP_DEBUG_CONSTRUCT,
31
"LDAPAttributeList::LDAPAttributList(&)" << endl);
35
LDAPAttributeList::LDAPAttributeList(const LDAPAsynConnection *ld,
37
DEBUG(LDAP_DEBUG_CONSTRUCT,
38
"LDAPAttributeList::LDAPAttributList()" << endl);
40
char *name=ldap_first_attribute(ld->getSessionHandle(), msg, &ptr);
42
This code was making problems if no attribute were returned
43
How am I supposed to find decoding errors? ldap_first/next_attribute
44
return 0 in case of error or if there are no more attributes. In either
45
case they set the LDAP* error code to 0x54 (Decoding error) ??? Strange..
47
There will be some changes in the new version of the C-API so that this
48
code should work in the future.
52
throw LDAPException(ld);
56
name=ldap_next_attribute(ld->getSessionHandle(),msg,ptr) ){
57
values=ldap_get_values_len(ld->getSessionHandle(),
59
this->addAttribute(LDAPAttribute(name, values));
61
ldap_value_free_len(values);
67
LDAPAttributeList::~LDAPAttributeList(){
68
DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttributeList::~LDAPAttributList()" << endl);
71
size_t LDAPAttributeList::size() const{
72
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::size()" << endl);
73
return m_attrs.size();
76
bool LDAPAttributeList::empty() const{
77
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::empty()" << endl);
78
return m_attrs.empty();
81
LDAPAttributeList::const_iterator LDAPAttributeList::begin() const{
82
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::begin()" << endl);
83
return m_attrs.begin();
86
LDAPAttributeList::const_iterator LDAPAttributeList::end() const{
87
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::end()" << endl);
91
const LDAPAttribute* LDAPAttributeList::getAttributeByName(
92
const string& name) const {
93
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getAttributeByName()" << endl);
94
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
95
" name:" << name << endl);
96
LDAPAttributeList::const_iterator i;
97
for( i = m_attrs.begin(); i != m_attrs.end(); i++){
98
const std::string& tmpType = i->getName();
99
if(name.size() == tmpType.size()){
100
if(equal(name.begin(), name.end(), tmpType.begin(),
103
DEBUG(LDAP_DEBUG_TRACE," found:" << name << endl);
110
void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){
111
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addAttribute()" << endl);
112
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
113
" attr:" << attr << endl);
114
const std::string attrType = attr.getName();
115
const std::string::size_type attrLen = attrType.size();
116
std::string::size_type tmpAttrLen = 0;
118
LDAPAttributeList::iterator i;
119
for( i=m_attrs.begin(); i != m_attrs.end(); i++ ){
120
const std::string tmpAttrType = i->getName();
121
tmpAttrLen = tmpAttrType.size();
122
if(tmpAttrLen == attrLen){
123
if(equal(tmpAttrType.begin(), tmpAttrType.end(), attrType.begin(),
125
const StringList& values = attr.getValues();
126
StringList::const_iterator j;
127
for(j = values.begin(); j != values.end(); j++){
130
DEBUG(LDAP_DEBUG_TRACE,"Attribute" << i->getName()
131
<< "already present" << endl);
133
break; // The AttributeType was already present,
139
m_attrs.push_back(attr);
143
void LDAPAttributeList::replaceAttribute(const LDAPAttribute& attr)
145
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::replaceAttribute()" << endl);
146
DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
147
" attr:" << attr << endl);
149
LDAPAttributeList::iterator i;
150
for( i = m_attrs.begin(); i != m_attrs.end(); i++){
151
if(attr.getName().size() == i->getName().size()){
152
if(equal(attr.getName().begin(), attr.getName().end(), i->getName().begin(),
159
m_attrs.push_back(attr);
162
LDAPMod** LDAPAttributeList::toLDAPModArray() const{
163
DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
164
LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
165
LDAPAttributeList::const_iterator i;
167
for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
168
ret[j]=i->toLDAPMod();
170
ret[m_attrs.size()]=0;
174
ostream& operator << (ostream& s, const LDAPAttributeList& al){
175
LDAPAttributeList::const_iterator i;
176
for(i=al.m_attrs.begin(); i!=al.m_attrs.end(); i++){
182
bool nocase_compare( char c1, char c2){
183
return toupper(c1) == toupper(c2);