Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-bdb / key.c
blob9f5de3bfba72cce40be51a4d4b85cda6ff1eacfa
1 /* index.c - routines for dealing with attribute indexes */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-bdb/key.c,v 1.20.2.3 2008/02/11 23:26:46 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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>.
17 #include "portable.h"
19 #include <stdio.h>
21 #include <ac/string.h>
22 #include <ac/socket.h>
24 #include "slap.h"
25 #include "back-bdb.h"
26 #include "idl.h"
28 /* read a key */
29 int
30 bdb_key_read(
31 Backend *be,
32 DB *db,
33 BDB_LOCKER locker,
34 struct berval *k,
35 ID *ids,
36 DBC **saved_cursor,
37 int get_flag
40 int rc;
41 DBT key;
43 Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
45 DBTzero( &key );
46 bv2DBT(k,&key);
47 key.ulen = key.size;
48 key.flags = DB_DBT_USERMEM;
50 rc = bdb_idl_fetch_key( be, db, locker, &key, ids, saved_cursor, get_flag );
52 if( rc != LDAP_SUCCESS ) {
53 Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
54 rc, 0, 0 );
55 } else {
56 Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
57 (long) BDB_IDL_N(ids), 0, 0 );
60 return rc;
63 /* Add or remove stuff from index files */
64 int
65 bdb_key_change(
66 Backend *be,
67 DB *db,
68 DB_TXN *txn,
69 struct berval *k,
70 ID id,
71 int op
74 int rc;
75 DBT key;
77 Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
78 op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
80 DBTzero( &key );
81 bv2DBT(k,&key);
82 key.ulen = key.size;
83 key.flags = DB_DBT_USERMEM;
85 if (op == SLAP_INDEX_ADD_OP) {
86 /* Add values */
88 #ifdef BDB_TOOL_IDL_CACHING
89 if ( slapMode & SLAP_TOOL_QUICK )
90 rc = bdb_tool_idl_add( be, db, txn, &key, id );
91 else
92 #endif
93 rc = bdb_idl_insert_key( be, db, txn, &key, id );
94 if ( rc == DB_KEYEXIST ) rc = 0;
95 } else {
96 /* Delete values */
97 rc = bdb_idl_delete_key( be, db, txn, &key, id );
98 if ( rc == DB_NOTFOUND ) rc = 0;
101 Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
103 return rc;