Back to index

openldap  2.4.31
Public Member Functions | Private Attributes | Friends
LDAPAttribute Class Reference

Represents the name an value(s) of an Attribute. More...

#include <LDAPAttribute.h>

Collaboration diagram for LDAPAttribute:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 LDAPAttribute ()
 Default constructor.
 LDAPAttribute (const LDAPAttribute &attr)
 Copy constructor.
 LDAPAttribute (const std::string &name, const std::string &value="")
 Construct an Attribute with a single string value.
 LDAPAttribute (const char *name, char **values)
 Construct an attribute with multiple string values.
 LDAPAttribute (const std::string &name, const StringList &values)
 Construct an attribute with multiple string values.
 LDAPAttribute (const char *name, BerValue **values)
 Construct an attribute with multiple binary coded values.
 ~LDAPAttribute ()
 Destructor.
void addValue (const std::string &value)
 Add a single string value(bin/char) to the Attribute.
int addValue (const BerValue *value)
 Add a single binary value to the Attribute.
int setValues (char **values)
 Set the values of the attribute.
int setValues (BerValue **values)
 Set the values of the attribute.
void setValues (const StringList &values)
 Set the values of the attribute.
BerValue ** getBerValues () const
 For interal use only.
const StringListgetValues () const
int getNumValues () const
const std::string & getName () const
void setName (const std::string &name)
 Sets the Attribute's name (type)
LDAPModtoLDAPMod () const
 For internal use only.
bool isNotPrintable () const

Private Attributes

std::string m_name
StringList m_values

Friends

std::ostream & operator<< (std::ostream &s, const LDAPAttribute &attr)
 This method can be used to dump the data of a LDAPResult-Object.

Detailed Description

Represents the name an value(s) of an Attribute.

Definition at line 21 of file LDAPAttribute.h.


Constructor & Destructor Documentation

Default constructor.

initializes an empty object.

Definition at line 25 of file LDAPAttribute.cpp.

                            {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute( )" << endl);
    m_name=string();
}

Copy constructor.

Copies all values of an Attribute to a new one

Parameters:
attrThe Attribute that should be copied

Definition at line 30 of file LDAPAttribute.cpp.

                                                     {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute(&)" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
            "   attr:" << attr << endl);
       m_name=attr.m_name;
    m_values=StringList(attr.m_values);
}
LDAPAttribute::LDAPAttribute ( const std::string &  name,
const std::string &  value = "" 
)

Construct an Attribute with a single string value.

Parameters:
nameThe attribute's name (type)
valueThe string value of the attribute, if "" the attribute will have no values, for LDAPv3 this values must be UTF-8 encoded

Definition at line 38 of file LDAPAttribute.cpp.

                                                                   {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
            "   name:" << name << endl << "   value:" << value << endl);
    this->setName(name);
    if(value != ""){
       this->addValue(value);
    }
}
LDAPAttribute::LDAPAttribute ( const char *  name,
char **  values 
)

Construct an attribute with multiple string values.

Parameters:
nameThe attribute's name (type)
valuesA 0-terminated array of char*. Each char* specifies one value of the attribute (UTF-8 encoded)

Definition at line 57 of file LDAPAttribute.cpp.

                                                           {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
            "   name:" << name << endl);
       this->setName(name);
       this->setValues(values);
}
LDAPAttribute::LDAPAttribute ( const std::string &  name,
const StringList values 
)

Construct an attribute with multiple string values.

Parameters:
nameThe attribute's name (type)
valuesA list of strings. Each element specifies one value of the attribute (UTF-8 or binary encoded)

Definition at line 49 of file LDAPAttribute.cpp.

                                                                        {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
            "   name:" << name << endl);
    m_name=name;
    m_values=values;
}
LDAPAttribute::LDAPAttribute ( const char *  name,
BerValue **  values 
)

Construct an attribute with multiple binary coded values.

Parameters:
nameThe attribute's name (type)
values0-terminated array of binary attribute values The BerValue struct is declared as:
struct berval{ unsigned long bv_len; char *bv_val; } BerValue;

Definition at line 65 of file LDAPAttribute.cpp.

                                                               {
    DEBUG(LDAP_DEBUG_CONSTRUCT, "LDAPAttribute::LDAPAttribute()" << endl);
    DEBUG(LDAP_DEBUG_CONSTRUCT | LDAP_DEBUG_PARAMETER,
            "   name:" << name << endl);
       this->setName(name);
       this->setValues(values);
}

Destructor.

Definition at line 73 of file LDAPAttribute.cpp.

                             {
    DEBUG(LDAP_DEBUG_DESTROY,"LDAPAttribute::~LDAPAttribute()" << endl);
}

Member Function Documentation

void LDAPAttribute::addValue ( const std::string &  value)

Add a single string value(bin/char) to the Attribute.

Parameters:
valueValue that should be added, it is copied inside the object

Definition at line 77 of file LDAPAttribute.cpp.

                                               {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
    m_values.add(value);
}

Here is the caller graph for this function:

Add a single binary value to the Attribute.

Parameters:
valueThe binary coded value that should be added to the Attribute.
Returns:
0 no problem
-1 failure (mem. allocation problem)

Definition at line 82 of file LDAPAttribute.cpp.

                                                {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::addValue()" << endl);
       if(value!=0){
              this->addValue(string(value->bv_val, value->bv_len));
              return 0;
       }
       return -1;
}

For interal use only.

This method is used to translate the values of the Attribute to 0-terminated Array of BerValue-structs as used by the C-API

Returns:
The Values of the Attribute as an 0-terminated Array of BerValue* (is dynamically allocated, delete it after usage)
0-pointer in case of error

Definition at line 125 of file LDAPAttribute.cpp.

                                            {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getBerValues()" << endl);
    size_t size=m_values.size();
    if (size == 0){
        return 0;
    }else{
        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]=(BerValue*) malloc(sizeof(BerValue));
            temp[p]->bv_len= i->size();
            temp[p]->bv_val= (char*) malloc(sizeof(char) * (i->size()+1));
            i->copy(temp[p]->bv_val,string::npos);
        }
        temp[size]=0;
        return temp;
    }
}

Here is the caller graph for this function:

const string & LDAPAttribute::getName ( ) const
Returns:
The name(type) of the attribute

Definition at line 151 of file LDAPAttribute.cpp.

                                           {
    DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::getName()" << endl);
       return m_name;
}

Here is the caller graph for this function:

Returns:
The number of values of the attribute

Definition at line 146 of file LDAPAttribute.cpp.

                                     {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getNumValues()" << endl);
       return m_values.size();
}
Returns:
The values of the array as a list of strings

Definition at line 120 of file LDAPAttribute.cpp.

                                                {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::getValues()" << endl);
    return m_values;
}

Here is the caller graph for this function:

Returns:
true If the attribute contains non-printable attributes

Definition at line 175 of file LDAPAttribute.cpp.

                                         {
    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;
}

Here is the caller graph for this function:

void LDAPAttribute::setName ( const std::string &  name)

Sets the Attribute's name (type)

Parameters:
thenew name of the object

Definition at line 156 of file LDAPAttribute.cpp.

                                             {
    DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::setName()" << endl);
    DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,"   name:" << name << endl);
    m_name.erase();
    m_name=name;
}
int LDAPAttribute::setValues ( char **  values)

Set the values of the attribute.

If the object contains some values already, they are deleted

Parameters:
values0-terminated array of char*, each char* representing a string value to add to the entry
Returns:
0 no problem
-1 failure (mem. allocation problem)

Definition at line 91 of file LDAPAttribute.cpp.

                                         {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
       if(values){
        m_values.clear();
        for( char **i=values; *i!=0; i++){
            this->addValue(*i);
        }
    }
    return 0;
}

Set the values of the attribute.

If the object does already contain some values, they will be deleted

Parameters:
values0-terminated array of BerValue*, each BerValue representing a binary value to add to the entry
Returns:
0 no problem
-1 failure (mem. allocation problem)

Definition at line 102 of file LDAPAttribute.cpp.

                                             {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
    if(values){
           m_values.clear();
        for( BerValue **i=values; *i!=0; i++){
            if( this->addValue(*i) ){
                return -1;
            }
        }
    }
       return 0;
}

Set the values of the attribute.

If the object does already contain some values, they will be deleted

Parameters:
valuesA list of string-Objects. Each string is representing a string or binary value to add to the entry

Definition at line 115 of file LDAPAttribute.cpp.

                                                     {
    DEBUG(LDAP_DEBUG_TRACE,"LDAPAttribute::setValues()" << endl);
    m_values=values;
}

For internal use only.

This method translate the attribute of the object into a LDAPMod-Structure as used by the C-API

Definition at line 164 of file LDAPAttribute.cpp.

                                        {
    DEBUG(LDAP_DEBUG_TRACE, "LDAPAttribute::toLDAPMod()" << endl);
    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;
}

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  s,
const LDAPAttribute attr 
) [friend]

This method can be used to dump the data of a LDAPResult-Object.

It is only useful for debugging purposes at the moment

Definition at line 188 of file LDAPAttribute.cpp.

                                                            {
    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;
}

Member Data Documentation

std::string LDAPAttribute::m_name [private]

Definition at line 172 of file LDAPAttribute.h.

Definition at line 173 of file LDAPAttribute.h.


The documentation for this class was generated from the following files: