]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/key.c
132dcc21197b8d5861e060d6e785c1cdd7b97c67
[openldap] / servers / slapd / back-mdb / 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 2000-2017 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-mdb.h"
26 #include "idl.h"
27
28 /* read a key */
29 int
30 mdb_key_read(
31         Backend *be,
32         MDB_txn *txn,
33         MDB_dbi dbi,
34         struct berval *k,
35         ID *ids,
36         MDB_cursor **saved_cursor,
37         int get_flag
38 )
39 {
40         int rc;
41         MDB_val key;
42 #ifndef MISALIGNED_OK
43         int kbuf[2];
44 #endif
45
46         Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
47
48 #ifndef MISALIGNED_OK
49         if (k->bv_len & ALIGNER) {
50                 key.mv_size = sizeof(kbuf);
51                 key.mv_data = kbuf;
52                 kbuf[1] = 0;
53                 memcpy(kbuf, k->bv_val, k->bv_len);
54         } else
55 #endif
56         {
57                 key.mv_size = k->bv_len;
58                 key.mv_data = k->bv_val;
59         }
60
61         rc = mdb_idl_fetch_key( be, txn, dbi, &key, ids, saved_cursor, get_flag );
62
63         if( rc != LDAP_SUCCESS ) {
64                 Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read: failed (%d)\n",
65                         rc, 0, 0 );
66         } else {
67                 Debug( LDAP_DEBUG_TRACE, "<= mdb_index_read %ld candidates\n",
68                         (long) MDB_IDL_N(ids), 0, 0 );
69         }
70
71         return rc;
72 }