| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "OPENSSL_LH_COMPFUNC 3SSL" |
| 58 |
.TH OPENSSL_LH_COMPFUNC 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
LHASH, LHASH_OF, DEFINE_LHASH_OF_EX, DEFINE_LHASH_OF, |
| 65 |
OPENSSL_LH_COMPFUNC, OPENSSL_LH_HASHFUNC, OPENSSL_LH_DOALL_FUNC, |
| 66 |
LHASH_DOALL_ARG_FN_TYPE, |
| 67 |
IMPLEMENT_LHASH_HASH_FN, IMPLEMENT_LHASH_COMP_FN, |
| 68 |
lh_TYPE_new, lh_TYPE_free, lh_TYPE_flush, |
| 69 |
lh_TYPE_insert, lh_TYPE_delete, lh_TYPE_retrieve, |
| 70 |
lh_TYPE_doall, lh_TYPE_doall_arg, lh_TYPE_num_items, lh_TYPE_get_down_load, |
| 71 |
lh_TYPE_set_down_load, lh_TYPE_error, |
| 72 |
OPENSSL_LH_new, OPENSSL_LH_free, OPENSSL_LH_flush, |
| 73 |
OPENSSL_LH_insert, OPENSSL_LH_delete, OPENSSL_LH_retrieve, |
| 74 |
OPENSSL_LH_doall, OPENSSL_LH_doall_arg, OPENSSL_LH_doall_arg_thunk, |
| 75 |
OPENSSL_LH_set_thunks, OPENSSL_LH_num_items, |
| 76 |
OPENSSL_LH_get_down_load, OPENSSL_LH_set_down_load, OPENSSL_LH_error |
| 77 |
\&\- dynamic hash table |
| 78 |
.SH SYNOPSIS |
| 79 |
.IX Header "SYNOPSIS" |
| 80 |
.Vb 1 |
| 81 |
\& #include <openssl/lhash.h> |
| 82 |
\& |
| 83 |
\& LHASH_OF(TYPE) |
| 84 |
\& |
| 85 |
\& DEFINE_LHASH_OF_EX(TYPE); |
| 86 |
\& |
| 87 |
\& LHASH_OF(TYPE) *lh_TYPE_new(OPENSSL_LH_HASHFUNC hash, OPENSSL_LH_COMPFUNC compare); |
| 88 |
\& void lh_TYPE_free(LHASH_OF(TYPE) *table); |
| 89 |
\& void lh_TYPE_flush(LHASH_OF(TYPE) *table); |
| 90 |
\& OPENSSL_LHASH *OPENSSL_LH_set_thunks(OPENSSL_LHASH *lh, |
| 91 |
\& OPENSSL_LH_HASHFUNCTHUNK hw, |
| 92 |
\& OPENSSL_LH_COMPFUNCTHUNK cw, |
| 93 |
\& OPENSSL_LH_DOALL_FUNC_THUNK daw, |
| 94 |
\& OPENSSL_LH_DOALL_FUNCARG_THUNK daaw) |
| 95 |
\& |
| 96 |
\& TYPE *lh_TYPE_insert(LHASH_OF(TYPE) *table, TYPE *data); |
| 97 |
\& TYPE *lh_TYPE_delete(LHASH_OF(TYPE) *table, TYPE *data); |
| 98 |
\& TYPE *lh_TYPE_retrieve(LHASH_OF(TYPE) *table, TYPE *data); |
| 99 |
\& |
| 100 |
\& void lh_TYPE_doall(LHASH_OF(TYPE) *table, OPENSSL_LH_DOALL_FUNC func); |
| 101 |
\& void lh_TYPE_doall_arg(LHASH_OF(TYPE) *table, OPENSSL_LH_DOALL_FUNCARG func, |
| 102 |
\& TYPE *arg); |
| 103 |
\& void OPENSSL_LH_doall_arg_thunk(OPENSSL_LHASH *lh, |
| 104 |
\& OPENSSL_LH_DOALL_FUNCARG_THUNK daaw, |
| 105 |
\& OPENSSL_LH_DOALL_FUNCARG fn, void *arg) |
| 106 |
\& |
| 107 |
\& unsigned long lh_TYPE_num_items(OPENSSL_LHASH *lh); |
| 108 |
\& unsigned long lh_TYPE_get_down_load(OPENSSL_LHASH *lh); |
| 109 |
\& void lh_TYPE_set_down_load(OPENSSL_LHASH *lh, unsigned long dl); |
| 110 |
\& |
| 111 |
\& int lh_TYPE_error(LHASH_OF(TYPE) *table); |
| 112 |
\& |
| 113 |
\& typedef int (*OPENSSL_LH_COMPFUNC)(const void *, const void *); |
| 114 |
\& typedef unsigned long (*OPENSSL_LH_HASHFUNC)(const void *); |
| 115 |
\& typedef void (*OPENSSL_LH_DOALL_FUNC)(const void *); |
| 116 |
\& typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, const void *); |
| 117 |
\& |
| 118 |
\& OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c); |
| 119 |
\& void OPENSSL_LH_free(OPENSSL_LHASH *lh); |
| 120 |
\& void OPENSSL_LH_flush(OPENSSL_LHASH *lh); |
| 121 |
\& |
| 122 |
\& void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data); |
| 123 |
\& void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data); |
| 124 |
\& void *OPENSSL_LH_retrieve(OPENSSL_LHASH *lh, const void *data); |
| 125 |
\& |
| 126 |
\& void OPENSSL_LH_doall(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNC func); |
| 127 |
\& void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg); |
| 128 |
\& |
| 129 |
\& unsigned long OPENSSL_LH_num_items(OPENSSL_LHASH *lh); |
| 130 |
\& unsigned long OPENSSL_LH_get_down_load(OPENSSL_LHASH *lh); |
| 131 |
\& void OPENSSL_LH_set_down_load(OPENSSL_LHASH *lh, unsigned long dl); |
| 132 |
\& |
| 133 |
\& int OPENSSL_LH_error(OPENSSL_LHASH *lh); |
| 134 |
\& |
| 135 |
\& #define LH_LOAD_MULT /* integer constant */ |
| 136 |
.Ve |
| 137 |
.PP |
| 138 |
The following macro is deprecated: |
| 139 |
.PP |
| 140 |
.Vb 1 |
| 141 |
\& DEFINE_LHASH_OF(TYPE); |
| 142 |
.Ve |
| 143 |
.SH DESCRIPTION |
| 144 |
.IX Header "DESCRIPTION" |
| 145 |
This library implements type-checked dynamic hash tables. The hash |
| 146 |
table entries can be arbitrary structures. Usually they consist of key |
| 147 |
and value fields. In the description here, \fR\f(BITYPE\fR\fB\fR is used a placeholder |
| 148 |
for any of the OpenSSL datatypes, such as \fISSL_SESSION\fR. |
| 149 |
.PP |
| 150 |
To define a new type-checked dynamic hash table, use \fBDEFINE_LHASH_OF_EX\fR(). |
| 151 |
\&\fBDEFINE_LHASH_OF\fR() was previously used for this purpose, but is now |
| 152 |
deprecated. The \fBDEFINE_LHASH_OF_EX\fR() macro provides all functionality of |
| 153 |
\&\fBDEFINE_LHASH_OF\fR() except for certain deprecated statistics functions (see |
| 154 |
\&\fBOPENSSL_LH_stats\fR\|(3)). |
| 155 |
.PP |
| 156 |
\&\fBlh_\fR\f(BITYPE\fR\fB_new\fR() creates a new \fBLHASH_OF\fR(\fR\f(BITYPE\fR\fB\fR) structure to store |
| 157 |
arbitrary data entries, and specifies the 'hash' and 'compare' |
| 158 |
callbacks to be used in organising the table's entries. The \fIhash\fR |
| 159 |
callback takes a pointer to a table entry as its argument and returns |
| 160 |
an unsigned long hash value for its key field. The hash value is |
| 161 |
normally truncated to a power of 2, so make sure that your hash |
| 162 |
function returns well mixed low order bits. The \fIcompare\fR callback |
| 163 |
takes two arguments (pointers to two hash table entries), and returns |
| 164 |
0 if their keys are equal, nonzero otherwise. |
| 165 |
.PP |
| 166 |
If your hash table |
| 167 |
will contain items of some particular type and the \fIhash\fR and |
| 168 |
\&\fIcompare\fR callbacks hash/compare these types, then the |
| 169 |
\&\fBIMPLEMENT_LHASH_HASH_FN\fR and \fBIMPLEMENT_LHASH_COMP_FN\fR macros can be |
| 170 |
used to create callback wrappers of the prototypes required by |
| 171 |
\&\fBlh_\fR\f(BITYPE\fR\fB_new\fR() as shown in this example: |
| 172 |
.PP |
| 173 |
.Vb 11 |
| 174 |
\& /* |
| 175 |
\& * Implement the hash and compare functions; "stuff" can be any word. |
| 176 |
\& */ |
| 177 |
\& static unsigned long stuff_hash(const TYPE *a) |
| 178 |
\& { |
| 179 |
\& ... |
| 180 |
\& } |
| 181 |
\& static int stuff_cmp(const TYPE *a, const TYPE *b) |
| 182 |
\& { |
| 183 |
\& ... |
| 184 |
\& } |
| 185 |
\& |
| 186 |
\& /* |
| 187 |
\& * Implement the wrapper functions. |
| 188 |
\& */ |
| 189 |
\& static IMPLEMENT_LHASH_HASH_FN(stuff, TYPE) |
| 190 |
\& static IMPLEMENT_LHASH_COMP_FN(stuff, TYPE) |
| 191 |
.Ve |
| 192 |
.PP |
| 193 |
If the type is going to be used in several places, the following macros |
| 194 |
can be used in a common header file to declare the function wrappers: |
| 195 |
.PP |
| 196 |
.Vb 2 |
| 197 |
\& DECLARE_LHASH_HASH_FN(stuff, TYPE) |
| 198 |
\& DECLARE_LHASH_COMP_FN(stuff, TYPE) |
| 199 |
.Ve |
| 200 |
.PP |
| 201 |
Then a hash table of \fR\f(BITYPE\fR\fB\fR objects can be created using this: |
| 202 |
.PP |
| 203 |
.Vb 1 |
| 204 |
\& LHASH_OF(TYPE) *htable; |
| 205 |
\& |
| 206 |
\& htable = B<lh_I<TYPE>_new>(LHASH_HASH_FN(stuff), LHASH_COMP_FN(stuff)); |
| 207 |
.Ve |
| 208 |
.PP |
| 209 |
\&\fBlh_\fR\f(BITYPE\fR\fB_free\fR() frees the \fBLHASH_OF\fR(\fR\f(BITYPE\fR\fB\fR) structure |
| 210 |
\&\fItable\fR. Allocated hash table entries will not be freed; consider |
| 211 |
using \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() to deallocate any remaining entries in the |
| 212 |
hash table (see below). If the argument is NULL, nothing is done. |
| 213 |
.PP |
| 214 |
\&\fBlh_\fR\f(BITYPE\fR\fB_flush\fR() empties the \fBLHASH_OF\fR(\fR\f(BITYPE\fR\fB\fR) structure \fItable\fR. New |
| 215 |
entries can be added to the flushed table. Allocated hash table entries |
| 216 |
will not be freed; consider using \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() to deallocate any |
| 217 |
remaining entries in the hash table (see below). |
| 218 |
.PP |
| 219 |
\&\fBlh_\fR\f(BITYPE\fR\fB_insert\fR() inserts the structure pointed to by \fIdata\fR into |
| 220 |
\&\fItable\fR. If there already is an entry with the same key, the old |
| 221 |
value is replaced. Note that \fBlh_\fR\f(BITYPE\fR\fB_insert\fR() stores pointers, the |
| 222 |
data are not copied. |
| 223 |
.PP |
| 224 |
\&\fBlh_\fR\f(BITYPE\fR\fB_delete\fR() deletes an entry from \fItable\fR. |
| 225 |
.PP |
| 226 |
\&\fBlh_\fR\f(BITYPE\fR\fB_retrieve\fR() looks up an entry in \fItable\fR. Normally, \fIdata\fR |
| 227 |
is a structure with the key field(s) set; the function will return a |
| 228 |
pointer to a fully populated structure. |
| 229 |
.PP |
| 230 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall\fR() will, for every entry in the hash table, call |
| 231 |
\&\fIfunc\fR with the data item as its parameter. |
| 232 |
For example: |
| 233 |
.PP |
| 234 |
.Vb 2 |
| 235 |
\& /* Cleans up resources belonging to \*(Aqa\*(Aq (this is implemented elsewhere) */ |
| 236 |
\& void TYPE_cleanup_doall(TYPE *a); |
| 237 |
\& |
| 238 |
\& /* Implement a prototype\-compatible wrapper for "TYPE_cleanup" */ |
| 239 |
\& IMPLEMENT_LHASH_DOALL_FN(TYPE_cleanup, TYPE) |
| 240 |
\& |
| 241 |
\& /* Call "TYPE_cleanup" against all items in a hash table. */ |
| 242 |
\& lh_TYPE_doall(hashtable, LHASH_DOALL_FN(TYPE_cleanup)); |
| 243 |
\& |
| 244 |
\& /* Then the hash table itself can be deallocated */ |
| 245 |
\& lh_TYPE_free(hashtable); |
| 246 |
.Ve |
| 247 |
.PP |
| 248 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR() is the same as \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() except that |
| 249 |
\&\fIfunc\fR will be called with \fIarg\fR as the second argument and \fIfunc\fR |
| 250 |
should be of type \fBLHASH_DOALL_ARG_FN\fR(\fR\f(BITYPE\fR\fB\fR) (a callback prototype |
| 251 |
that is passed both the table entry and an extra argument). As with |
| 252 |
\&\fBlh_doall()\fR, you can instead choose to declare your callback with a |
| 253 |
prototype matching the types you are dealing with and use the |
| 254 |
declare/implement macros to create compatible wrappers that cast |
| 255 |
variables before calling your type-specific callbacks. An example of |
| 256 |
this is demonstrated here (printing all hash table entries to a BIO |
| 257 |
that is provided by the caller): |
| 258 |
.PP |
| 259 |
.Vb 2 |
| 260 |
\& /* Prints item \*(Aqa\*(Aq to \*(Aqoutput_bio\*(Aq (this is implemented elsewhere) */ |
| 261 |
\& void TYPE_print_doall_arg(const TYPE *a, BIO *output_bio); |
| 262 |
\& |
| 263 |
\& /* Implement a prototype\-compatible wrapper for "TYPE_print" */ |
| 264 |
\& static IMPLEMENT_LHASH_DOALL_ARG_FN(TYPE, const TYPE, BIO) |
| 265 |
\& |
| 266 |
\& /* Print out the entire hashtable to a particular BIO */ |
| 267 |
\& lh_TYPE_doall_arg(hashtable, LHASH_DOALL_ARG_FN(TYPE_print), BIO, |
| 268 |
\& logging_bio); |
| 269 |
.Ve |
| 270 |
.PP |
| 271 |
Note that it is by default \fBnot\fR safe to use \fBlh_\fR\f(BITYPE\fR\fB_delete\fR() inside a |
| 272 |
callback passed to \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() or \fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR(). The |
| 273 |
reason for this is that deleting an item from the hash table may result in the |
| 274 |
hash table being contracted to a smaller size and rehashed. |
| 275 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall\fR() and \fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR() are unsafe and will exhibit |
| 276 |
undefined behaviour under these conditions, as these functions assume the hash |
| 277 |
table size and bucket pointers do not change during the call. |
| 278 |
.PP |
| 279 |
If it is desired to use \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() or \fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR() with |
| 280 |
\&\fBlh_\fR\f(BITYPE\fR\fB_delete\fR(), it is essential that you call |
| 281 |
\&\fBlh_\fR\f(BITYPE\fR\fB_set_down_load\fR() with a \fIdown_load\fR argument of 0 first. This |
| 282 |
disables hash table contraction and guarantees that it will be safe to delete |
| 283 |
items from a hash table during a call to \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() or |
| 284 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR(). |
| 285 |
.PP |
| 286 |
It is never safe to call \fBlh_\fR\f(BITYPE\fR\fB_insert\fR() during a call to |
| 287 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall\fR() or \fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR(). |
| 288 |
.PP |
| 289 |
\&\fBlh_\fR\f(BITYPE\fR\fB_error\fR() can be used to determine if an error occurred in the last |
| 290 |
operation. |
| 291 |
.PP |
| 292 |
\&\fBlh_\fR\f(BITYPE\fR\fB_num_items\fR() returns the number of items in the hash table. |
| 293 |
.PP |
| 294 |
\&\fBlh_\fR\f(BITYPE\fR\fB_get_down_load\fR() and \fBlh_\fR\f(BITYPE\fR\fB_set_down_load\fR() get and set the |
| 295 |
factor used to determine when the hash table is contracted. The factor is the |
| 296 |
load factor at or below which hash table contraction will occur, multiplied by |
| 297 |
\&\fBLH_LOAD_MULT\fR, where the load factor is the number of items divided by the |
| 298 |
number of nodes. Setting this value to 0 disables hash table contraction. |
| 299 |
.PP |
| 300 |
\&\fBOPENSSL_LH_new()\fR is the same as the \fBlh_\fR\f(BITYPE\fR\fB_new\fR() except that it is not |
| 301 |
type specific. So instead of returning an \fBLHASH_OF(\fR\f(BITYPE\fR\fB)\fR value it returns |
| 302 |
a \fBvoid *\fR. In the same way the functions \fBOPENSSL_LH_free()\fR, |
| 303 |
\&\fBOPENSSL_LH_flush()\fR, \fBOPENSSL_LH_insert()\fR, \fBOPENSSL_LH_delete()\fR, |
| 304 |
\&\fBOPENSSL_LH_retrieve()\fR, \fBOPENSSL_LH_doall()\fR, \fBOPENSSL_LH_doall_arg()\fR, |
| 305 |
\&\fBOPENSSL_LH_num_items()\fR, \fBOPENSSL_LH_get_down_load()\fR, \fBOPENSSL_LH_set_down_load()\fR |
| 306 |
and \fBOPENSSL_LH_error()\fR are equivalent to the similarly named \fBlh_\fR\f(BITYPE\fR |
| 307 |
functions except that they return or use a \fBvoid *\fR where the equivalent |
| 308 |
\&\fBlh_\fR\f(BITYPE\fR\fB\fR function returns or uses a \fB\fR\f(BITYPE\fR\fB *\fR or \fBLHASH_OF(\fR\f(BITYPE\fR\fB) *\fR. |
| 309 |
\&\fBlh_\fR\f(BITYPE\fR\fB\fR functions are implemented as type checked wrappers around the |
| 310 |
\&\fBOPENSSL_LH\fR functions. Most applications should not call the \fBOPENSSL_LH\fR |
| 311 |
functions directly. |
| 312 |
.PP |
| 313 |
\&\fBOPENSSL_LH_set_thunks()\fR and \fBOPENSSL_LH_doall_arg_thunk()\fR, while public by |
| 314 |
necessity, are actually internal functions and should not be used. |
| 315 |
.SH "RETURN VALUES" |
| 316 |
.IX Header "RETURN VALUES" |
| 317 |
\&\fBlh_\fR\f(BITYPE\fR\fB_new\fR() and \fBOPENSSL_LH_new()\fR return NULL on error, otherwise a |
| 318 |
pointer to the new \fBLHASH\fR structure. |
| 319 |
.PP |
| 320 |
When a hash table entry is replaced, \fBlh_\fR\f(BITYPE\fR\fB_insert\fR() or |
| 321 |
\&\fBOPENSSL_LH_insert()\fR return the value being replaced. NULL is returned on normal |
| 322 |
operation and on error. |
| 323 |
.PP |
| 324 |
\&\fBlh_\fR\f(BITYPE\fR\fB_delete\fR() and \fBOPENSSL_LH_delete()\fR return the entry being deleted. |
| 325 |
NULL is returned if there is no such value in the hash table. |
| 326 |
.PP |
| 327 |
\&\fBlh_\fR\f(BITYPE\fR\fB_retrieve\fR() and \fBOPENSSL_LH_retrieve()\fR return the hash table entry |
| 328 |
if it has been found, NULL otherwise. |
| 329 |
.PP |
| 330 |
\&\fBlh_\fR\f(BITYPE\fR\fB_error\fR() and \fBOPENSSL_LH_error()\fR return 1 if an error occurred in |
| 331 |
the last operation, 0 otherwise. It's meaningful only after non-retrieve |
| 332 |
operations. |
| 333 |
.PP |
| 334 |
\&\fBlh_\fR\f(BITYPE\fR\fB_free\fR(), \fBOPENSSL_LH_free()\fR, \fBlh_\fR\f(BITYPE\fR\fB_flush\fR(), |
| 335 |
\&\fBOPENSSL_LH_flush()\fR, \fBlh_\fR\f(BITYPE\fR\fB_doall\fR() \fBOPENSSL_LH_doall()\fR, |
| 336 |
\&\fBlh_\fR\f(BITYPE\fR\fB_doall_arg\fR() and \fBOPENSSL_LH_doall_arg()\fR return no values. |
| 337 |
.SH NOTE |
| 338 |
.IX Header "NOTE" |
| 339 |
The LHASH code is not thread safe. All updating operations, as well as |
| 340 |
\&\fBlh_\fR\f(BITYPE\fR\fB_error\fR() or \fBOPENSSL_LH_error()\fR calls must be performed under |
| 341 |
a write lock. All retrieve operations should be performed under a read lock, |
| 342 |
\&\fIunless\fR accurate usage statistics are desired. In which case, a write lock |
| 343 |
should be used for retrieve operations as well. For output of the usage |
| 344 |
statistics, using the functions from \fBOPENSSL_LH_stats\fR\|(3), a read lock |
| 345 |
suffices. |
| 346 |
.PP |
| 347 |
The LHASH code regards table entries as constant data. As such, it |
| 348 |
internally represents \fBlh_insert()\fR'd items with a "const void *" |
| 349 |
pointer type. This is why callbacks such as those used by \fBlh_doall()\fR |
| 350 |
and \fBlh_doall_arg()\fR declare their prototypes with "const", even for the |
| 351 |
parameters that pass back the table items' data pointers \- for |
| 352 |
consistency, user-provided data is "const" at all times as far as the |
| 353 |
LHASH code is concerned. However, as callers are themselves providing |
| 354 |
these pointers, they can choose whether they too should be treating |
| 355 |
all such parameters as constant. |
| 356 |
.PP |
| 357 |
As an example, a hash table may be maintained by code that, for |
| 358 |
reasons of encapsulation, has only "const" access to the data being |
| 359 |
indexed in the hash table (i.e. it is returned as "const" from |
| 360 |
elsewhere in their code) \- in this case the LHASH prototypes are |
| 361 |
appropriate as-is. Conversely, if the caller is responsible for the |
| 362 |
life-time of the data in question, then they may well wish to make |
| 363 |
modifications to table item passed back in the \fBlh_doall()\fR or |
| 364 |
\&\fBlh_doall_arg()\fR callbacks (see the "TYPE_cleanup" example above). If |
| 365 |
so, the caller can either cast the "const" away (if they're providing |
| 366 |
the raw callbacks themselves) or use the macros to declare/implement |
| 367 |
the wrapper functions without "const" types. |
| 368 |
.PP |
| 369 |
Callers that only have "const" access to data they're indexing in a |
| 370 |
table, yet declare callbacks without constant types (or cast the |
| 371 |
"const" away themselves), are therefore creating their own risks/bugs |
| 372 |
without being encouraged to do so by the API. On a related note, |
| 373 |
those auditing code should pay special attention to any instances of |
| 374 |
DECLARE/IMPLEMENT_LHASH_DOALL_[ARG_]_FN macros that provide types |
| 375 |
without any "const" qualifiers. |
| 376 |
.SH BUGS |
| 377 |
.IX Header "BUGS" |
| 378 |
\&\fBlh_\fR\f(BITYPE\fR\fB_insert\fR() and \fBOPENSSL_LH_insert()\fR return NULL both for success |
| 379 |
and error. |
| 380 |
.SH "SEE ALSO" |
| 381 |
.IX Header "SEE ALSO" |
| 382 |
\&\fBOPENSSL_LH_stats\fR\|(3) |
| 383 |
.SH HISTORY |
| 384 |
.IX Header "HISTORY" |
| 385 |
In OpenSSL 1.0.0, the lhash interface was revamped for better |
| 386 |
type checking. |
| 387 |
.PP |
| 388 |
In OpenSSL 3.1, \fBDEFINE_LHASH_OF_EX\fR() was introduced and \fBDEFINE_LHASH_OF\fR() |
| 389 |
was deprecated. |
| 390 |
.PP |
| 391 |
\&\fBOPENSSL_LH_doall_arg_thunk()\fR, \fBOPENSSL_LH_set_thunks()\fR were added in |
| 392 |
OpenSSL 3.3. |
| 393 |
.SH COPYRIGHT |
| 394 |
.IX Header "COPYRIGHT" |
| 395 |
Copyright 2000\-2024 The OpenSSL Project Authors. All Rights Reserved. |
| 396 |
.PP |
| 397 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 398 |
this file except in compliance with the License. You can obtain a copy |
| 399 |
in the file LICENSE in the source distribution or at |
| 400 |
<https://www.openssl.org/source/license.html>. |