From: Kurt Zeilenga Date: Wed, 11 Aug 1999 20:59:28 +0000 (+0000) Subject: Implement DN_PARENT_PREFIX and framework for DN_SUBTREE_PREFIX. X-Git-Tag: TWEB_OL_BASE~233 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1ffe5122b72603930a58fe5e731ed2cc7aedc875;p=openldap Implement DN_PARENT_PREFIX and framework for DN_SUBTREE_PREFIX. --- diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index bd2613d561..5df341a6db 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -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 '-' diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 7bfb1078e2..2ae17df03c 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -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 ); diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index debd1608fb..f10a5906fd 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -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) ) { diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index cc88a40bbf..b52079f258 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -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. diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 7e6562a05a..801dbd2afc 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -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 diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c index 4258a87aea..5c50f3909c 100644 --- a/servers/slapd/tools/ldif2id2children.c +++ b/servers/slapd/tools/ldif2id2children.c @@ -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 } }