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