]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/id2children.c
fix SIGUNUSED typo
[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         Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %d, %d )\n", p ? p->e_id
27             : 0, e->e_id, 0 );
28
29         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
30             LDBM_WRCREAT )) == NULL ) {
31                 Debug( LDAP_DEBUG_ANY,
32                     "<= id2children_add -1 could not open \"id2children%s\"\n",
33                     LDBM_SUFFIX, 0, 0 );
34                 return( -1 );
35         }
36
37         sprintf( buf, "%c%d", EQ_PREFIX, p ? p->e_id : 0 );
38         key.dptr = buf;
39         key.dsize = strlen( buf ) + 1;
40
41         if ( idl_insert_key( be, db, key, e->e_id ) != 0 ) {
42                 Debug( LDAP_DEBUG_TRACE, "<= id2children_add -1 (idl_insert)\n",
43                     0, 0, 0 );
44                 ldbm_cache_close( be, db );
45                 return( -1 );
46         }
47
48         ldbm_cache_close( be, db );
49
50         Debug( LDAP_DEBUG_TRACE, "<= id2children_add 0\n", 0, 0, 0 );
51         return( 0 );
52 }
53
54 int
55 has_children(
56     Backend     *be,
57     Entry       *p
58 )
59 {
60         struct dbcache  *db;
61         Datum           key;
62         int             rc;
63         IDList          *idl;
64         char            buf[20];
65
66         Debug( LDAP_DEBUG_TRACE, "=> has_children( %d )\n", p->e_id , 0, 0 );
67
68         if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
69             LDBM_WRCREAT )) == NULL ) {
70                 Debug( LDAP_DEBUG_ANY,
71                     "<= has_children -1 could not open \"id2children%s\"\n",
72                     LDBM_SUFFIX, 0, 0 );
73                 return( 0 );
74         }
75
76         sprintf( buf, "%c%d", EQ_PREFIX, p->e_id );
77         key.dptr = buf;
78         key.dsize = strlen( buf ) + 1;
79
80         idl = idl_fetch( be, db, key );
81
82         ldbm_cache_close( be, db );
83         rc = idl ? 1 : 0;
84         idl_free( idl );
85
86         Debug( LDAP_DEBUG_TRACE, "<= has_children %d\n", rc, 0, 0 );
87         return( rc );
88 }