]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/key.c
Fix IRIX sc_mask conflict
[openldap] / servers / slapd / back-ldbm / 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-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, ENTRY, "key_read: enter\n", 0, 0, 0 );
32 #else
33         Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
34 #endif
35
36
37         ldbm_datum_init( key );
38         key.dptr = k->bv_val;
39         key.dsize = k->bv_len;
40
41         idl = idl_fetch( be, db, key );
42
43 #ifdef NEW_LOGGING
44         LDAP_LOG( INDEX, ENTRY, 
45                    "key_read: %ld candidates\n", idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
46 #else
47         Debug( LDAP_DEBUG_TRACE, "<= index_read %ld candidates\n",
48                idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
49 #endif
50
51
52         *idout = idl;
53         return LDAP_SUCCESS;
54 }
55
56 /* Add or remove stuff from index files */
57 int
58 key_change(
59     Backend             *be,
60     DBCache     *db,
61     struct berval *k,
62     ID                  id,
63     int                 op
64 )
65 {
66         int     rc;
67         Datum   key;
68
69 #ifdef NEW_LOGGING
70         LDAP_LOG( INDEX, ENTRY, "key_change: %s ID %lx\n",
71                    op == SLAP_INDEX_ADD_OP ? "Add" : "Delete", (long)id, 0 );
72 #else
73         Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
74                 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
75 #endif
76
77
78         ldbm_datum_init( key );
79         key.dptr = k->bv_val;
80         key.dsize = k->bv_len;
81
82         ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
83         if (op == SLAP_INDEX_ADD_OP) {
84             /* Add values */
85             rc = idl_insert_key( be, db, key, id );
86
87         } else {
88             /* Delete values */
89             rc = idl_delete_key( be, db, key, id );
90         }
91         ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
92
93
94 #ifdef NEW_LOGGING
95         LDAP_LOG( INDEX, ENTRY, "key_change: return %d\n", rc, 0, 0 );
96 #else
97         Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
98 #endif
99
100
101         ldap_pvt_thread_yield();
102
103         return rc;
104 }