Back to index

openldap  2.4.31
key.c
Go to the documentation of this file.
00001 /* index.c - routines for dealing with attribute indexes */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2000-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 
00017 #include "portable.h"
00018 
00019 #include <stdio.h>
00020 
00021 #include <ac/string.h>
00022 #include <ac/socket.h>
00023 
00024 #include "slap.h"
00025 #include "back-bdb.h"
00026 #include "idl.h"
00027 
00028 /* read a key */
00029 int
00030 bdb_key_read(
00031        Backend       *be,
00032        DB *db,
00033        DB_TXN *txn,
00034        struct berval *k,
00035        ID *ids,
00036        DBC **saved_cursor,
00037        int get_flag
00038 )
00039 {
00040        int rc;
00041        DBT key;
00042 
00043        Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
00044 
00045        DBTzero( &key );
00046        bv2DBT(k,&key);
00047        key.ulen = key.size;
00048        key.flags = DB_DBT_USERMEM;
00049 
00050        rc = bdb_idl_fetch_key( be, db, txn, &key, ids, saved_cursor, get_flag );
00051 
00052        if( rc != LDAP_SUCCESS ) {
00053               Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
00054                      rc, 0, 0 );
00055        } else {
00056               Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
00057                      (long) BDB_IDL_N(ids), 0, 0 );
00058        }
00059 
00060        return rc;
00061 }
00062 
00063 /* Add or remove stuff from index files */
00064 int
00065 bdb_key_change(
00066        Backend *be,
00067        DB *db,
00068        DB_TXN *txn,
00069        struct berval *k,
00070        ID id,
00071        int op
00072 )
00073 {
00074        int    rc;
00075        DBT    key;
00076 
00077        Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
00078               op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
00079 
00080        DBTzero( &key );
00081        bv2DBT(k,&key);
00082        key.ulen = key.size;
00083        key.flags = DB_DBT_USERMEM;
00084 
00085        if (op == SLAP_INDEX_ADD_OP) {
00086               /* Add values */
00087 
00088 #ifdef BDB_TOOL_IDL_CACHING
00089               if ( slapMode & SLAP_TOOL_QUICK )
00090                      rc = bdb_tool_idl_add( be, db, txn, &key, id );
00091               else
00092 #endif
00093                      rc = bdb_idl_insert_key( be, db, txn, &key, id );
00094               if ( rc == DB_KEYEXIST ) rc = 0;
00095        } else {
00096               /* Delete values */
00097               rc = bdb_idl_delete_key( be, db, txn, &key, id );
00098               if ( rc == DB_NOTFOUND ) rc = 0;
00099        }
00100 
00101        Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
00102 
00103        return rc;
00104 }