X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=doc%2Fman3%2FDEFINE_STACK_OF.pod;h=9088dc040b3fc3404c6d423d59548e29cdfea01d;hp=4dd3de843f80dbf481936a48a4ba3d1b8276140d;hb=HEAD;hpb=bb82531f6592f0e9af28d3502346191a465374a3 diff --git a/doc/man3/DEFINE_STACK_OF.pod b/doc/man3/DEFINE_STACK_OF.pod index 4dd3de843f..ff2074820f 100644 --- a/doc/man3/DEFINE_STACK_OF.pod +++ b/doc/man3/DEFINE_STACK_OF.pod @@ -8,8 +8,16 @@ sk_TYPE_num, sk_TYPE_value, sk_TYPE_new, sk_TYPE_new_null, sk_TYPE_reserve, sk_TYPE_free, sk_TYPE_zero, sk_TYPE_delete, sk_TYPE_delete_ptr, sk_TYPE_push, sk_TYPE_unshift, sk_TYPE_pop, sk_TYPE_shift, sk_TYPE_pop_free, sk_TYPE_insert, sk_TYPE_set, -sk_TYPE_find, sk_TYPE_find_ex, sk_TYPE_sort, sk_TYPE_is_sorted, -sk_TYPE_dup, sk_TYPE_deep_copy, sk_TYPE_set_cmp_func, sk_TYPE_new_reserve +sk_TYPE_find, sk_TYPE_find_ex, sk_TYPE_find_all, sk_TYPE_sort, +sk_TYPE_is_sorted, sk_TYPE_dup, sk_TYPE_deep_copy, sk_TYPE_set_cmp_func, +sk_TYPE_new_reserve, +OPENSSL_sk_deep_copy, OPENSSL_sk_delete, OPENSSL_sk_delete_ptr, +OPENSSL_sk_dup, OPENSSL_sk_find, OPENSSL_sk_find_ex, OPENSSL_sk_find_all, +OPENSSL_sk_free, OPENSSL_sk_insert, OPENSSL_sk_is_sorted, OPENSSL_sk_new, +OPENSSL_sk_new_null, OPENSSL_sk_new_reserve, OPENSSL_sk_num, OPENSSL_sk_pop, +OPENSSL_sk_pop_free, OPENSSL_sk_push, OPENSSL_sk_reserve, OPENSSL_sk_set, +OPENSSL_sk_set_cmp_func, OPENSSL_sk_shift, OPENSSL_sk_sort, +OPENSSL_sk_unshift, OPENSSL_sk_value, OPENSSL_sk_zero - stack container =head1 SYNOPSIS @@ -33,8 +41,8 @@ sk_TYPE_dup, sk_TYPE_deep_copy, sk_TYPE_set_cmp_func, sk_TYPE_new_reserve STACK_OF(TYPE) *sk_TYPE_new(sk_TYPE_compfunc compare); STACK_OF(TYPE) *sk_TYPE_new_null(void); int sk_TYPE_reserve(STACK_OF(TYPE) *sk, int n); - void sk_TYPE_free(const STACK_OF(TYPE) *sk); - void sk_TYPE_zero(const STACK_OF(TYPE) *sk); + void sk_TYPE_free(STACK_OF(TYPE) *sk); + void sk_TYPE_zero(STACK_OF(TYPE) *sk); TYPE *sk_TYPE_delete(STACK_OF(TYPE) *sk, int i); TYPE *sk_TYPE_delete_ptr(STACK_OF(TYPE) *sk, TYPE *ptr); int sk_TYPE_push(STACK_OF(TYPE) *sk, const TYPE *ptr); @@ -46,6 +54,7 @@ sk_TYPE_dup, sk_TYPE_deep_copy, sk_TYPE_set_cmp_func, sk_TYPE_new_reserve TYPE *sk_TYPE_set(STACK_OF(TYPE) *sk, int idx, const TYPE *ptr); int sk_TYPE_find(STACK_OF(TYPE) *sk, TYPE *ptr); int sk_TYPE_find_ex(STACK_OF(TYPE) *sk, TYPE *ptr); + int sk_TYPE_find_all(STACK_OF(TYPE) *sk, TYPE *ptr, int *pnum); void sk_TYPE_sort(const STACK_OF(TYPE) *sk); int sk_TYPE_is_sorted(const STACK_OF(TYPE) *sk); STACK_OF(TYPE) *sk_TYPE_dup(const STACK_OF(TYPE) *sk); @@ -64,27 +73,31 @@ functions that wrap around the utility B API. In the description here, B> is used as a placeholder for any of the OpenSSL datatypes, such as B. -STACK_OF() returns the name for a stack of the specified B>. -DEFINE_STACK_OF() creates set of functions for a stack of B>. This -will mean that type B> is stored in each stack, the type is referenced by -B(B>) and each function name begins with B_>. -For example: - - TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); +The STACK_OF() macro returns the name for a stack of the specified B>. +This is an opaque pointer to a structure declaration. +This can be used in every header file that references the stack. +There are several B macros that create static inline functions +for all of the functions described on this page. +This should normally be used in one source file, and the stack manipulation +is wrapped with application-specific functions. +DEFINE_STACK_OF() creates set of functions for a stack of B> elements. +The type is referenced by +B(B>) and each function name begins with B_>. DEFINE_STACK_OF_CONST() is identical to DEFINE_STACK_OF() except -each element is constant. For example: +each element is constant. + /* DEFINE_STACK_OF(TYPE) */ + TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); + /* DEFINE_STACK_OF_CONST(TYPE) */ const TYPE *sk_TYPE_value(STACK_OF(TYPE) *sk, int idx); -DEFINE_SPECIAL_STACK_OF() defines a stack of B> but -each function uses B in the function name. For example: +DEFINE_SPECIAL_STACK_OF() and DEFINE_SPECIAL_STACK_OF_CONST() are similar +except B is used in the function names: + /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); - -DEFINE_SPECIAL_STACK_OF_CONST() is similar except that each element is -constant: - + /* DEFINE_SPECIAL_STACK_OF(TYPE, FUNCNAME) */ const TYPE *sk_FUNCNAME_value(STACK_OF(TYPE) *sk, int idx); B_num>() returns the number of elements in I or -1 if I is @@ -161,29 +174,36 @@ B_find>() searches I for the element I. In the case where no comparison function has been specified, the function performs a linear search for a pointer equal to I. The index of the first matching element is returned or B<-1> if there is no match. In the case -where a comparison function has been specified, I is sorted then +where a comparison function has been specified, I is sorted and B_find>() returns the index of a matching element or B<-1> if there -is no match. Note that, in this case, the matching element returned is -not guaranteed to be the first; the comparison function will usually +is no match. Note that, in this case the comparison function will usually compare the values pointed to rather than the pointers themselves and -the order of elements in I could change. +the order of elements in I can change. B_find_ex>() operates like B_find>() except when a comparison function has been specified and no matching element is found. Instead of returning B<-1>, B_find_ex>() returns the index of the element either before or after the location where I would be if it were -present in I. +present in I. The function also does not guarantee that the first matching +element in the sorted stack is returned. + +B_find_all>() operates like B_find>() but it also +sets the I<*pnum> to number of matching elements in the stack. In case +no comparison function has been specified the I<*pnum> will be always set +to 1 if matching element was found, 0 otherwise. B_sort>() sorts I using the supplied comparison function. B_is_sorted>() returns B<1> if I is sorted and B<0> otherwise. -B_dup>() returns a copy of I. Note the pointers in the copy -are identical to the original. +B_dup>() returns a shallow copy of I +or an empty stack if the passed stack is NULL. +Note the pointers in the copy are identical to the original. B_deep_copy>() returns a new stack where each element has been -copied. Copying is performed by the supplied copyfunc() and freeing by -freefunc(). The function freefunc() is only called if an error occurs. +copied or an empty stack if the passed stack is NULL. +Copying is performed by the supplied copyfunc() and freeing by freefunc(). +The function freefunc() is only called if an error occurs. =head1 NOTES @@ -206,16 +226,23 @@ A failed search is indicated by a B<-1> return value. STACK_OF(), DEFINE_STACK_OF(), DEFINE_STACK_OF_CONST(), and DEFINE_SPECIAL_STACK_OF() are implemented as macros. +It is not an error to call B_num>(), B_value>(), +B_free>(), B_zero>(), B_pop_free>(), +B_delete>(), B_delete_ptr>(), B_pop>(), +B_shift>(), B_find>(), B_find_ex>(), +and B_find_all>() on a NULL stack, empty stack, or with +an invalid index. An error is not raised in these conditions. + The underlying utility B API should not be used directly. It defines these functions: OPENSSL_sk_deep_copy(), OPENSSL_sk_delete(), OPENSSL_sk_delete_ptr(), OPENSSL_sk_dup(), -OPENSSL_sk_find(), OPENSSL_sk_find_ex(), OPENSSL_sk_free(), -OPENSSL_sk_insert(), OPENSSL_sk_is_sorted(), OPENSSL_sk_new(), -OPENSSL_sk_new_null(), OPENSSL_sk_num(), OPENSSL_sk_pop(), -OPENSSL_sk_pop_free(), OPENSSL_sk_push(), OPENSSL_sk_reserve(), -OPENSSL_sk_set(), OPENSSL_sk_set_cmp_func(), OPENSSL_sk_shift(), -OPENSSL_sk_sort(), OPENSSL_sk_unshift(), OPENSSL_sk_value(), -OPENSSL_sk_zero(). +OPENSSL_sk_find(), OPENSSL_sk_find_ex(), OPENSSL_sk_find_all(), +OPENSSL_sk_free(), OPENSSL_sk_insert(), OPENSSL_sk_is_sorted(), +OPENSSL_sk_new(), OPENSSL_sk_new_null(), OPENSSL_sk_new_reserve(), +OPENSSL_sk_num(), OPENSSL_sk_pop(), OPENSSL_sk_pop_free(), OPENSSL_sk_push(), +OPENSSL_sk_reserve(), OPENSSL_sk_set(), OPENSSL_sk_set_cmp_func(), +OPENSSL_sk_shift(), OPENSSL_sk_sort(), OPENSSL_sk_unshift(), +OPENSSL_sk_value(), OPENSSL_sk_zero(). =head1 RETURN VALUES @@ -254,7 +281,7 @@ B_is_sorted>() returns B<1> if the stack is sorted and B<0> if it is not. B_dup>() and B_deep_copy>() return a pointer to the copy -of the stack. +of the stack or NULL on error. =head1 HISTORY @@ -264,9 +291,17 @@ and was not a public API. B_reserve>() and B_new_reserve>() were added in OpenSSL 1.1.1. +From OpenSSL 3.2.0, the B_find>(), B_find_ex>() +and B_find_all>() calls are read-only and do not sort the +stack. To avoid any performance implications this change introduces, +B_sort>() should be called before these find operations. + +Before OpenSSL 3.3.0 B_push>() returned -1 if I was NULL. It +was changed to return 0 in this condition as for other errors. + =head1 COPYRIGHT -Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy