| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_EX_DATA_H |
| 16 | #define OPENSSL_HEADER_EX_DATA_H |
| 17 |
| 18 | #include <openssl/base.h> // IWYU pragma: export |
| 19 |
| 20 | #include <openssl/stack.h> |
| 21 |
| 22 | #if defined(__cplusplus) |
| 23 | extern "C" { |
| 24 | #endif |
| 25 |
| 26 |
| 27 | // ex_data is a mechanism for associating arbitrary extra data with objects. |
| 28 | // For each type of object that supports ex_data, different users can be |
| 29 | // assigned indexes in which to store their data. Each index has callback |
| 30 | // functions that are called when an object of that type is freed or |
| 31 | // duplicated. |
| 32 |
| 33 |
| 34 | typedef struct crypto_ex_data_st CRYPTO_EX_DATA; |
| 35 |
| 36 |
| 37 | // Type-specific functions. |
| 38 |
| 39 | #if 0 // Sample |
| 40 |
| 41 | // Each type that supports ex_data provides three functions: |
| 42 |
| 43 | // TYPE_get_ex_new_index allocates a new index for |TYPE|. An optional |
| 44 | // |free_func| argument may be provided which is called when the owning object |
| 45 | // is destroyed. See |CRYPTO_EX_free| for details. The |argl| and |argp| |
| 46 | // arguments are opaque values that are passed to the callback. It returns the |
| 47 | // new index or a negative number on error. |
| 48 | OPENSSL_EXPORT int TYPE_get_ex_new_index(long argl, void *argp, |
| 49 | CRYPTO_EX_unused *unused, |
| 50 | CRYPTO_EX_dup *dup_unused, |
| 51 | CRYPTO_EX_free *free_func); |
| 52 |
| 53 | // TYPE_set_ex_data sets an extra data pointer on |t|. The |index| argument |
| 54 | // must have been returned from a previous call to |TYPE_get_ex_new_index|. |
| 55 | OPENSSL_EXPORT int TYPE_set_ex_data(TYPE *t, int index, void *arg); |
| 56 |
| 57 | // TYPE_get_ex_data returns an extra data pointer for |t|, or NULL if no such |
| 58 | // pointer exists. The |index| argument should have been returned from a |
| 59 | // previous call to |TYPE_get_ex_new_index|. |
| 60 | OPENSSL_EXPORT void *TYPE_get_ex_data(const TYPE *t, int index); |
| 61 |
| 62 | // Some types additionally preallocate index zero, with all callbacks set to |
| 63 | // NULL. Applications that do not need the general ex_data machinery may use |
| 64 | // this instead. |
| 65 |
| 66 | // TYPE_set_app_data sets |t|'s application data pointer to |arg|. It returns |
| 67 | // one on success and zero on error. |
| 68 | OPENSSL_EXPORT int TYPE_set_app_data(TYPE *t, void *arg); |
| 69 |
| 70 | // TYPE_get_app_data returns the application data pointer for |t|, or NULL if no |
| 71 | // such pointer exists. |
| 72 | OPENSSL_EXPORT void *TYPE_get_app_data(const TYPE *t); |
| 73 |
| 74 | #endif // Sample |
| 75 |
| 76 |
| 77 | // Callback types. |
| 78 |
| 79 | // CRYPTO_EX_free is a callback function that is called when an object of the |
| 80 | // class with extra data pointers is being destroyed. For example, if this |
| 81 | // callback has been passed to |SSL_get_ex_new_index| then it may be called each |
| 82 | // time an |SSL*| is destroyed. |
| 83 | // |
| 84 | // The callback is passed the to-be-destroyed object (i.e. the |SSL*|) in |
| 85 | // |parent|. As |parent| will shortly be destroyed, callers must not perform |
| 86 | // operations that would increment its reference count, pass ownership, or |
| 87 | // assume the object outlives the function call. The arguments |argl| and |argp| |
| 88 | // contain opaque values that were given to |CRYPTO_get_ex_new_index_ex|. |
| 89 | // |
| 90 | // This callback may be called with a NULL value for |ptr| if |parent| has no |
| 91 | // value set for this index. However, the callbacks may also be skipped entirely |
| 92 | // if no extra data pointers are set on |parent| at all. |
| 93 | typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, |
| 94 | int index, long argl, void *argp); |
| 95 |
| 96 |
| 97 | // Deprecated functions. |
| 98 |
| 99 | // CRYPTO_cleanup_all_ex_data does nothing. |
| 100 | OPENSSL_EXPORT void CRYPTO_cleanup_all_ex_data(void); |
| 101 |
| 102 | // CRYPTO_EX_dup is a legacy callback function type which is ignored. |
| 103 | typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, |
| 104 | void **from_d, int index, long argl, void *argp); |
| 105 |
| 106 |
| 107 | // Private structures. |
| 108 |
| 109 | // CRYPTO_EX_unused is a placeholder for an unused callback. It is aliased to |
| 110 | // int to ensure non-NULL callers fail to compile rather than fail silently. |
| 111 | typedef int CRYPTO_EX_unused; |
| 112 |
| 113 | struct crypto_ex_data_st { |
| 114 | STACK_OF(void) *sk; |
| 115 | }; |
| 116 |
| 117 |
| 118 | #if defined(__cplusplus) |
| 119 | } // extern C |
| 120 | #endif |
| 121 |
| 122 | #endif // OPENSSL_HEADER_EX_DATA_H |
| 123 |