]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/key.c
Happy new year
[openldap] / servers / slapd / back-ldbm / key.c
1 /* index.c - routines for dealing with attribute indexes */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2004 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16
17 #include "portable.h"
18
19 #include <stdio.h>
20
21 #include <ac/string.h>
22 #include <ac/socket.h>
23
24 #include "slap.h"
25 #include "back-ldbm.h"
26
27 /* read a key */
28 int
29 key_read(
30     Backend     *be,
31         DBCache *db,
32     struct berval *k,
33         ID_BLOCK **idout
34 )
35 {
36         Datum           key;
37         ID_BLOCK                *idl;
38
39 #ifdef NEW_LOGGING
40         LDAP_LOG( INDEX, ENTRY, "key_read: enter\n", 0, 0, 0 );
41 #else
42         Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
43 #endif
44
45
46         ldbm_datum_init( key );
47         key.dptr = k->bv_val;
48         key.dsize = k->bv_len;
49
50         idl = idl_fetch( be, db, key );
51
52 #ifdef NEW_LOGGING
53         LDAP_LOG( INDEX, ENTRY, 
54                    "key_read: %ld candidates\n", idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
55 #else
56         Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
57                idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
58 #endif
59
60
61         *idout = idl;
62         return LDAP_SUCCESS;
63 }
64
65 /* Add or remove stuff from index files */
66 int
67 key_change(
68     Backend             *be,
69     DBCache     *db,
70     struct berval *k,
71     ID                  id,
72     int                 op
73 )
74 {
75         int     rc;
76         Datum   key;
77
78 #ifdef NEW_LOGGING
79         LDAP_LOG( INDEX, ENTRY, "key_change: %s ID %lx\n",
80                    op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id, 0 );
81 #else
82         Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
83                 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
84 #endif
85
86
87         ldbm_datum_init( key );
88         key.dptr = k->bv_val;
89         key.dsize = k->bv_len;
90
91         ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
92         if (op == SLAP_INDEX_ADD_OP) {
93             /* Add values */
94             rc = idl_insert_key( be, db, key, id );
95
96         } else {
97             /* Delete values */
98             rc = idl_delete_key( be, db, key, id );
99         }
100         ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
101
102
103 #ifdef NEW_LOGGING
104         LDAP_LOG( INDEX, ENTRY, "key_change: return %d\n", rc, 0, 0 );
105 #else
106         Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
107 #endif
108
109
110         ldap_pvt_thread_yield();
111
112         return rc;
113 }