OPENSSL_LH_COMPFUNC.3ossl 20 KB

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