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-mdb.h"
00026 #include "idl.h"
00027 
00028 /* read a key */
00029 int
00030 mdb_key_read(
00031        Backend       *be,
00032        MDB_txn *txn,
00033        MDB_dbi dbi,
00034        struct berval *k,
00035        ID *ids,
00036        MDB_cursor **saved_cursor,
00037        int get_flag
00038 )
00039 {
00040        int rc;
00041        MDB_val key;
00042 #ifndef MISALIGNED_OK
00043        int kbuf[2];
00044 #endif
00045 
00046        Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
00047 
00048 #ifndef MISALIGNED_OK
00049        if (k->bv_len & ALIGNER) {
00050               key.mv_size = sizeof(kbuf);
00051               key.mv_data = kbuf;
00052               kbuf[1] = 0;
00053               memcpy(kbuf, k->bv_val, k->bv_len);
00054        } else
00055 #endif
00056        {
00057               key.mv_size = k->bv_len;
00058               key.mv_data = k->bv_val;
00059        }
00060 
00061        rc = mdb_idl_fetch_key( be, txn, dbi, &key, ids, saved_cursor, get_flag );
00062 
00063        if( rc != LDAP_SUCCESS ) {
00064               Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read: failed (%d)\n",
00065                      rc, 0, 0 );
00066        } else {
00067               Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read %ld candidates\n",
00068                      (long) MDB_IDL_N(ids), 0, 0 );
00069        }
00070 
00071        return rc;
00072 }