Constify X509|X509_CRL|X509_REVOKED_get_ext
[openssl.git] / doc / crypto / BIO_set_callback.pod
1 =pod
2
3 =head1 NAME
4
5 BIO_set_callback, BIO_get_callback, BIO_set_callback_arg, BIO_get_callback_arg,
6 BIO_debug_callback - BIO callback functions
7
8 =head1 SYNOPSIS
9
10  #include <openssl/bio.h>
11
12
13  typedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
14                                  long argl, long ret);
15
16  void BIO_set_callback(BIO *b, BIO_callack_fn cb);
17  BIO_callack_fn BIO_get_callback(BIO *b);
18  void BIO_set_callback_arg(BIO *b, char *arg);
19  char *BIO_get_callback_arg(const BIO *b);
20
21  long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
22                          long argl, long ret);
23
24 =head1 DESCRIPTION
25
26 BIO_set_callback() and BIO_get_callback() set and retrieve the BIO callback,
27 they are both macros. The callback is called during most high level BIO
28 operations. It can be used for debugging purposes to trace operations on
29 a BIO or to modify its operation.
30
31 BIO_set_callback_arg() and BIO_get_callback_arg() are macros which can be
32 used to set and retrieve an argument for use in the callback.
33
34 BIO_debug_callback() is a standard debugging callback which prints
35 out information relating to each BIO operation. If the callback
36 argument is set it is interpreted as a BIO to send the information
37 to, otherwise stderr is used.
38
39 BIO_callback_fn() is the type of the callback function. The meaning of each
40 argument is described below:
41
42 =over
43
44 =item B<b>
45
46 The BIO the callback is attached to is passed in B<b>.
47
48 =item B<oper>
49
50 B<oper> is set to the operation being performed. For some operations
51 the callback is called twice, once before and once after the actual
52 operation, the latter case has B<oper> or'ed with BIO_CB_RETURN.
53
54 =item B<argp> B<argi> B<argl>
55
56 The meaning of the arguments B<argp>, B<argi> and B<argl> depends on
57 the value of B<oper>, that is the operation being performed.
58
59 =item B<ret>
60
61 B<ret> is the return value that would be returned to the
62 application if no callback were present. The actual value returned
63 is the return value of the callback itself. In the case of callbacks
64 called before the actual BIO operation 1 is placed in B<ret>, if
65 the return value is not positive it will be immediately returned to
66 the application and the BIO operation will not be performed.
67
68 =back
69
70 The callback should normally simply return B<ret> when it has
71 finished processing, unless it specifically wishes to modify the
72 value returned to the application.
73
74 =head1 CALLBACK OPERATIONS
75
76 In the notes below, B<callback> defers to the actual callback
77 function that is called.
78
79 =over 4
80
81 =item B<BIO_free(b)>
82
83 callback(b, BIO_CB_FREE, NULL, 0L, 0L, 1L) is called before the
84 free operation.
85
86 =item B<BIO_read(b, out, outl)>
87
88 callback(b, BIO_CB_READ, out, outl, 0L, 1L) is called before
89 the read and callback(b, BIO_CB_READ|BIO_CB_RETURN, out, outl, 0L, retvalue)
90 after.
91
92 =item B<BIO_write(b, in, inl)>
93
94 callback(b, BIO_CB_WRITE, in, inl, 0L, 1L) is called before
95 the write and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl, 0L, retvalue)
96 after.
97
98 =item B<BIO_gets(b, out, outl)>
99
100 callback(b, BIO_CB_GETS, out, outl, 0L, 1L) is called before
101 the operation and callback(b, BIO_CB_GETS|BIO_CB_RETURN, out, outl, 0L, retvalue)
102 after.
103
104 =item B<BIO_puts(b, in)>
105
106 callback(b, BIO_CB_WRITE, in, 0, 0L, 1L) is called before
107 the operation and callback(b, BIO_CB_WRITE|BIO_CB_RETURN, in, 0, 0L, retvalue)
108 after.
109
110 =item B<BIO_ctrl(BIO *b, int cmd, long larg, void *parg)>
111
112 callback(b, BIO_CB_CTRL, parg, cmd, larg, 1L) is called before the call and
113 callback(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret) after.
114
115 =back
116
117 =head1 EXAMPLE
118
119 The BIO_debug_callback() function is a good example, its source is
120 in crypto/bio/bio_cb.c
121
122 =head1 COPYRIGHT
123
124 Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
125
126 Licensed under the OpenSSL license (the "License").  You may not use
127 this file except in compliance with the License.  You can obtain a copy
128 in the file LICENSE in the source distribution or at
129 L<https://www.openssl.org/source/license.html>.
130
131 =cut