]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
7210eece0dcf29d47795d11dece11166acd5b1bb
[openldap] / servers / slapd / back-ldbm / id2children.c
1 /* id2children.c - routines to deal with the id2children index */
2
3 #include <stdio.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include "slap.h"
7 #include "back-ldbm.h"
8
9 struct dbcache  *ldbm_cache_open();
10 extern Datum    ldbm_cache_fetch();
11 IDList          *idl_fetch();
12
13 int
14 id2children_add(
15     Backend     *be,
16     Entry       *p,
17     Entry       *e
18 )
19 {
20         struct dbcache  *db;
21         Datum           key, data;
22         int             len, rc;
23         IDList          *idl;
24         char            buf[20];
25
26 #ifdef LDBM_USE_DB2
27         memset( &key, 0, sizeof( key ) );
28         memset( &data, 0, sizeof( data ) );
29 #endif
30
31         Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %d, %d )\n", p ? p->e_id
32             : 0, e->e_id, 0 );
33
34         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
35             LDBM_WRCREAT )) == NULL ) {
36                 Debug( LDAP_DEBUG_ANY,
37                     "<= id2children_add -1 could not open \"id2children%s\"\n",
38                     LDBM_SUFFIX, 0, 0 );
39                 return( -1 );
40         }
41
42         sprintf( buf, "%c%d", EQ_PREFIX, p ? p->e_id : 0 );
43         key.dptr = buf;
44         key.dsize = strlen( buf ) + 1;
45
46         if ( idl_insert_key( be, db, key, e->e_id ) != 0 ) {
47                 Debug( LDAP_DEBUG_TRACE, "<= id2children_add -1 (idl_insert)\n",
48                     0, 0, 0 );
49                 ldbm_cache_close( be, db );
50                 return( -1 );
51         }
52
53         ldbm_cache_close( be, db );
54
55         Debug( LDAP_DEBUG_TRACE, "<= id2children_add 0\n", 0, 0, 0 );
56         return( 0 );
57 }
58
59 int
60 has_children(
61     Backend     *be,
62     Entry       *p
63 )
64 {
65         struct dbcache  *db;
66         Datum           key;
67         int             rc;
68         IDList          *idl;
69         char            buf[20];
70
71 #ifdef LDBM_USE_DB2
72         memset( &key, 0, sizeof( key ) );
73 #endif
74
75         Debug( LDAP_DEBUG_TRACE, "=> has_children( %d )\n", p->e_id , 0, 0 );
76
77         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
78             LDBM_WRCREAT )) == NULL ) {
79                 Debug( LDAP_DEBUG_ANY,
80                     "<= has_children -1 could not open \"id2children%s\"\n",
81                     LDBM_SUFFIX, 0, 0 );
82                 return( 0 );
83         }
84
85         sprintf( buf, "%c%d", EQ_PREFIX, p->e_id );
86         key.dptr = buf;
87         key.dsize = strlen( buf ) + 1;
88
89         idl = idl_fetch( be, db, key );
90
91         ldbm_cache_close( be, db );
92         rc = idl ? 1 : 0;
93         idl_free( idl );
94
95         Debug( LDAP_DEBUG_TRACE, "<= has_children %d\n", rc, 0, 0 );
96         return( rc );
97 }