3 #include <openssl/bio.h>
6 const BIO_METHOD *method;
7 /* bio, mode, argp, argi, argl, ret */
8 long ( *callback )( struct bio_st *, int, const char *, int, long, long );
9 char *cb_arg; /* first argument for the callback */
12 int flags; /* extra storage */
16 struct bio_st *next_bio; /* used by filter BIOs */
17 struct bio_st *prev_bio; /* used by filter BIOs */
21 CRYPTO_EX_DATA ex_data;
26 #define BIO_TYPE_CUSTOM 0xff
30 static const int typeID = BIO_TYPE_CUSTOM;
31 virtual ~OpensslBIO();
33 virtual int write( const char *buf, int num ) = 0;
34 virtual int read( char *buf, int size ) = 0;
35 virtual int puts( const char *str );
36 virtual int gets( char *str, int size );
37 virtual long ctrl( int cmod, long arg1, void *arg2 ) = 0;
40 namespace BIOWrapper {
42 int write( BIO *b, const char *buf, int num );
44 int read( BIO *b, char *buf, int size );
46 int puts( BIO *b, const char *str );
48 int gets( BIO *b, char *str, int size );
50 long ctrl( BIO *b, int cmod, long arg1, void *arg2 );
53 int bio_new( BIO *b ) {
66 return toBio<T>( BIOWrapper::bio_new<T> );
70 BIO_METHOD *toBio( int ( *newfunc )( BIO * ) ) {
71 BIO_METHOD *meth = BIO_meth_new( T::typeID, T::getName() );
72 BIO_meth_set_write( meth, BIOWrapper::write );
73 BIO_meth_set_read( meth, BIOWrapper::read );
74 BIO_meth_set_puts( meth, BIOWrapper::puts );
75 BIO_meth_set_gets( meth, BIOWrapper::gets );
76 BIO_meth_set_ctrl( meth, BIOWrapper::ctrl );
77 BIO_meth_set_destroy( meth, BIOWrapper::free );
78 BIO_meth_set_create( meth, newfunc );