1 1.1 christos =pod 2 1.1 christos 3 1.1 christos =head1 NAME 4 1.1 christos 5 1.1 christos BIO_set_callback_ex, BIO_get_callback_ex, BIO_set_callback, BIO_get_callback, 6 1.1 christos BIO_set_callback_arg, BIO_get_callback_arg, BIO_debug_callback, 7 1.1.1.4 christos BIO_debug_callback_ex, BIO_callback_fn_ex, BIO_callback_fn 8 1.1 christos - BIO callback functions 9 1.1 christos 10 1.1 christos =head1 SYNOPSIS 11 1.1 christos 12 1.1 christos #include <openssl/bio.h> 13 1.1 christos 14 1.1 christos typedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp, 15 1.1 christos size_t len, int argi, 16 1.1 christos long argl, int ret, size_t *processed); 17 1.1 christos 18 1.1 christos void BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback); 19 1.1 christos BIO_callback_fn_ex BIO_get_callback_ex(const BIO *b); 20 1.1 christos 21 1.1 christos void BIO_set_callback_arg(BIO *b, char *arg); 22 1.1 christos char *BIO_get_callback_arg(const BIO *b); 23 1.1 christos 24 1.1.1.4 christos long BIO_debug_callback_ex(BIO *bio, int oper, const char *argp, size_t len, 25 1.1.1.4 christos int argi, long argl, int ret, size_t *processed); 26 1.1.1.4 christos 27 1.1.1.4 christos The following functions have been deprecated since OpenSSL 3.0, and can be 28 1.1.1.4 christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value, 29 1.1.1.4 christos see L<openssl_user_macros(7)>: 30 1.1.1.4 christos 31 1.1.1.4 christos typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi, 32 1.1.1.4 christos long argl, long ret); 33 1.1.1.4 christos void BIO_set_callback(BIO *b, BIO_callback_fn cb); 34 1.1.1.4 christos BIO_callback_fn BIO_get_callback(const BIO *b); 35 1.1 christos long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, 36 1.1 christos long argl, long ret); 37 1.1 christos 38 1.1 christos =head1 DESCRIPTION 39 1.1 christos 40 1.1 christos BIO_set_callback_ex() and BIO_get_callback_ex() set and retrieve the BIO 41 1.1.1.3 christos callback. The callback is called during most high-level BIO operations. It can 42 1.1 christos be used for debugging purposes to trace operations on a BIO or to modify its 43 1.1 christos operation. 44 1.1 christos 45 1.1 christos BIO_set_callback() and BIO_get_callback() set and retrieve the old format BIO 46 1.1 christos callback. New code should not use these functions, but they are retained for 47 1.1 christos backwards compatibility. Any callback set via BIO_set_callback_ex() will get 48 1.1 christos called in preference to any set by BIO_set_callback(). 49 1.1 christos 50 1.1 christos BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be 51 1.1 christos used to set and retrieve an argument for use in the callback. 52 1.1 christos 53 1.1.1.4 christos BIO_debug_callback_ex() is a standard debugging callback which prints 54 1.1 christos out information relating to each BIO operation. If the callback 55 1.1 christos argument is set it is interpreted as a BIO to send the information 56 1.1.1.4 christos to, otherwise stderr is used. The BIO_debug_callback() function is the 57 1.1.1.4 christos deprecated version of the same callback for use with the old callback 58 1.1.1.4 christos format BIO_set_callback() function. 59 1.1 christos 60 1.1.1.4 christos BIO_callback_fn_ex is the type of the callback function and BIO_callback_fn 61 1.1 christos is the type of the old format callback function. The meaning of each argument 62 1.1 christos is described below: 63 1.1 christos 64 1.1 christos =over 4 65 1.1 christos 66 1.1 christos =item B<b> 67 1.1 christos 68 1.1 christos The BIO the callback is attached to is passed in B<b>. 69 1.1 christos 70 1.1 christos =item B<oper> 71 1.1 christos 72 1.1 christos B<oper> is set to the operation being performed. For some operations 73 1.1 christos the callback is called twice, once before and once after the actual 74 1.1 christos operation, the latter case has B<oper> or'ed with BIO_CB_RETURN. 75 1.1 christos 76 1.1 christos =item B<len> 77 1.1 christos 78 1.1 christos The length of the data requested to be read or written. This is only useful if 79 1.1 christos B<oper> is BIO_CB_READ, BIO_CB_WRITE or BIO_CB_GETS. 80 1.1 christos 81 1.1 christos =item B<argp> B<argi> B<argl> 82 1.1 christos 83 1.1 christos The meaning of the arguments B<argp>, B<argi> and B<argl> depends on 84 1.1 christos the value of B<oper>, that is the operation being performed. 85 1.1 christos 86 1.1 christos =item B<processed> 87 1.1 christos 88 1.1 christos B<processed> is a pointer to a location which will be updated with the amount of 89 1.1 christos data that was actually read or written. Only used for BIO_CB_READ, BIO_CB_WRITE, 90 1.1 christos BIO_CB_GETS and BIO_CB_PUTS. 91 1.1 christos 92 1.1 christos =item B<ret> 93 1.1 christos 94 1.1 christos B<ret> is the return value that would be returned to the 95 1.1 christos application if no callback were present. The actual value returned 96 1.1 christos is the return value of the callback itself. In the case of callbacks 97 1.1 christos called before the actual BIO operation 1 is placed in B<ret>, if 98 1.1 christos the return value is not positive it will be immediately returned to 99 1.1 christos the application and the BIO operation will not be performed. 100 1.1 christos 101 1.1 christos =back 102 1.1 christos 103 1.1 christos The callback should normally simply return B<ret> when it has 104 1.1 christos finished processing, unless it specifically wishes to modify the 105 1.1 christos value returned to the application. 106 1.1 christos 107 1.1 christos =head1 CALLBACK OPERATIONS 108 1.1 christos 109 1.1 christos In the notes below, B<callback> defers to the actual callback 110 1.1 christos function that is called. 111 1.1 christos 112 1.1 christos =over 4 113 1.1 christos 114 1.1 christos =item B<BIO_free(b)> 115 1.1 christos 116 1.1 christos callback_ex(b, BIO_CB_FREE, NULL, 0, 0, 0L, 1L, NULL) 117 1.1 christos 118 1.1 christos or 119 1.1 christos 120 1.1 christos callback(b, BIO_CB_FREE, NULL, 0L, 0L, 1L) 121 1.1 christos 122 1.1 christos is called before the free operation. 123 1.1 christos 124 1.1 christos =item B<BIO_read_ex(b, data, dlen, readbytes)> 125 1.1 christos 126 1.1 christos callback_ex(b, BIO_CB_READ, data, dlen, 0, 0L, 1L, NULL) 127 1.1 christos 128 1.1 christos or 129 1.1 christos 130 1.1 christos callback(b, BIO_CB_READ, data, dlen, 0L, 1L) 131 1.1 christos 132 1.1 christos is called before the read and 133 1.1 christos 134 1.1 christos callback_ex(b, BIO_CB_READ | BIO_CB_RETURN, data, dlen, 0, 0L, retvalue, 135 1.1 christos &readbytes) 136 1.1 christos 137 1.1 christos or 138 1.1 christos 139 1.1 christos callback(b, BIO_CB_READ|BIO_CB_RETURN, data, dlen, 0L, retvalue) 140 1.1 christos 141 1.1 christos after. 142 1.1 christos 143 1.1 christos =item B<BIO_write(b, data, dlen, written)> 144 1.1 christos 145 1.1 christos callback_ex(b, BIO_CB_WRITE, data, dlen, 0, 0L, 1L, NULL) 146 1.1 christos 147 1.1 christos or 148 1.1 christos 149 1.1 christos callback(b, BIO_CB_WRITE, datat, dlen, 0L, 1L) 150 1.1 christos 151 1.1 christos is called before the write and 152 1.1 christos 153 1.1 christos callback_ex(b, BIO_CB_WRITE | BIO_CB_RETURN, data, dlen, 0, 0L, retvalue, 154 1.1 christos &written) 155 1.1 christos 156 1.1 christos or 157 1.1 christos 158 1.1 christos callback(b, BIO_CB_WRITE|BIO_CB_RETURN, data, dlen, 0L, retvalue) 159 1.1 christos 160 1.1 christos after. 161 1.1 christos 162 1.1 christos =item B<BIO_gets(b, buf, size)> 163 1.1 christos 164 1.1 christos callback_ex(b, BIO_CB_GETS, buf, size, 0, 0L, 1, NULL, NULL) 165 1.1 christos 166 1.1 christos or 167 1.1 christos 168 1.1 christos callback(b, BIO_CB_GETS, buf, size, 0L, 1L) 169 1.1 christos 170 1.1 christos is called before the operation and 171 1.1 christos 172 1.1 christos callback_ex(b, BIO_CB_GETS | BIO_CB_RETURN, buf, size, 0, 0L, retvalue, 173 1.1 christos &readbytes) 174 1.1 christos 175 1.1 christos or 176 1.1 christos 177 1.1 christos callback(b, BIO_CB_GETS|BIO_CB_RETURN, buf, size, 0L, retvalue) 178 1.1 christos 179 1.1 christos after. 180 1.1 christos 181 1.1 christos =item B<BIO_puts(b, buf)> 182 1.1 christos 183 1.1 christos callback_ex(b, BIO_CB_PUTS, buf, 0, 0, 0L, 1L, NULL); 184 1.1 christos 185 1.1 christos or 186 1.1 christos 187 1.1 christos callback(b, BIO_CB_PUTS, buf, 0, 0L, 1L) 188 1.1 christos 189 1.1 christos is called before the operation and 190 1.1 christos 191 1.1 christos callback_ex(b, BIO_CB_PUTS | BIO_CB_RETURN, buf, 0, 0, 0L, retvalue, &written) 192 1.1 christos 193 1.1 christos or 194 1.1 christos 195 1.1 christos callback(b, BIO_CB_PUTS|BIO_CB_RETURN, buf, 0, 0L, retvalue) 196 1.1 christos 197 1.1 christos after. 198 1.1 christos 199 1.1 christos =item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)> 200 1.1 christos 201 1.1 christos callback_ex(b, BIO_CB_CTRL, parg, 0, cmd, larg, 1L, NULL) 202 1.1 christos 203 1.1 christos or 204 1.1 christos 205 1.1 christos callback(b, BIO_CB_CTRL, parg, cmd, larg, 1L) 206 1.1 christos 207 1.1 christos is called before the call and 208 1.1 christos 209 1.1 christos callback_ex(b, BIO_CB_CTRL | BIO_CB_RETURN, parg, 0, cmd, larg, ret, NULL) 210 1.1 christos 211 1.1 christos or 212 1.1 christos 213 1.1 christos callback(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret) 214 1.1 christos 215 1.1 christos after. 216 1.1 christos 217 1.1 christos Note: B<cmd> == B<BIO_CTRL_SET_CALLBACK> is special, because B<parg> is not the 218 1.1 christos argument of type B<BIO_info_cb> itself. In this case B<parg> is a pointer to 219 1.1 christos the actual call parameter, see B<BIO_callback_ctrl>. 220 1.1 christos 221 1.1 christos =back 222 1.1 christos 223 1.1 christos =head1 RETURN VALUES 224 1.1 christos 225 1.1 christos BIO_get_callback_ex() and BIO_get_callback() return the callback function 226 1.1 christos previously set by a call to BIO_set_callback_ex() and BIO_set_callback() 227 1.1 christos respectively. 228 1.1 christos 229 1.1 christos BIO_get_callback_arg() returns a B<char> pointer to the value previously set 230 1.1 christos via a call to BIO_set_callback_arg(). 231 1.1 christos 232 1.1 christos BIO_debug_callback() returns 1 or B<ret> if it's called after specific BIO 233 1.1 christos operations. 234 1.1 christos 235 1.1.1.2 christos =head1 EXAMPLES 236 1.1.1.2 christos 237 1.1.1.4 christos The BIO_debug_callback_ex() function is an example, its source is 238 1.1.1.2 christos in crypto/bio/bio_cb.c 239 1.1.1.2 christos 240 1.1.1.4 christos =head1 HISTORY 241 1.1.1.4 christos 242 1.1.1.4 christos The BIO_debug_callback_ex() function was added in OpenSSL 3.0. 243 1.1.1.4 christos 244 1.1.1.4 christos BIO_set_callback(), BIO_get_callback(), and BIO_debug_callback() were 245 1.1.1.4 christos deprecated in OpenSSL 3.0. Use the non-deprecated _ex functions instead. 246 1.1.1.4 christos 247 1.1 christos =head1 COPYRIGHT 248 1.1 christos 249 1.1.1.4 christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved. 250 1.1 christos 251 1.1.1.4 christos Licensed under the Apache License 2.0 (the "License"). You may not use 252 1.1 christos this file except in compliance with the License. You can obtain a copy 253 1.1 christos in the file LICENSE in the source distribution or at 254 1.1 christos L<https://www.openssl.org/source/license.html>. 255 1.1 christos 256 1.1 christos =cut 257