]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/key.c
Add some initial BDB_INDEX code... needs much work.
[openldap] / servers / slapd / back-bdb / 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-bdb.h"
17
18 #ifdef BDB_FILTER_INDICES
19 /* read a key */
20 int
21 bdb_key_read(
22     Backend     *be,
23         DB *db,
24         DB_TXN *txn,
25     struct berval *k,
26         ID **idout
27 )
28 {
29         Datum           key;
30         ID_BLOCK                *idl;
31
32 #ifdef NEW_LOGGING
33         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
34                    "key_read: enter\n" ));
35 #else
36         Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
37 #endif
38
39         ldbm_datum_init( key );
40         key.dptr = k->bv_val;
41         key.dsize = k->bv_len;
42
43         rc = bdb_idl_fetch_key( be, db, key, idl );
44
45 #ifdef NEW_LOGGING
46         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
47                    "key_read: %ld candidates\n",
48                    idl ? ID_BLOCK_NIDS(idl) : 0 ));
49 #else
50         Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
51                idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
52 #endif
53
54         *idout = idl;
55         return LDAP_SUCCESS;
56 }
57 #endif
58
59 #ifdef BDB_INDEX
60 /* Add or remove stuff from index files */
61 int
62 bdb_key_change(
63     Backend *be,
64     DB *db,
65         DB_TXN *txn,
66     struct berval *k,
67     ID id,
68     int op
69 )
70 {
71         int     rc;
72         DBT     key;
73
74 #ifdef NEW_LOGGING
75         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
76                 "key_change: %s ID %lx\n",
77                 op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id ));
78 #else
79         Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
80                 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
81 #endif
82
83         DBTzero( &key );
84         key.data = k->bv_val;
85         key.size = k->bv_len;
86
87         if (op == SLAP_INDEX_ADD_OP) {
88             /* Add values */
89             rc = bdb_idl_insert_key( be, db, txn, &key, id );
90
91         } else {
92             /* Delete values */
93             rc = bdb_idl_delete_key( be, db, txn, &key, id );
94         }
95
96 #ifdef NEW_LOGGING
97         LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
98                 "key_change: return %d\n", rc ));
99 #else
100         Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
101 #endif
102
103         return rc;
104 }
105 #endif