]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/attr.c
fix previous commit
[openldap] / servers / slapd / attr.c
index 0513a9d2d5cbc312e2668b3f6aef76c4aa13c810..63973e03cfa53ec2271214579cb3558f4eec0f52 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2004 The OpenLDAP Foundation.
+ * Copyright 1998-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 
 #include "slap.h"
 
-#ifdef LDAP_COMP_MATCH
-extern free_component_func* component_destructor;
-#endif
 void
 attr_free( Attribute *a )
 {
-       if ( a->a_nvals && a->a_nvals != a->a_vals )
+       if ( a->a_nvals && a->a_nvals != a->a_vals ) {
                ber_bvarray_free( a->a_nvals );
-       ber_bvarray_free( a->a_vals );
-#ifdef LDAP_COMP_MATCH
-       if ( component_destructor && a->a_component_values ) {
-               component_destructor(a->a_component_values);
-               a->a_component_values = NULL;
        }
-#endif
+       /* a_vals may be equal to slap_dummy_bv, a static empty berval;
+        * this is used as a placeholder for attributes that do not carry
+        * values, e.g. when proxying search entries with the "attrsonly"
+        * bit set. */
+       if ( a->a_vals != &slap_dummy_bv ) {
+               ber_bvarray_free( a->a_vals );
+       }
        free( a );
 }
 
+#ifdef LDAP_COMP_MATCH
+void
+comp_tree_free( Attribute *a )
+{
+       Attribute *next;
+
+       for( ; a != NULL ; a = next ) {
+               next = a->a_next;
+               if ( component_destructor && a->a_comp_data ) {
+                       if ( a->a_comp_data->cd_mem_op )
+                               component_destructor( a->a_comp_data->cd_mem_op );
+                       free ( a->a_comp_data );
+               }
+       }
+}
+#endif
+
 void
 attrs_free( Attribute *a )
 {
@@ -118,7 +133,7 @@ attr_dup( Attribute *a )
        tmp->a_next = NULL;
        tmp->a_flags = 0;
 #ifdef LDAP_COMP_MATCH
-       tmp->a_component_values = NULL;
+       tmp->a_comp_data = NULL;
 #endif
 
        return tmp;
@@ -168,7 +183,7 @@ attr_merge(
        Attribute       **a;
 
        for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
-               if ( ad_cmp( (*a)->a_desc, desc ) == 0 ) {
+               if (  (*a)->a_desc == desc ) {
                        break;
                }
        }
@@ -181,8 +196,15 @@ attr_merge(
                (*a)->a_next = NULL;
                (*a)->a_flags = 0;
 #ifdef LDAP_COMP_MATCH
-               (*a)->a_component_values = NULL;
+               (*a)->a_comp_data = NULL;
 #endif
+       } else {
+               /*
+                * FIXME: if the attribute already exists, the presence
+                * of nvals and the value of (*a)->a_nvals must be consistent
+                */
+               assert( ( nvals == NULL && (*a)->a_nvals == (*a)->a_vals )
+                               || ( nvals != NULL && (*a)->a_nvals != (*a)->a_vals ) );
        }
 
        rc = value_add( &(*a)->a_vals, vals );
@@ -252,7 +274,7 @@ attr_merge_one(
        Attribute       **a;
 
        for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
-               if ( ad_cmp( (*a)->a_desc, desc ) == 0 ) {
+               if ( (*a)->a_desc == desc ) {
                        break;
                }
        }
@@ -265,7 +287,7 @@ attr_merge_one(
                (*a)->a_next = NULL;
                (*a)->a_flags = 0;
 #ifdef LDAP_COMP_MATCH
-               (*a)->a_component_values = NULL;
+               (*a)->a_comp_data = NULL;
 #endif
        }
 
@@ -344,7 +366,7 @@ attr_find(
        AttributeDescription *desc )
 {
        for ( ; a != NULL; a = a->a_next ) {
-               if ( ad_cmp( a->a_desc, desc ) == 0 ) {
+               if ( a->a_desc == desc ) {
                        return( a );
                }
        }
@@ -367,7 +389,7 @@ attr_delete(
        Attribute       **a;
 
        for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
-               if ( ad_cmp( (*a)->a_desc, desc ) == 0 ) {
+               if ( (*a)->a_desc == desc ) {
                        Attribute       *save = *a;
                        *a = (*a)->a_next;
                        attr_free( save );