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