]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/safestack.h
Rename lh_xxx,sk_xxx tp OPENSSL_{LH,SK}_xxx
[thirdparty/openssl.git] / include / openssl / safestack.h
CommitLineData
21dcbebc
RS
1/*
2 * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
f73e07cf 3 *
21dcbebc
RS
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
f73e07cf
BL
8 */
9
10#ifndef HEADER_SAFESTACK_H
0f113f3e 11# define HEADER_SAFESTACK_H
f73e07cf 12
0f113f3e 13# include <openssl/stack.h>
411abf2d 14# include <openssl/e_os2.h>
f73e07cf 15
17e80c6b
RS
16#ifdef __cplusplus
17extern "C" {
18#endif
19
0f113f3e 20# define STACK_OF(type) struct stack_st_##type
1d1a6465 21
85885715 22# define SKM_DEFINE_STACK_OF(t1, t2, t3) \
411abf2d 23 STACK_OF(t1); \
739a1eb1
RS
24 typedef int (*sk_##t1##_compfunc)(const t3 * const *a, const t3 *const *b); \
25 typedef void (*sk_##t1##_freefunc)(t3 *a); \
26 typedef t3 * (*sk_##t1##_copyfunc)(const t3 *a); \
411abf2d
DSH
27 static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
28 { \
739a1eb1 29 return OPENSSL_sk_num((const OPENSSL_STACK *)sk); \
411abf2d
DSH
30 } \
31 static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
32 { \
739a1eb1 33 return (t2 *)OPENSSL_sk_value((const OPENSSL_STACK *)sk, idx); \
411abf2d 34 } \
739a1eb1 35 static ossl_inline STACK_OF(t1) *sk_##t1##_new(sk_##t1##_compfunc compare) \
411abf2d 36 { \
739a1eb1 37 return (STACK_OF(t1) *)OPENSSL_sk_new((OPENSSL_sk_compfunc)compare); \
411abf2d
DSH
38 } \
39 static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
40 { \
739a1eb1 41 return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \
411abf2d 42 } \
afdd82fb 43 static ossl_inline void sk_##t1##_free(STACK_OF(t1) *sk) \
411abf2d 44 { \
739a1eb1 45 OPENSSL_sk_free((OPENSSL_STACK *)sk); \
411abf2d 46 } \
afdd82fb 47 static ossl_inline void sk_##t1##_zero(STACK_OF(t1) *sk) \
411abf2d 48 { \
739a1eb1 49 OPENSSL_sk_zero((OPENSSL_STACK *)sk); \
411abf2d
DSH
50 } \
51 static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
52 { \
739a1eb1 53 return (t2 *)OPENSSL_sk_delete((OPENSSL_STACK *)sk, i); \
411abf2d
DSH
54 } \
55 static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
56 { \
739a1eb1 57 return (t2 *)OPENSSL_sk_delete_ptr((OPENSSL_STACK *)sk, (void *)ptr); \
411abf2d
DSH
58 } \
59 static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
60 { \
739a1eb1 61 return OPENSSL_sk_push((OPENSSL_STACK *)sk, (void *)ptr); \
411abf2d
DSH
62 } \
63 static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
64 { \
739a1eb1 65 return OPENSSL_sk_unshift((OPENSSL_STACK *)sk, (void *)ptr); \
411abf2d
DSH
66 } \
67 static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
68 { \
739a1eb1 69 return (t2 *)OPENSSL_sk_pop((OPENSSL_STACK *)sk); \
411abf2d
DSH
70 } \
71 static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
72 { \
739a1eb1 73 return (t2 *)OPENSSL_sk_shift((OPENSSL_STACK *)sk); \
411abf2d 74 } \
739a1eb1 75 static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, sk_##t1##_freefunc freefunc) \
411abf2d 76 { \
739a1eb1 77 OPENSSL_sk_pop_free((OPENSSL_STACK *)sk, (OPENSSL_sk_freefunc)freefunc); \
411abf2d
DSH
78 } \
79 static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
80 { \
739a1eb1 81 return OPENSSL_sk_insert((OPENSSL_STACK *)sk, (void *)ptr, idx); \
411abf2d
DSH
82 } \
83 static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
84 { \
739a1eb1 85 return (t2 *)OPENSSL_sk_set((OPENSSL_STACK *)sk, idx, (void *)ptr); \
411abf2d
DSH
86 } \
87 static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
88 { \
739a1eb1 89 return OPENSSL_sk_find((OPENSSL_STACK *)sk, (void *)ptr); \
411abf2d
DSH
90 } \
91 static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
92 { \
739a1eb1 93 return OPENSSL_sk_find_ex((OPENSSL_STACK *)sk, (void *)ptr); \
411abf2d 94 } \
afdd82fb 95 static ossl_inline void sk_##t1##_sort(STACK_OF(t1) *sk) \
411abf2d 96 { \
739a1eb1 97 OPENSSL_sk_sort((OPENSSL_STACK *)sk); \
411abf2d
DSH
98 } \
99 static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
100 { \
739a1eb1 101 return OPENSSL_sk_is_sorted((const OPENSSL_STACK *)sk); \
411abf2d
DSH
102 } \
103 static ossl_inline STACK_OF(t1) * sk_##t1##_dup(STACK_OF(t1) *sk) \
104 { \
739a1eb1 105 return (STACK_OF(t1) *)OPENSSL_sk_dup((OPENSSL_STACK *)sk); \
411abf2d
DSH
106 } \
107 static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(STACK_OF(t1) *sk, \
739a1eb1
RS
108 sk_##t1##_copyfunc copyfunc, \
109 sk_##t1##_freefunc freefunc) \
411abf2d 110 { \
739a1eb1
RS
111 return (STACK_OF(t1) *)OPENSSL_sk_deep_copy((OPENSSL_STACK *)sk, \
112 (OPENSSL_sk_copyfunc)copyfunc, \
113 (OPENSSL_sk_freefunc)freefunc); \
411abf2d 114 } \
739a1eb1 115 static ossl_inline sk_##t1##_compfunc sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, sk_##t1##_compfunc compare) \
411abf2d 116 { \
739a1eb1 117 return (sk_##t1##_compfunc)OPENSSL_sk_set_cmp_func((OPENSSL_STACK *)sk, (OPENSSL_sk_compfunc)compare); \
411abf2d
DSH
118 }
119
85885715
DSH
120# define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
121# define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
a8eba56e 122# define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
1d1a6465 123
1d97c843
TH
124/*-
125 * Strings are special: normally an lhash entry will point to a single
5ce278a7
BL
126 * (somewhat) mutable object. In the case of strings:
127 *
128 * a) Instead of a single char, there is an array of chars, NUL-terminated.
129 * b) The string may have be immutable.
130 *
131 * So, they need their own declarations. Especially important for
132 * type-checking tools, such as Deputy.
133 *
1d97c843 134 * In practice, however, it appears to be hard to have a const
5ce278a7
BL
135 * string. For now, I'm settling for dealing with the fact it is a
136 * string at all.
137 */
c869da88 138typedef char *OPENSSL_STRING;
c869da88 139typedef const char *OPENSSL_CSTRING;
5ce278a7 140
5b18d302 141/*-
0f113f3e
MC
142 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
143 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
144 * above, instead of a single char each entry is a NUL-terminated array of
145 * chars. So, we have to implement STRING specially for STACK_OF. This is
146 * dealt with in the autogenerated macros below.
5ce278a7 147 */
85885715 148DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
5ce278a7 149
0f113f3e
MC
150/*
151 * Similarly, we sometimes use a block of characters, NOT nul-terminated.
152 * These should also be distinguished from "normal" stacks.
153 */
512d359e 154typedef void *OPENSSL_BLOCK;
85885715 155DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
5ce278a7 156
5b18d302 157# ifdef __cplusplus
17e80c6b 158}
5b18d302 159# endif
17e80c6b 160#endif