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