]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/key.c
Added bdb_attribute and bdb_group ACL support routines
[openldap] / servers / slapd / back-ldbm / key.c
1 /* index.c - routines for dealing with attribute indexes */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17
18 /* read a key */
19 int
20 key_read(
21     Backend     *be,
22         DBCache *db,
23     struct berval *k,
24         ID_BLOCK **idout
25 )
26 {
27         Datum           key;
28         ID_BLOCK                *idl;
29
30 #ifdef NEW_LOGGING
31         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
32                    "key_read: enter\n" ));
33 #else
34         Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
35 #endif
36
37
38         ldbm_datum_init( key );
39         key.dptr = k->bv_val;
40         key.dsize = k->bv_len;
41
42         idl = idl_fetch( be, db, key );
43
44 #ifdef NEW_LOGGING
45         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
46                    "key_read: %ld candidates\n",
47                    idl ? ID_BLOCK_NIDS(idl) : 0 ));
48 #else
49         Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
50                idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
51 #endif
52
53
54         *idout = idl;
55         return LDAP_SUCCESS;
56 }
57
58 /* Add or remove stuff from index files */
59 int
60 key_change(
61     Backend             *be,
62     DBCache     *db,
63     struct berval *k,
64     ID                  id,
65     int                 op
66 )
67 {
68         int     rc;
69         Datum   key;
70
71 #ifdef NEW_LOGGING
72         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
73                    "key_change: %s ID %lx\n",
74                    op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id ));
75 #else
76         Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
77                 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
78 #endif
79
80
81         ldbm_datum_init( key );
82         key.dptr = k->bv_val;
83         key.dsize = k->bv_len;
84
85         ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
86         if (op == SLAP_INDEX_ADD_OP) {
87             /* Add values */
88             rc = idl_insert_key( be, db, key, id );
89
90         } else {
91             /* Delete values */
92             rc = idl_delete_key( be, db, key, id );
93         }
94         ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
95
96
97 #ifdef NEW_LOGGING
98         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
99                    "key_change: return %d\n", rc ));
100 #else
101         Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
102 #endif
103
104
105         ldap_pvt_thread_yield();
106
107         return rc;
108 }