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