]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
New dn2id format with base/one/subtree indices (ldbm/bdb2)
[openldap] / servers / slapd / back-ldbm / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2 /*
3  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10 #include <ac/string.h>
11
12 #include <ac/socket.h>
13
14 #include "slap.h"
15 #include "back-ldbm.h"
16
17
18 int
19 has_children(
20     Backend     *be,
21     Entry       *p
22 )
23 {
24         DBCache *db;
25         Datum           key;
26         int             rc = 0;
27         ID_BLOCK                *idl;
28
29         ldbm_datum_init( key );
30
31         Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 );
32
33         if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX,
34             LDBM_WRCREAT )) == NULL ) {
35                 Debug( LDAP_DEBUG_ANY,
36                     "<= has_children -1 could not open \"dn2id%s\"\n",
37                     LDBM_SUFFIX, 0, 0 );
38                 return( 0 );
39         }
40
41         key.dsize = strlen( p->e_ndn ) + 2;
42         key.dptr = ch_malloc( key.dsize );
43         sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn );
44
45         idl = idl_fetch( be, db, key );
46
47         free( key.dptr );
48
49         ldbm_cache_close( be, db );
50
51         if( idl != NULL ) {
52                 idl_free( idl );
53                 rc = 1;
54         }
55
56         Debug( LDAP_DEBUG_TRACE, "<= has_children( %ld ): %s\n",
57                 p->e_id, rc ? "yes" : "no", 0 );
58         return( rc );
59 }