]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/key.c
a6b490f101cac5f2d2dcdc9f9e50987a9020face
[openldap] / servers / slapd / back-bdb / key.c
1 /* index.c - routines for dealing with attribute indexes */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2002 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 #include "idl.h"
18
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 *ids
27 )
28 {
29         int rc;
30         DBT key;
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         DBTzero( &key );
40         bv2DBT(k,&key);
41         key.ulen = key.size;
42         key.flags = DB_DBT_USERMEM;
43
44         rc = bdb_idl_fetch_key( be, db, txn, &key, ids );
45
46         if( rc != LDAP_SUCCESS ) {
47 #ifdef NEW_LOGGING
48                 LDAP_LOG(( "index", LDAP_LEVEL_ERR,
49                         "bdb_key_read: failed (%d)\n",
50                         rc ));
51 #else
52                 Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
53                         rc, 0, 0 );
54 #endif
55         } else {
56 #ifdef NEW_LOGGING
57                 LDAP_LOG(( "index", LDAP_LEVEL_DETAIL1,
58                         "bdb_key_read: %ld candidates\n", (long) BDB_IDL_N(ids) ));
59 #else
60                 Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
61                         (long) BDB_IDL_N(ids), 0, 0 );
62 #endif
63         }
64
65         return rc;
66 }
67
68 /* Add or remove stuff from index files */
69 int
70 bdb_key_change(
71         Backend *be,
72         DB *db,
73         DB_TXN *txn,
74         struct berval *k,
75         ID id,
76         int op
77 )
78 {
79         int     rc;
80         DBT     key;
81
82 #ifdef NEW_LOGGING
83         LDAP_LOG(( "index", LDAP_LEVEL_DETAIL1,
84                 "key_change: %s ID %lx\n",
85                 op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long) id ));
86 #else
87         Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
88                 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
89 #endif
90
91         DBTzero( &key );
92         bv2DBT(k,&key);
93         key.ulen = key.size;
94         key.flags = DB_DBT_USERMEM;
95
96         if (op == SLAP_INDEX_ADD_OP) {
97                 /* Add values */
98                 rc = bdb_idl_insert_key( be, db, txn, &key, id );
99
100         } else {
101                 /* Delete values */
102                 rc = bdb_idl_delete_key( be, db, txn, &key, id );
103         }
104
105 #ifdef NEW_LOGGING
106         LDAP_LOG(( "index", LDAP_LEVEL_RESULTS,
107                 "key_change: return %d\n", rc ));
108 #else
109         Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
110 #endif
111
112         return rc;
113 }