1 /* automatically generated by util/mkstack.pl */
2 /* ====================================================================
3 * Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
31 * 6. Redistributions of any form whatsoever must retain the following
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
56 #ifndef HEADER_SAFESTACK_H
57 # define HEADER_SAFESTACK_H
59 # include <openssl/stack.h>
60 # include <openssl/e_os2.h>
66 # ifndef CHECKED_PTR_OF
67 # define CHECKED_PTR_OF(type, p) ((void*) (1 ? p : (type*)0))
71 * In C++ we get problems because an explicit cast is needed from (void *) we
72 * use CHECKED_STACK_OF to ensure the correct type is passed in the macros
76 # define CHECKED_STACK_OF(type, p) \
77 ((_STACK*) (1 ? p : (STACK_OF(type)*)0))
79 # define CHECKED_SK_COPY_FUNC(type, p) \
80 ((void *(*)(void *)) ((1 ? p : (type *(*)(const type *))0)))
82 # define CHECKED_SK_FREE_FUNC(type, p) \
83 ((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
85 # define CHECKED_SK_CMP_FUNC(type, p) \
86 ((int (*)(const void *, const void *)) \
87 ((1 ? p : (int (*)(const type * const *, const type * const *))0)))
89 # define STACK_OF(type) struct stack_st_##type
91 # define SKM_DEFINE_STACK_OF(t1, t2, t3) \
93 static ossl_inline int sk_##t1##_num(const STACK_OF(t1) *sk) \
95 return sk_num((_STACK *)sk); \
97 static ossl_inline t2 *sk_##t1##_value(const STACK_OF(t1) *sk, int idx) \
99 return (t2 *)sk_value((_STACK *)sk, idx); \
101 static ossl_inline STACK_OF(t1) *sk_##t1##_new(int (*cmpf)(const t3 * const *a, const t3 * const *b)) \
103 return (STACK_OF(t1) *)sk_new((int (*)(const void *a, const void *b))cmpf); \
105 static ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \
107 return (STACK_OF(t1) *)sk_new_null(); \
109 static ossl_inline void sk_##t1##_free(const STACK_OF(t1) *sk) \
111 sk_free((_STACK *)sk); \
113 static ossl_inline void sk_##t1##_zero(const STACK_OF(t1) *sk) \
115 sk_zero((_STACK *)sk); \
117 static ossl_inline t2 *sk_##t1##_delete(STACK_OF(t1) *sk, int i) \
119 return (t2 *)sk_delete((_STACK *)sk, i); \
121 static ossl_inline t2 *sk_##t1##_delete_ptr(STACK_OF(t1) *sk, t2 *ptr) \
123 return (t2 *)sk_delete_ptr((_STACK *)sk, (void *)ptr); \
125 static ossl_inline int sk_##t1##_push(STACK_OF(t1) *sk, t2 *ptr) \
127 return sk_push((_STACK *)sk, (void *)ptr); \
129 static ossl_inline int sk_##t1##_unshift(STACK_OF(t1) *sk, t2 *ptr) \
131 return sk_unshift((_STACK *)sk, (void *)ptr); \
133 static ossl_inline t2 *sk_##t1##_pop(STACK_OF(t1) *sk) \
135 return (t2 *)sk_pop((_STACK *)sk); \
137 static ossl_inline t2 *sk_##t1##_shift(STACK_OF(t1) *sk) \
139 return (t2 *)sk_shift((_STACK *)sk); \
141 static ossl_inline void sk_##t1##_pop_free(STACK_OF(t1) *sk, void (*func)(t3 *a)) \
143 sk_pop_free((_STACK *)sk, (void (*)(void *))func); \
145 static ossl_inline int sk_##t1##_insert(STACK_OF(t1) *sk, t2 *ptr, int idx) \
147 return sk_insert((_STACK *)sk, (void *)ptr, idx); \
149 static ossl_inline t2 *sk_##t1##_set(STACK_OF(t1) *sk, int idx, t2 *ptr) \
151 return (t2 *)sk_set((_STACK *)sk, idx, (void *)ptr); \
153 static ossl_inline int sk_##t1##_find(STACK_OF(t1) *sk, t2 *ptr) \
155 return sk_find((_STACK *)sk, (void *)ptr); \
157 static ossl_inline int sk_##t1##_find_ex(STACK_OF(t1) *sk, t2 *ptr) \
159 return sk_find_ex((_STACK *)sk, (void *)ptr); \
161 static ossl_inline void sk_##t1##_sort(const STACK_OF(t1) *sk) \
163 sk_sort((_STACK *)sk); \
165 static ossl_inline int sk_##t1##_is_sorted(const STACK_OF(t1) *sk) \
167 return sk_is_sorted((_STACK *)sk); \
169 static ossl_inline STACK_OF(t1) * sk_##t1##_dup(STACK_OF(t1) *sk) \
171 return (STACK_OF(t1) *)sk_dup((_STACK *)sk); \
173 static ossl_inline STACK_OF(t1) *sk_##t1##_deep_copy(STACK_OF(t1) *sk, \
174 t3 *(*copyfn)(const t3 *), \
175 void (*freefn)(t3 *)) \
177 return (STACK_OF(t1) *)sk_deep_copy((_STACK *)sk, \
178 (void * (*)(void *a))copyfn, \
179 (void (*)(void *a))freefn); \
181 static ossl_inline int (*sk_##t1##_set_cmp_func(STACK_OF(t1) *sk, int (*cmpf)(const t3 * const *a, const t3 * const *b)))(const t3 * const *, const t3 * const *) \
183 return (int (*)(const t3 * const *,const t3 * const *))sk_set_cmp_func((_STACK *)sk, (int (*)(const void *a, const void *b))cmpf); \
186 # define DEFINE_SPECIAL_STACK_OF(t1, t2) SKM_DEFINE_STACK_OF(t1, t2, t2)
187 # define DEFINE_STACK_OF(t) SKM_DEFINE_STACK_OF(t, t, t)
188 # define DEFINE_STACK_OF_CONST(t) SKM_DEFINE_STACK_OF(t, const t, t)
191 * Strings are special: normally an lhash entry will point to a single
192 * (somewhat) mutable object. In the case of strings:
194 * a) Instead of a single char, there is an array of chars, NUL-terminated.
195 * b) The string may have be immutable.
197 * So, they need their own declarations. Especially important for
198 * type-checking tools, such as Deputy.
200 * In practice, however, it appears to be hard to have a const
201 * string. For now, I'm settling for dealing with the fact it is a
204 typedef char *OPENSSL_STRING;
205 typedef const char *OPENSSL_CSTRING;
208 * Confusingly, LHASH_OF(STRING) deals with char ** throughout, but
209 * STACK_OF(STRING) is really more like STACK_OF(char), only, as mentioned
210 * above, instead of a single char each entry is a NUL-terminated array of
211 * chars. So, we have to implement STRING specially for STACK_OF. This is
212 * dealt with in the autogenerated macros below.
214 DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)
217 * Similarly, we sometimes use a block of characters, NOT nul-terminated.
218 * These should also be distinguished from "normal" stacks.
220 typedef void *OPENSSL_BLOCK;
221 DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
224 * This file is automatically generated by util/mkstack.pl
229 * SKM_sk_... stack macros are internal to safestack.h: never use them
230 * directly, use sk_<type>_... instead
234 # define lh_ADDED_OBJ_new() LHM_lh_new(ADDED_OBJ,added_obj)
235 # define lh_ADDED_OBJ_doall(lh,fn) LHM_lh_doall(ADDED_OBJ,lh,fn)
236 # define lh_ADDED_OBJ_doall_arg(lh,fn,arg_type,arg) \
237 LHM_lh_doall_arg(ADDED_OBJ,lh,fn,arg_type,arg)
239 # define lh_APP_INFO_new() LHM_lh_new(APP_INFO,app_info)
240 # define lh_APP_INFO_doall(lh,fn) LHM_lh_doall(APP_INFO,lh,fn)
241 # define lh_APP_INFO_doall_arg(lh,fn,arg_type,arg) \
242 LHM_lh_doall_arg(APP_INFO,lh,fn,arg_type,arg)
244 # define lh_CONF_VALUE_new() LHM_lh_new(CONF_VALUE,conf_value)
245 # define lh_CONF_VALUE_doall(lh,fn) LHM_lh_doall(CONF_VALUE,lh,fn)
246 # define lh_CONF_VALUE_doall_arg(lh,fn,arg_type,arg) \
247 LHM_lh_doall_arg(CONF_VALUE,lh,fn,arg_type,arg)
249 # define lh_ENGINE_PILE_new() LHM_lh_new(ENGINE_PILE,engine_pile)
250 # define lh_ENGINE_PILE_doall(lh,fn) LHM_lh_doall(ENGINE_PILE,lh,fn)
251 # define lh_ENGINE_PILE_doall_arg(lh,fn,arg_type,arg) \
252 LHM_lh_doall_arg(ENGINE_PILE,lh,fn,arg_type,arg)
254 # define lh_ERR_STATE_new() LHM_lh_new(ERR_STATE,err_state)
255 # define lh_ERR_STATE_doall(lh,fn) LHM_lh_doall(ERR_STATE,lh,fn)
256 # define lh_ERR_STATE_doall_arg(lh,fn,arg_type,arg) \
257 LHM_lh_doall_arg(ERR_STATE,lh,fn,arg_type,arg)
259 # define lh_ERR_STRING_DATA_new() LHM_lh_new(ERR_STRING_DATA,err_string_data)
260 # define lh_ERR_STRING_DATA_doall(lh,fn) LHM_lh_doall(ERR_STRING_DATA,lh,fn)
261 # define lh_ERR_STRING_DATA_doall_arg(lh,fn,arg_type,arg) \
262 LHM_lh_doall_arg(ERR_STRING_DATA,lh,fn,arg_type,arg)
264 # define lh_FUNCTION_new() LHM_lh_new(FUNCTION,function)
265 # define lh_FUNCTION_doall(lh,fn) LHM_lh_doall(FUNCTION,lh,fn)
266 # define lh_FUNCTION_doall_arg(lh,fn,arg_type,arg) \
267 LHM_lh_doall_arg(FUNCTION,lh,fn,arg_type,arg)
269 # define lh_MEM_new() LHM_lh_new(MEM,mem)
270 # define lh_MEM_doall(lh,fn) LHM_lh_doall(MEM,lh,fn)
271 # define lh_MEM_doall_arg(lh,fn,arg_type,arg) \
272 LHM_lh_doall_arg(MEM,lh,fn,arg_type,arg)
274 # define lh_OBJ_NAME_new() LHM_lh_new(OBJ_NAME,obj_name)
275 # define lh_OBJ_NAME_doall(lh,fn) LHM_lh_doall(OBJ_NAME,lh,fn)
276 # define lh_OBJ_NAME_doall_arg(lh,fn,arg_type,arg) \
277 LHM_lh_doall_arg(OBJ_NAME,lh,fn,arg_type,arg)
279 # define lh_OPENSSL_CSTRING_new() LHM_lh_new(OPENSSL_CSTRING,openssl_cstring)
280 # define lh_OPENSSL_CSTRING_doall(lh,fn) LHM_lh_doall(OPENSSL_CSTRING,lh,fn)
281 # define lh_OPENSSL_CSTRING_doall_arg(lh,fn,arg_type,arg) \
282 LHM_lh_doall_arg(OPENSSL_CSTRING,lh,fn,arg_type,arg)
284 # define lh_OPENSSL_STRING_new() LHM_lh_new(OPENSSL_STRING,openssl_string)
285 # define lh_OPENSSL_STRING_doall(lh,fn) LHM_lh_doall(OPENSSL_STRING,lh,fn)
286 # define lh_OPENSSL_STRING_doall_arg(lh,fn,arg_type,arg) \
287 LHM_lh_doall_arg(OPENSSL_STRING,lh,fn,arg_type,arg)
289 # define lh_SSL_SESSION_new() LHM_lh_new(SSL_SESSION,ssl_session)
290 # define lh_SSL_SESSION_doall(lh,fn) LHM_lh_doall(SSL_SESSION,lh,fn)
291 # define lh_SSL_SESSION_doall_arg(lh,fn,arg_type,arg) \
292 LHM_lh_doall_arg(SSL_SESSION,lh,fn,arg_type,arg)