| 1 |
/* idl.h - ldap mdb back-end ID list header file */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2000-2024 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 |
#ifndef _MDB_IDL_H_ |
| 18 |
#define _MDB_IDL_H_ |
| 19 |
|
| 20 |
/* IDL sizes - likely should be even bigger |
| 21 |
* limiting factors: sizeof(ID), thread stack size |
| 22 |
*/ |
| 23 |
#define MDB_IDL_LOGN 16 /* DB_SIZE is 2^16, UM_SIZE is 2^17 */ |
| 24 |
extern unsigned int MDB_idl_logn; |
| 25 |
extern unsigned int MDB_idl_db_size; |
| 26 |
extern unsigned int MDB_idl_um_size; |
| 27 |
extern unsigned int MDB_idl_db_max; |
| 28 |
extern unsigned int MDB_idl_um_max; |
| 29 |
|
| 30 |
#define MDB_IDL_IS_RANGE(ids) ((ids)[0] == NOID) |
| 31 |
#define MDB_IDL_RANGE_SIZE (3) |
| 32 |
#define MDB_IDL_RANGE_SIZEOF (MDB_IDL_RANGE_SIZE * sizeof(ID)) |
| 33 |
#define MDB_IDL_SIZEOF(ids) ((MDB_IDL_IS_RANGE(ids) \ |
| 34 |
? MDB_IDL_RANGE_SIZE : ((ids)[0]+1)) * sizeof(ID)) |
| 35 |
|
| 36 |
#define MDB_IDL_RANGE_FIRST(ids) ((ids)[1]) |
| 37 |
#define MDB_IDL_RANGE_LAST(ids) ((ids)[2]) |
| 38 |
|
| 39 |
#define MDB_IDL_RANGE( ids, f, l ) \ |
| 40 |
do { \ |
| 41 |
(ids)[0] = NOID; \ |
| 42 |
(ids)[1] = (f); \ |
| 43 |
(ids)[2] = (l); \ |
| 44 |
} while(0) |
| 45 |
|
| 46 |
#define MDB_IDL_ZERO(ids) \ |
| 47 |
do { \ |
| 48 |
(ids)[0] = 0; \ |
| 49 |
(ids)[1] = 0; \ |
| 50 |
(ids)[2] = 0; \ |
| 51 |
} while(0) |
| 52 |
|
| 53 |
#define MDB_IDL_IS_ZERO(ids) ( (ids)[0] == 0 ) |
| 54 |
#define MDB_IDL_IS_ALL( range, ids ) ( (ids)[0] == NOID \ |
| 55 |
&& (ids)[1] <= (range)[1] && (range)[2] <= (ids)[2] ) |
| 56 |
|
| 57 |
#define MDB_IDL_CPY( dst, src ) (AC_MEMCPY( dst, src, MDB_IDL_SIZEOF( src ) )) |
| 58 |
|
| 59 |
#define MDB_IDL_ID( mdb, ids, id ) MDB_IDL_RANGE( ids, id, NOID ) |
| 60 |
#define MDB_IDL_ALL( ids ) MDB_IDL_RANGE( ids, 1, NOID ) |
| 61 |
|
| 62 |
#define MDB_IDL_FIRST( ids ) ( (ids)[1] ) |
| 63 |
#define MDB_IDL_LLAST( ids ) ( (ids)[(ids)[0]] ) |
| 64 |
#define MDB_IDL_LAST( ids ) ( MDB_IDL_IS_RANGE(ids) \ |
| 65 |
? (ids)[2] : (ids)[(ids)[0]] ) |
| 66 |
|
| 67 |
#define MDB_IDL_N( ids ) ( MDB_IDL_IS_RANGE(ids) \ |
| 68 |
? ((ids)[2]-(ids)[1])+1 : (ids)[0] ) |
| 69 |
|
| 70 |
/** An ID2 is an ID/value pair. |
| 71 |
*/ |
| 72 |
typedef struct ID2 { |
| 73 |
ID mid; /**< The ID */ |
| 74 |
MDB_val mval; /**< The value */ |
| 75 |
} ID2; |
| 76 |
|
| 77 |
/** An ID2L is an ID2 List, a sorted array of ID2s. |
| 78 |
* The first element's \b mid member is a count of how many actual |
| 79 |
* elements are in the array. The \b mptr member of the first element is unused. |
| 80 |
* The array is sorted in ascending order by \b mid. |
| 81 |
*/ |
| 82 |
typedef ID2 *ID2L; |
| 83 |
|
| 84 |
typedef struct IdScopes { |
| 85 |
MDB_txn *mt; |
| 86 |
MDB_cursor *mc; |
| 87 |
ID id; |
| 88 |
ID2L scopes; |
| 89 |
ID2L sctmp; |
| 90 |
int numrdns; |
| 91 |
int nscope; |
| 92 |
int oscope; |
| 93 |
struct berval rdns[MAXRDNS]; |
| 94 |
struct berval nrdns[MAXRDNS]; |
| 95 |
} IdScopes; |
| 96 |
|
| 97 |
LDAP_BEGIN_DECL |
| 98 |
/** Reset IDL params after changing logn */ |
| 99 |
void mdb_idl_reset(); |
| 100 |
|
| 101 |
|
| 102 |
/** Search for an ID in an ID2L. |
| 103 |
* @param[in] ids The ID2L to search. |
| 104 |
* @param[in] id The ID to search for. |
| 105 |
* @return The index of the first ID2 whose \b mid member is greater than or equal to \b id. |
| 106 |
*/ |
| 107 |
unsigned mdb_id2l_search( ID2L ids, ID id ); |
| 108 |
|
| 109 |
|
| 110 |
/** Insert an ID2 into a ID2L. |
| 111 |
* @param[in,out] ids The ID2L to insert into. |
| 112 |
* @param[in] id The ID2 to insert. |
| 113 |
* @return 0 on success, -1 if the ID was already present in the MIDL2. |
| 114 |
*/ |
| 115 |
int mdb_id2l_insert( ID2L ids, ID2 *id ); |
| 116 |
LDAP_END_DECL |
| 117 |
|
| 118 |
#endif |