]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/oc.c
error message from be_entry_put tool backend function
[openldap] / servers / slapd / oc.c
index aac10ef95db6ca62029b0a3d72042200a9d4cdbc..c2ba69013df2c18d05162c54a4d27a1fecd2466a 100644 (file)
@@ -1,7 +1,7 @@
 /* oc.c - object class routines */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -51,7 +51,7 @@ int is_entry_objectclass(
        ObjectClass *oc )
 {
        Attribute *attr;
-       int i;
+       struct berval *bv;
        AttributeDescription *objectClass = slap_schema.si_ad_objectClass;
        assert(!( e == NULL || oc == NULL ));
 
@@ -81,8 +81,8 @@ int is_entry_objectclass(
                return 0;
        }
 
-       for( i=0; attr->a_vals[i]; i++ ) {
-               ObjectClass *objectClass = oc_find( attr->a_vals[i]->bv_val );
+       for( bv=attr->a_vals; bv->bv_val; bv++ ) {
+               ObjectClass *objectClass = oc_bvfind( bv );
 
                if( objectClass == oc ) {
                        return 1;
@@ -95,7 +95,7 @@ int is_entry_objectclass(
 
 
 struct oindexrec {
-       char            *oir_name;
+       struct berval   oir_name;
        ObjectClass     *oir_oc;
 };
 
@@ -107,56 +107,32 @@ oc_index_cmp(
     struct oindexrec   *oir1,
     struct oindexrec   *oir2 )
 {
-       assert( oir1->oir_name );
-       assert( oir1->oir_oc );
-       assert( oir2->oir_name );
-       assert( oir2->oir_oc );
-
-       return strcasecmp( oir1->oir_name, oir2->oir_name );
-}
-
-static int
-oc_index_bvname_cmp(
-    struct berval      *name,
-    struct oindexrec   *oir )
-{
-       int rc;
-
-       assert( oir->oir_name );
-       assert( oir->oir_oc );
-
-       rc = strncasecmp( name->bv_val, oir->oir_name, name->bv_len );
-       if (rc) return rc;
-       return oir->oir_name[name->bv_len] ? -1 : 0;
+       int i = oir1->oir_name.bv_len - oir2->oir_name.bv_len;
+       if (i)
+               return i;
+       return strcasecmp( oir1->oir_name.bv_val, oir2->oir_name.bv_val );
 }
 
 static int
 oc_index_name_cmp(
-    char               *name,
+    struct berval      *name,
     struct oindexrec   *oir )
 {
-       assert( oir->oir_name );
-       assert( oir->oir_oc );
-
-       return (strcasecmp( name, oir->oir_name ));
+       int i = name->bv_len - oir->oir_name.bv_len;
+       if (i)
+               return i;
+       return strncasecmp( name->bv_val, oir->oir_name.bv_val, name->bv_len );
 }
 
 ObjectClass *
 oc_find( const char *ocname )
 {
-       struct oindexrec        *oir;
+       struct berval bv;
 
-       oir = (struct oindexrec *) avl_find( oc_index, ocname,
-            (AVL_CMP) oc_index_name_cmp );
+       bv.bv_val = (char *)ocname;
+       bv.bv_len = strlen( ocname );
 
-       if ( oir != NULL ) {
-               assert( oir->oir_name );
-               assert( oir->oir_oc );
-
-               return( oir->oir_oc );
-       }
-
-       return( NULL );
+       return( oc_bvfind( &bv ) );
 }
 
 ObjectClass *
@@ -165,12 +141,9 @@ oc_bvfind( struct berval *ocname )
        struct oindexrec        *oir;
 
        oir = (struct oindexrec *) avl_find( oc_index, ocname,
-            (AVL_CMP) oc_index_bvname_cmp );
+            (AVL_CMP) oc_index_name_cmp );
 
        if ( oir != NULL ) {
-               assert( oir->oir_name );
-               assert( oir->oir_oc );
-
                return( oir->oir_oc );
        }
 
@@ -321,9 +294,9 @@ oc_destroy( void )
        for (o=oc_list; o; o=n)
        {
                n = o->soc_next;
-               ldap_memfree(o->soc_sups);
-               ldap_memfree(o->soc_required);
-               ldap_memfree(o->soc_allowed);
+               if (o->soc_sups) ldap_memfree(o->soc_sups);
+               if (o->soc_required) ldap_memfree(o->soc_required);
+               if (o->soc_allowed) ldap_memfree(o->soc_allowed);
                ldap_objectclass_free((LDAPObjectClass *)o);
        }
 }
@@ -347,10 +320,11 @@ oc_insert(
        if ( soc->soc_oid ) {
                oir = (struct oindexrec *)
                        ch_calloc( 1, sizeof(struct oindexrec) );
-               oir->oir_name = soc->soc_oid;
+               oir->oir_name.bv_val = soc->soc_oid;
+               oir->oir_name.bv_len = strlen( soc->soc_oid );
                oir->oir_oc = soc;
 
-               assert( oir->oir_name );
+               assert( oir->oir_name.bv_val );
                assert( oir->oir_oc );
 
                if ( avl_insert( &oc_index, (caddr_t) oir,
@@ -363,17 +337,18 @@ oc_insert(
                }
 
                /* FIX: temporal consistency check */
-               assert( oc_find(oir->oir_name) != NULL );
+               assert( oc_bvfind(&oir->oir_name) != NULL );
        }
 
        if ( (names = soc->soc_names) ) {
                while ( *names ) {
                        oir = (struct oindexrec *)
                                ch_calloc( 1, sizeof(struct oindexrec) );
-                       oir->oir_name = *names;
+                       oir->oir_name.bv_val = *names;
+                       oir->oir_name.bv_len = strlen( *names );
                        oir->oir_oc = soc;
 
-                       assert( oir->oir_name );
+                       assert( oir->oir_name.bv_val );
                        assert( oir->oir_oc );
 
                        if ( avl_insert( &oc_index, (caddr_t) oir,
@@ -386,7 +361,7 @@ oc_insert(
                        }
 
                        /* FIX: temporal consistency check */
-                       assert( oc_find(oir->oir_name) != NULL );
+                       assert( oc_bvfind(&oir->oir_name) != NULL );
 
                        names++;
                }
@@ -414,6 +389,19 @@ oc_add(
                }
        }
 
+       if ( !OID_LEADCHAR( oc->oc_oid[0] )) {
+               /* Expand OID macros */
+               char *oid = oidm_find( oc->oc_oid );
+               if ( !oid ) {
+                       *err = oc->oc_oid;
+                       return SLAP_SCHERR_OIDM;
+               }
+               if ( oid != oc->oc_oid ) {
+                       ldap_memfree( oc->oc_oid );
+                       oc->oc_oid = oid;
+               }
+       }
+
        soc = (ObjectClass *) ch_calloc( 1, sizeof(ObjectClass) );
        AC_MEMCPY( &soc->soc_oclass, oc, sizeof(LDAPObjectClass) );
 
@@ -472,27 +460,23 @@ oc_print( ObjectClass *oc )
 int
 oc_schema_info( Entry *e )
 {
-       struct berval   val;
-       struct berval   *vals[2];
+       struct berval   vals[2];
        ObjectClass     *oc;
 
        AttributeDescription *ad_objectClasses = slap_schema.si_ad_objectClasses;
 
-       vals[0] = &val;
-       vals[1] = NULL;
+       vals[1].bv_val = NULL;
 
        for ( oc = oc_list; oc; oc = oc->soc_next ) {
-               val.bv_val = ldap_objectclass2str( &oc->soc_oclass );
-               if ( val.bv_val == NULL ) {
+               if ( ldap_objectclass2bv( &oc->soc_oclass, vals ) == NULL ) {
                        return -1;
                }
-               val.bv_len = strlen( val.bv_val );
 #if 0
                Debug( LDAP_DEBUG_TRACE, "Merging oc [%ld] %s\n",
-              (long) val.bv_len, val.bv_val, 0 );
+              (long) vals[0].bv_len, vals[0].bv_val, 0 );
 #endif
                attr_merge( e, ad_objectClasses, vals );
-               ldap_memfree( val.bv_val );
+               ldap_memfree( vals[0].bv_val );
        }
        return 0;
 }