2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
9 #include "LDAPAttributeList.h"
11 #include "LDAPException.h"
12 #include "LDAPAttribute.h"
13 #include "LDAPAsynConnection.h"
14 #include "LDAPMessage.h"
18 LDAPAttributeList::LDAPAttributeList(){
19 DEBUG(LDAP_DEBUG_CONSTRUCT,
20 "LDAPAttributeList::LDAPAttributList( )" << endl);
23 LDAPAttributeList::LDAPAttributeList(const LDAPAttributeList& al){
24 DEBUG(LDAP_DEBUG_CONSTRUCT,
25 "LDAPAttributeList::LDAPAttributList(&)" << endl);
29 LDAPAttributeList::LDAPAttributeList(const LDAPAsynConnection *ld,
31 DEBUG(LDAP_DEBUG_CONSTRUCT,
32 "LDAPAttributeList::LDAPAttributList()" << endl);
34 char *name=ldap_first_attribute(ld->getSessionHandle(), msg, &ptr);
36 This code was making problems if no attribute were returned
37 How am I supposed to find decoding errors? ldap_first/next_attribute
38 return 0 in case of error or if there are no more attributes. In either
39 case they set the LDAP* error code to 0x54 (Decoding error) ??? Strange..
41 There will be some changes in the new version of the C-API so that this
42 code should work in the future.
46 throw LDAPException(ld);
50 name=ldap_next_attribute(ld->getSessionHandle(),msg,ptr) ){
51 values=ldap_get_values_len(ld->getSessionHandle(),
53 this->addAttribute(LDAPAttribute(name, values));
55 ldap_value_free_len(values);
61 LDAPAttributeList::~LDAPAttributeList(){
62 DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttributeList::~LDAPAttributList()" << endl);
65 size_t LDAPAttributeList::size() const{
66 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::size()" << endl);
67 return m_attrs.size();
70 bool LDAPAttributeList::empty() const{
71 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::empty()" << endl);
72 return m_attrs.empty();
75 LDAPAttributeList::const_iterator LDAPAttributeList::begin() const{
76 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::begin()" << endl);
77 return m_attrs.begin();
80 LDAPAttributeList::const_iterator LDAPAttributeList::end() const{
81 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::end()" << endl);
85 void LDAPAttributeList::addAttribute(const LDAPAttribute& attr){
86 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addAttribute()" << endl);
87 DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
88 " attr:" << attr << endl);
89 m_attrs.push_back(attr);
93 LDAPMod** LDAPAttributeList::toLDAPModArray() const{
94 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::toLDAPModArray()" << endl);
95 LDAPMod **ret = (LDAPMod**) malloc((m_attrs.size()+1) * sizeof(LDAPMod*));
96 AttrList::const_iterator i;
98 for (i=m_attrs.begin(); i!= m_attrs.end(); i++, j++){
99 ret[j]=i->toLDAPMod();
101 ret[m_attrs.size()]=0;
105 ostream& operator << (ostream& s, const LDAPAttributeList& al){
106 AttrList::const_iterator i;
107 for(i=al.m_attrs.begin(); i!=al.m_attrs.end(); i++){