]> git.sur5r.net Git - openldap/commitdiff
Implement DN_PARENT_PREFIX and framework for DN_SUBTREE_PREFIX.
authorKurt Zeilenga <kurt@openldap.org>
Wed, 11 Aug 1999 20:59:28 +0000 (20:59 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 11 Aug 1999 20:59:28 +0000 (20:59 +0000)
servers/slapd/back-ldbm/back-ldbm.h
servers/slapd/back-ldbm/dn2id.c
servers/slapd/back-ldbm/index.c
servers/slapd/dn.c
servers/slapd/proto-slap.h
servers/slapd/tools/ldif2id2children.c

index bd2613d561f396f68d1898d0d2c27dda2cad084e..5df341a6db5dc42e92674d5493f780578a53b9b5 100644 (file)
@@ -24,8 +24,9 @@ LDAP_BEGIN_DECL
 
 #define SUBLEN                 3
 
+#define DN_INDICES 1
 /* #define DN_INDICES 1 *//* generate dn eq, subtree, and parent indices */
-#define DN_EQ_PREFIX           '='
+#define DN_ENTRY_PREFIX                '='
 #define DN_SUBTREE_PREFIX      '+'
 #define DN_PARENT_PREFIX       '-'
 
index 7bfb1078e22ab7e45fd1c87f4a17cc5b97f671cd..2ae17df03c8e0d28f9093372904d947c91b710a9 100644 (file)
@@ -45,7 +45,7 @@ dn2id_add(
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
 #endif
 
        data.dptr = (char *) &id;
@@ -56,12 +56,46 @@ dn2id_add(
 
        rc = ldbm_cache_store( db, key, data, flags );
 
-       ldbm_cache_close( be, db );
-
 #ifdef DN_INDICES
        free( key.dptr );
+
+       if ( rc != -1 ) {
+               char *pdn = dn_parent( NULL, dn );
+
+               if( pdn != NULL ) {
+                       key.dsize = strlen( pdn ) + 2;
+                       key.dptr = ch_malloc( key.dsize );
+                       sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn );
+                       rc = idl_insert_key( be, db, key, id );
+                       free( key.dptr );
+               }
+       }
+
+       if ( rc != -1 ) {
+               char **subtree = dn_subtree( NULL, dn );
+
+               if( subtree != NULL ) {
+                       int i;
+                       for( i=0; subtree[i] != NULL; i++ ) {
+                               key.dsize = strlen( subtree[i] ) + 2;
+                               key.dptr = ch_malloc( key.dsize );
+                               sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] );
+
+                               rc = idl_insert_key( be, db, key, id );
+
+                               free( key.dptr );
+
+                               if(rc == -1) break;
+                       }
+
+                       charray_free( subtree );
+               }
+
+       }
 #endif
 
+       ldbm_cache_close( be, db );
+
        Debug( LDAP_DEBUG_TRACE, "<= dn2id_add %d\n", rc, 0, 0 );
        return( rc );
 }
@@ -96,13 +130,48 @@ dn2id(
                return( NOID );
        }
 
+#ifdef DN_INDICES
+       {
+               char *pdn = dn_parent( NULL, dn );
+
+               if( pdn != NULL ) {
+                       key.dsize = strlen( pdn ) + 2;
+                       key.dptr = ch_malloc( key.dsize );
+                       sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn );
+                       (void) idl_delete_key( be, db, key, id );
+                       free( key.dptr );
+               }
+
+       }
+
+       {
+               char **subtree = dn_subtree( NULL, dn );
+
+               if( subtree != NULL ) {
+                       int i;
+                       for( i=0; subtree[i] != NULL; i++ ) {
+                               key.dsize = strlen( dn ) + 2;
+                               key.dptr = ch_malloc( key.dsize );
+                               sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, dn );
+
+                               (void) idl_delete_key( be, db, key, id );
+
+                               free( key.dptr );
+                       }
+
+                       charray_free( subtree );
+               }
+
+       }
+#endif
+
 #ifndef DN_INDICES
        key.dptr = dn;
        key.dsize = strlen( key.dptr ) + 1;
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
 #endif
 
        data = ldbm_cache_fetch( db, key );
@@ -154,7 +223,7 @@ dn2id_delete(
 #else
        key.dsize = strlen( dn ) + 2;
        key.dptr = ch_malloc( key.dsize );
-       sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, dn );
+       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn );
 #endif
 
        rc = ldbm_cache_delete( db, key );
index debd1608fb79b11404ebe6e8efc50d2c1192b9c6..f10a5906fd98637689c67dc3efbd7e11e7dcce4b 100644 (file)
@@ -133,8 +133,8 @@ index_read(
        ldbm_datum_init( key );
 
        prefix = index2prefix( indextype );
-       Debug( LDAP_DEBUG_TRACE, "=> index_read( \"%s\" \"%c\" \"%s\" )\n",
-           type, prefix, val );
+       Debug( LDAP_DEBUG_TRACE, "=> index_read(\"%c%s\"->\"%s\")\n",
+           prefix, type, val );
 
        attr_masks( be->be_private, type, &indexmask, &syntax );
        if ( ! (indextype & indexmask) ) {
index cc88a40bbfe280057996ba0d34a7682612de31ae..b52079f25898a3896660b6f4aca6ec948140f6eb 100644 (file)
@@ -339,6 +339,19 @@ char * dn_rdn(
        return( dn );
 }
 
+
+/*
+ * return a charray of all subtrees to which the DN resides in
+ */
+char **dn_subtree(
+       Backend *be,
+    char       *dn )
+{
+       /* not yet implemented */
+       return NULL;
+}
+
+
 /*
  * dn_issuffix - tells whether suffix is a suffix of dn.  both dn
  * and suffix must be normalized.
index 7e6562a05a06916257b79e92b26dffc893aad877..801dbd2afcc0c5c30637a69798ce49fb68f3445f 100644 (file)
@@ -188,6 +188,7 @@ void connection_done LDAP_P((Connection *));
 char * dn_normalize LDAP_P(( char *dn ));
 char * dn_normalize_case LDAP_P(( char *dn ));
 char * dn_parent LDAP_P(( Backend *be, char *dn ));
+char ** dn_subtree LDAP_P(( Backend *be, char *dn ));
 char * dn_rdn LDAP_P(( Backend *be, char *dn ));
 int dn_issuffix LDAP_P(( char *dn, char *suffix ));
 #ifdef DNS_DN
index 4258a87aeab9c0fdabe6115095fdf7371b4e1dbd..5c50f3909c2f7d8c8c7a3803a3a0602d9cd21176 100644 (file)
@@ -92,7 +92,7 @@ main( int argc, char **argv )
 #else
                                        key.dsize = strlen( val ) + 2;
                                        key.dptr = ch_malloc( key.dsize );
-                                       sprintf( key.dptr, "%c%s", DN_EQ_PREFIX, val );
+                                       sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, val );
 #endif
                                        data.dptr = (char *) &id;
                                        data.dsize = sizeof(ID);
@@ -102,7 +102,51 @@ main( int argc, char **argv )
                                                exit( EXIT_FAILURE );
                                        }
 #ifdef DN_INDICES
-                                       free( val );
+                                       free( key.dptr );
+
+                                       {
+                                               int rc = 0;
+                                               char *pdn = dn_parent( NULL, val );
+
+                                               if( pdn != NULL ) {
+                                                       key.dsize = strlen( pdn ) + 2;
+                                                       key.dptr = ch_malloc( key.dsize );
+                                                       sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn );
+                                                       rc = idl_insert_key( be, db, key, id );
+                                                       free( key.dptr );
+                                               }
+
+                                               if( rc == -1 ) {
+                                                       perror( "dn2id dn_parent insert" );
+                                                       exit( EXIT_FAILURE );
+                                               }
+                                       }
+
+                                       {
+                                               int rc = 0;
+                                               char **subtree = dn_subtree( NULL, val );
+
+                                               if( subtree != NULL ) {
+                                                       int i;
+                                                       for( i=0; subtree[i] != NULL; i++ ) {
+                                                               key.dsize = strlen( subtree[i] ) + 2;
+                                                               key.dptr = ch_malloc( key.dsize );
+                                                               sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] );
+
+                                                               rc = idl_insert_key( be, db, key, id );
+
+                                                               free( key.dptr );
+
+                                                               if( rc == -1 ) {
+                                                                       perror( "dn2id dn_subtree insert" );
+                                                                       exit( EXIT_FAILURE );
+                                                               }
+                                                       }
+
+                                                       charray_free( subtree );
+                                               }
+
+                                       }
 #endif
                                }
        }