2 * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
8 // * some kind of iterator to step through the attribute values
9 // * remove values from Attribute
10 // * handling of subtypes (;de; and so on)
11 // * some documentation
18 #include "StringList.h"
20 #include "LDAPAttribute.h"
23 LDAPAttribute::LDAPAttribute(){
24 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute( )" << endl);
28 LDAPAttribute::LDAPAttribute(const LDAPAttribute& attr){
29 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute(&)" << endl);
30 DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
31 " attr:" << attr << endl);
33 m_values=StringList(attr.m_values);
36 LDAPAttribute::LDAPAttribute(const string& name, const string& value){
37 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
38 DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
39 " name:" << name << endl << " value:" << value << endl);
42 this->addValue(value);
47 LDAPAttribute::LDAPAttribute(const string& name, const StringList& values){
48 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
49 DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
50 " name:" << name << endl);
55 LDAPAttribute::LDAPAttribute(const char *name, char **values){
56 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
57 DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
58 " name:" << name << endl);
60 this->setValues(values);
63 LDAPAttribute::LDAPAttribute(const char *name, BerValue **values){
64 DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
65 DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
66 " name:" << name << endl);
68 this->setValues(values);
71 LDAPAttribute::~LDAPAttribute(){
72 DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttribute::~LDAPAttribute()" << endl);
75 void LDAPAttribute::addValue(const string& value){
76 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
80 int LDAPAttribute::addValue(const BerValue *value){
81 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
83 this->addValue(string(value->bv_val, value->bv_len));
89 int LDAPAttribute::setValues(char **values){
90 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
93 for( char **i=values; *i!=0; i++){
100 int LDAPAttribute::setValues(BerValue **values){
101 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
104 for( BerValue **i=values; *i!=0; i++){
105 if( this->addValue(*i) ){
113 void LDAPAttribute::setValues(const StringList& values){
114 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
118 const StringList& LDAPAttribute::getValues() const{
119 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getValues()" << endl);
123 BerValue** LDAPAttribute::getBerValues() const{
124 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getBerValues()" << endl);
125 size_t size=m_values.size();
129 BerValue **temp = new BerValue*[size+1];
130 StringList::const_iterator i;
133 for(i=m_values.begin(), p=0; i!=m_values.end(); i++,p++){
134 temp[p]=new BerValue;
135 temp[p]->bv_len= i->size();
136 temp[p]->bv_val= new char[i->size()+1];
137 i->copy(temp[p]->bv_val,string::npos);
144 int LDAPAttribute::getNumValues() const{
145 DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getNumValues()" << endl);
146 return m_values.size();
149 const string& LDAPAttribute::getName() const {
150 DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::getName()" << endl);
154 void LDAPAttribute::setName(const string& name){
155 DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::setName()" << endl);
156 DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER," name:" << name << endl);
161 // The bin-FLAG of the mod_op is always set to LDAP_MOD_BVALUES (0x80)
162 LDAPMod* LDAPAttribute::toLDAPMod() const {
163 DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::toLDAPMod()" << endl);
164 LDAPMod* ret=new LDAPMod();
165 ret->mod_op=LDAP_MOD_BVALUES; //always assume binary-Values
166 ret->mod_type= new char[m_name.size()+1];
167 m_name.copy(ret->mod_type,string::npos);
168 cerr << " " << m_name<< endl;
169 ret->mod_type[m_name.size()]=0;
170 ret->mod_bvalues=this->getBerValues();
174 bool LDAPAttribute::isNotPrintable() const {
175 StringList::const_iterator i;
176 for(i=m_values.begin(); i!=m_values.end(); i++){
177 size_t len = i->size();
178 for(size_t j=0; j<len; j++){
179 if (! isprint( (i->data())[j] ) ){
187 ostream& operator << (ostream& s, const LDAPAttribute& attr){
188 s << attr.m_name << "=";
189 StringList::const_iterator i;
190 if (attr.isNotPrintable()){
191 s << "NOT_PRINTABLE" ;
193 for(i=attr.m_values.begin(); i!=attr.m_values.end(); i++){