1/* $NetBSD: LDAPAttribute.h,v 1.1.1.2 2010/03/08 02:14:14 lukem Exp $ */ 2 3// OpenLDAP: pkg/ldap/contrib/ldapc++/src/LDAPAttribute.h,v 1.6.8.1 2008/04/14 23:09:26 quanah Exp 4/* 5 * Copyright 2000-2002, OpenLDAP Foundation, All Rights Reserved. 6 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file 7 */ 8 9 10#ifndef LDAP_ATTRIBUTE_H 11#define LDAP_ATTRIBUTE_H 12 13#include<iostream> 14#include<string> 15#include<ldap.h> 16#include<lber.h> 17 18#include <StringList.h> 19 20/** 21 * Represents the name an value(s) of an Attribute 22 */ 23class LDAPAttribute{ 24 public : 25 /** 26 * Default constructor. 27 * initializes an empty object. 28 */ 29 LDAPAttribute(); 30 31 /** 32 * Copy constructor. 33 * Copies all values of an Attribute to a new one 34 * @param attr The Attribute that should be copied 35 */ 36 LDAPAttribute(const LDAPAttribute& attr); 37 38 /** 39 * Construct an Attribute with a single string value 40 * @param name The attribute's name (type) 41 * @param value The string value of the attribute, if "" the 42 * attribute will have no values, for LDAPv3 43 * this values must be UTF-8 encoded 44 */ 45 LDAPAttribute(const std::string& name, const std::string& value=""); 46 47 /** 48 * Construct an attribute with multiple string values 49 * @param name The attribute's name (type) 50 * @param values A 0-terminated array of char*. Each char* specifies 51 * one value of the attribute (UTF-8 encoded) 52 */ 53 LDAPAttribute(const char* name, char **values); 54 55 /** 56 * Construct an attribute with multiple string values 57 * @param name The attribute's name (type) 58 * @param values A list of strings. Each element specifies 59 * one value of the attribute (UTF-8 or binary 60 * encoded) 61 */ 62 LDAPAttribute(const std::string& name, const StringList& values); 63 64 /** 65 * Construct an attribute with multiple binary coded values 66 * @param name The attribute's name (type) 67 * @param values 0-terminated array of binary attribute values 68 * The BerValue struct is declared as:<BR> 69 * struct berval{ 70 * unsigned long bv_len; 71 * char *bv_val; 72 * } BerValue; 73 */ 74 LDAPAttribute(const char* name, BerValue **values); 75 76 /** 77 * Destructor 78 */ 79 ~LDAPAttribute(); 80 81 /** 82 * Add a single string value(bin/char) to the Attribute 83 * @param value Value that should be added, it is copied inside the 84 * object 85 */ 86 void addValue(const std::string& value); 87 88 /** 89 * Add a single binary value to the Attribute 90 * @param value The binary coded value that should be added to the 91 * Attribute. 92 * @return 0 no problem <BR> 93 * -1 failure (mem. allocation problem) 94 */ 95 int addValue(const BerValue *value); 96 97 /** 98 * Set the values of the attribute. If the object contains some values 99 * already, they are deleted 100 * @param values 0-terminated array of char*, each char* 101 * representing a string value to add to the entry 102 * 103 * @return 0 no problem <BR> 104 * -1 failure (mem. allocation problem) 105 */ 106 int setValues(char** values); 107 108 /** 109 * Set the values of the attribute. If the object does already contain 110 * some values, they will be deleted 111 * @param values 0-terminated array of BerValue*, each BerValue 112 * representing a binary value to add to the entry 113 * 114 * @return 0 no problem <BR> 115 * -1 failure (mem. allocation problem) 116 */ 117 int setValues(BerValue** values); 118 119 /** 120 * Set the values of the attribute. If the object does already contain 121 * some values, they will be deleted 122 * @param values A list of string-Objects. Each string is 123 * representing a string or binary value to add to 124 * the entry 125 */ 126 void setValues(const StringList& values); 127 128 /** 129 * For interal use only. 130 * This method is used to translate the values of the Attribute to 131 * 0-terminated Array of BerValue-structs as used by the C-API 132 * @return The Values of the Attribute as an 0-terminated Array of 133 * BerValue* (is dynamically allocated, delete it after usage) 134 * <BR> 135 * 0-pointer in case of error 136 */ 137 BerValue** getBerValues() const; 138 139 /** 140 * @return The values of the array as a list of strings 141 */ 142 const StringList& getValues() const; 143 144 /** 145 * @return The number of values of the attribute 146 */ 147 int getNumValues() const; 148 149 /** 150 * @return The name(type) of the attribute 151 */ 152 const std::string& getName() const ; 153 154 /** 155 * Sets the Attribute's name (type) 156 * @param the new name of the object 157 */ 158 void setName(const std::string& name); 159 160 /** 161 * For internal use only. 162 * 163 * This method translate the attribute of the object into a 164 * LDAPMod-Structure as used by the C-API 165 */ 166 LDAPMod* toLDAPMod() const ; 167 168 /** 169 * @return true If the attribute contains non-printable attributes 170 */ 171 bool isNotPrintable() const ; 172 173 private : 174 std::string m_name; 175 StringList m_values; 176 177 /** 178 * This method can be used to dump the data of a LDAPResult-Object. 179 * It is only useful for debugging purposes at the moment 180 */ 181 friend std::ostream& operator << (std::ostream& s, const LDAPAttribute& attr); 182}; 183#endif //#ifndef LDAP_ATTRIBUTE_H 184