3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* attr.c - routines for dealing with attributes */
18 #include <ac/socket.h>
19 #include <ac/string.h>
26 static void at_index_print( void );
30 attr_free( Attribute *a )
32 #ifdef SLAPD_SCHEMA_NOT_COMPAT
33 /* not yet implemented */
34 ad_free( &a->a_desc, 0 );
38 ber_bvecfree( a->a_vals );
43 attrs_free( Attribute *a )
47 for( ; a != NULL ; a = next ) {
53 Attribute *attr_dup( Attribute *a )
57 if( a == NULL) return NULL;
59 tmp = ch_malloc( sizeof(Attribute) );
61 if( a->a_vals != NULL ) {
64 for( i=0; a->a_vals[i] != NULL; i++ ) {
68 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
70 for( i=0; a->a_vals[i] != NULL; i++ ) {
71 tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
73 if( tmp->a_vals[i] == NULL ) break;
76 tmp->a_vals[i] = NULL;
82 #ifdef SLAPD_SCHEMA_NOT_COMPAT
83 /* not yet implemented */
84 tmp->a_desc = a->a_desc;
85 tmp->a_desc.ad_cname = ber_bvdup( a->a_desc.ad_cname );
86 tmp->a_desc.ad_lang = ch_strdup( a->a_desc.ad_lang );
88 tmp->a_type = ch_strdup( a->a_type );
89 tmp->a_syntax = a->a_syntax;
96 Attribute *attrs_dup( Attribute *a )
98 Attribute *tmp, **next;
100 if( a == NULL ) return NULL;
105 for( ; a != NULL ; a = a->a_next ) {
106 *next = attr_dup( a );
107 next = &((*next)->a_next);
114 #ifndef SLAPD_SCHEMA_NOT_COMPAT
116 * attr_normalize - normalize an attribute name (make it all lowercase)
120 attr_normalize( char *s )
124 return( ldap_pvt_str2lower( s ) );
128 #ifndef SLAPD_SCHEMA_NOT_COMPAT
130 * attr_merge_fast - merge the given type and value with the list of
131 * attributes in attrs. called from str2entry(), where we can make some
132 * assumptions to make things faster.
133 * returns 0 everything went ok
141 struct berval **vals,
149 for ( *a = &e->e_attrs; **a != NULL; *a = &(**a)->a_next ) {
150 #ifdef SLAPD_SCHEMA_NOT_COMPAT
151 /* not yet implemented */
153 if ( strcasecmp( (**a)->a_type, type ) == 0 ) {
161 **a = (Attribute *) ch_malloc( sizeof(Attribute) );
162 (**a)->a_vals = NULL;
163 #ifndef SLAPD_SCHEMA_NOT_COMPAT
164 (**a)->a_type = attr_normalize( ch_strdup( type ) );
165 (**a)->a_syntax = attr_syntax( type );
167 (**a)->a_next = NULL;
170 return( value_add_fast( &(**a)->a_vals, vals, nvals, naddvals,
176 * attr_merge - merge the given type and value with the list of
177 * attributes in attrs.
178 * returns 0 everything went ok
191 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
192 #ifdef SLAPD_SCHEMA_NOT_COMPAT
193 /* not yet implemented */
195 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {
202 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
203 #ifdef SLAPD_SCHEMA_NOT_COMPAT
204 /* not yet implemented */
206 (*a)->a_type = attr_normalize( ch_strdup( type ) );
207 (*a)->a_syntax = attr_syntax( type );
213 return( value_add( &(*a)->a_vals, vals ) );
217 * attr_find - find attribute by type
226 for ( ; a != NULL; a = a->a_next ) {
227 #ifdef SLAPD_SCHEMA_NOT_COMPAT
228 /* not yet implemented */
230 if ( strcasecmp( a->a_type, type ) == 0 ) {
240 * attr_delete - delete the attribute type in list pointed to by attrs
241 * return 0 deleted ok
242 * 1 not found in list a
243 * -1 something bad happened
255 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
256 #ifdef SLAPD_SCHEMA_NOT_COMPAT
257 /* not yet implemented */
259 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {