
#use wml::openssl-macros area=docs page=BIO_set_callback

<title>Documents, BIO_set_callback(3)</title>

<h1>BIO_set_callback(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#CALLBACK_OPERATIONS">CALLBACK OPERATIONS</A>
	<LI><A HREF="#EXAMPLE">EXAMPLE</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BIO_set_callback, BIO_get_callback, BIO_set_callback_arg,
BIO_get_callback_arg, BIO_debug_callback - BIO callback functions

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bio.h&gt;
</PRE>
<PRE> #define BIO_set_callback(b,cb)         ((b)-&gt;callback=(cb))
 \#define BIO_get_callback(b)            ((b)-&gt;callback)
 \#define BIO_set_callback_arg(b,arg)    ((b)-&gt;cb_arg=(char *)(arg))
 \#define BIO_get_callback_arg(b)                ((b)-&gt;cb_arg)
</PRE>
<PRE> long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
        long argl,long ret);
</PRE>
<PRE> typedef long (*callback)(BIO *b, int oper, const char *argp,
                        int argi, long argl, long retvalue);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BIO_set_callback()</CODE> and <CODE>BIO_get_callback()</CODE> set and
retrieve the BIO callback, they are both macros. The callback is called
during most high level BIO operations. It can be used for debugging
purposes to trace operations on a BIO or to modify its operation.

</P>
<P>
<CODE>BIO_set_callback_arg()</CODE> and <CODE>BIO_get_callback_arg()</CODE>
are macros which can be used to set and retrieve an argument for use in the
callback.

</P>
<P>
<CODE>BIO_debug_callback()</CODE> is a standard debugging callback which
prints out information relating to each BIO operation. If the callback
argument is set if is interpreted as a BIO to send the information to,
otherwise stderr is used.

</P>
<P>
<CODE>callback()</CODE> is the callback function itself. The meaning of
each argument is described below.

</P>
<P>
The BIO the callback is attached to is passed in <STRONG>b</STRONG>.

</P>
<P>
<STRONG>oper</STRONG> is set to the operation being performed. For some operations the callback
is called twice, once before and once after the actual operation, the
latter case has <STRONG>oper</STRONG> or'ed with BIO_CB_RETURN.

</P>
<P>
The meaning of the arguments <STRONG>argp</STRONG>, <STRONG>argi</STRONG> and <STRONG>argl</STRONG> depends on the value of <STRONG>oper</STRONG>, that is the operation being performed.

</P>
<P>
<STRONG>retvalue</STRONG> is the return value that would be returned to the application if no
callback were present. The actual value returned is the return value of the
callback itself. In the case of callbacks called before the actual BIO
operation 1 is placed in retvalue, if the return value is not positive it
will be immediately returned to the application and the BIO operation will
not be performed.

</P>
<P>
The callback should normally simply return <STRONG>retvalue</STRONG> when it has finished processing, unless if specifically wishes to modify
the value returned to the application.

</P>
<P>
<HR>
<H1><A NAME="CALLBACK_OPERATIONS">CALLBACK OPERATIONS</A></H1>
<DL>
<DT><STRONG><A NAME="item_BIO_free"><STRONG>BIO_free(b)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,</CODE> BIO_CB_FREE, NULL, 0L, 0L, 1L) is called before
the free operation.

</P>
<DT><STRONG><A NAME="item_BIO_read"><STRONG>BIO_read(b, out, outl)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,</CODE> BIO_CB_READ, out, outl, 0L, 1L) is called before
the read and <CODE>callback(b,</CODE> BIO_CB_READ|BIO_CB_RETURN, out, outl,
0L, retvalue) after.

</P>
<DT><STRONG><A NAME="item_BIO_write"><STRONG>BIO_write(b, in, inl)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,</CODE> BIO_CB_WRITE, in, inl, 0L, 1L) is called before
the write and <CODE>callback(b,</CODE> BIO_CB_WRITE|BIO_CB_RETURN, in, inl,
0L, retvalue) after.

</P>
<DT><STRONG><A NAME="item_BIO_gets"><STRONG>BIO_gets(b, out, outl)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,</CODE> BIO_CB_GETS, out, outl, 0L, 1L) is called before
the operation and <CODE>callback(b,</CODE> BIO_CB_GETS|BIO_CB_RETURN, out,
outl, 0L, retvalue) after.

</P>
<DT><STRONG><A NAME="item_BIO_puts"><STRONG>BIO_puts(b, in)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,</CODE> BIO_CB_WRITE, in, 0, 0L, 1L) is called before the
operation and <CODE>callback(b,</CODE> BIO_CB_WRITE|BIO_CB_RETURN, in, 0,
0L, retvalue) after.

</P>
<DT><STRONG><A NAME="item_BIO_ctrl"><STRONG>BIO_ctrl(BIO *b, int cmd, long larg, void *parg)</STRONG></A></STRONG><DD>
<P>
<CODE>callback(b,BIO_CB_CTRL,parg,cmd,larg,1L)</CODE> is called before the
call and <CODE>callback(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,</CODE>
larg,ret) after.

</P>
</DL>
<P>
<HR>
<H1><A NAME="EXAMPLE">EXAMPLE</A></H1>
<P>
The <CODE>BIO_debug_callback()</CODE> function is a good example, its
source is in crypto/bio/bio_cb.c

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
TBA
</P>
:}

