]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/back-ldbm.h
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slapd / back-ldbm / back-ldbm.h
1 /* back-ldbm.h - ldap ldbm back-end header file */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #ifndef _BACK_LDBM_H_
9 #define _BACK_LDBM_H_
10
11 #include "ldbm.h"
12
13 LDAP_BEGIN_DECL
14
15 #define DEFAULT_CACHE_SIZE      1000
16
17 #ifdef HAVE_BERKELEY_DB2
18 #       define DEFAULT_DBCACHE_SIZE (100 * DEFAULT_DB_PAGE_SIZE)
19 #else
20 #       define DEFAULT_DBCACHE_SIZE 100000
21 #endif
22
23 #define DEFAULT_DB_DIRECTORY    "/usr/tmp"
24 #define DEFAULT_MODE            0600
25
26 #define SUBLEN                  3
27
28 #define DN_BASE_PREFIX          '='
29 #define DN_ONE_PREFIX           '@'
30 #define DN_SUBTREE_PREFIX       '?'
31
32 #define SLAPD_FILTER_DN_ONE             ((ber_tag_t) -2)
33 #define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3)
34
35 /*
36  * there is a single index for each attribute.  these prefixes ensure
37  * that there is no collision among keys.
38  */
39 #define EQ_PREFIX       '='     /* prefix for equality keys     */
40 #define APPROX_PREFIX   '~'     /* prefix for approx keys       */
41 #define SUB_PREFIX      '*'     /* prefix for substring keys    */
42 #define CONT_PREFIX     '\\'    /* prefix for continuation keys */
43
44 /* allow 3 characters per byte + PREFIX + EOS */
45 #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 )
46
47 #define UNKNOWN_PREFIX  '?'     /* prefix for unknown keys    */
48
49 #define DEFAULT_BLOCKSIZE       8192
50
51 /*
52  * This structure represents an id block on disk and an id list
53  * in core.
54  *
55  * The fields have the following meanings:
56  *
57  *      b_nmax  maximum number of ids in this block. if this is == ALLIDSBLOCK,
58  *              then this block represents all ids.
59  *      b_nids  current number of ids in use in this block.  if this
60  *              is == INDBLOCK, then this block is an indirect block
61  *              containing a list of other blocks containing actual ids.
62  *              the list is terminated by an id of NOID.
63  *      b_ids   a list of the actual ids themselves
64  */
65
66 typedef ID ID_BLOCK;
67
68 #define ID_BLOCK_NMAX_OFFSET    0
69 #define ID_BLOCK_NIDS_OFFSET    1
70 #define ID_BLOCK_IDS_OFFSET             2
71
72 /* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
73
74 #define ID_BLOCK_NMAX(b)                ((b)[ID_BLOCK_NMAX_OFFSET])
75 #define ID_BLOCK_NIDS(b)                ((b)[ID_BLOCK_NIDS_OFFSET])
76 #define ID_BLOCK_ID(b, n)               ((b)[ID_BLOCK_IDS_OFFSET+(n)])
77
78 #define ID_BLOCK_NOID(b, n)             (ID_BLOCK_ID((b),(n)) == NOID)
79
80 #define ID_BLOCK_ALLIDS_VALUE   0
81 #define ID_BLOCK_ALLIDS(b)              (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
82
83 #define ID_BLOCK_INDIRECT_VALUE 0
84 #define ID_BLOCK_INDIRECT(b)    (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
85
86 /* for the in-core cache of entries */
87 typedef struct ldbm_cache {
88         int             c_maxsize;
89         int             c_cursize;
90         Avlnode         *c_dntree;
91         Avlnode         *c_idtree;
92         Entry           *c_lruhead;     /* lru - add accessed entries here */
93         Entry           *c_lrutail;     /* lru - rem lru entries from here */
94         ldap_pvt_thread_mutex_t c_mutex;
95 } Cache;
96
97 #define CACHE_READ_LOCK         0
98 #define CACHE_WRITE_LOCK        1
99
100 /* for the cache of open index files */
101 typedef struct ldbm_dbcache {
102         int             dbc_refcnt;
103         int             dbc_maxids;
104         int             dbc_maxindirect;
105         time_t  dbc_lastref;
106         long    dbc_blksize;
107         char    *dbc_name;
108         LDBM    dbc_db;
109 } DBCache;
110
111 /* for the cache of attribute information (which are indexed, etc.) */
112 typedef struct ldbm_attrinfo {
113         char    *ai_type;       /* type name (cn, sn, ...)      */
114         int     ai_indexmask;   /* how the attr is indexed      */
115 #define INDEX_PRESENCE          0x0001
116 #define INDEX_EQUALITY          0x0002
117 #define INDEX_APPROX            0x0004
118 #define INDEX_SUB                       0x0008
119 #define INDEX_UNKNOWN           0x0010
120 #define INDEX_FROMINIT          0x1000
121         int     ai_syntaxmask;  /* what kind of syntax          */
122 /* ...from slap.h...
123 #define SYNTAX_CIS      0x01
124 #define SYNTAX_CES      0x02
125 #define SYNTAX_BIN      0x04
126    ... etc. ...
127 */
128 } AttrInfo;
129
130 #define MAXDBCACHE      16
131
132 struct ldbminfo {
133         ID                      li_nextid;
134         ldap_pvt_thread_mutex_t         li_nextid_mutex;
135         ldap_pvt_thread_mutex_t         li_root_mutex;
136         ldap_pvt_thread_mutex_t         li_add_mutex;
137         int                     li_mode;
138         char                    *li_directory;
139         Cache           li_cache;
140         Avlnode                 *li_attrs;
141         int                     li_dbcachesize;
142         int                     li_dbcachewsync;
143         DBCache         li_dbcache[MAXDBCACHE];
144         ldap_pvt_thread_mutex_t         li_dbcache_mutex;
145         ldap_pvt_thread_cond_t          li_dbcache_cv;
146 #ifdef HAVE_BERKELEY_DB2
147         DB_ENV                      li_db_env;
148 #endif
149 };
150
151 LDAP_END_DECL
152
153 #include "proto-back-ldbm.h"
154
155 #endif /* _back_ldbm_h_ */