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