bio.h revision 68651
155714Skris/* crypto/bio/bio.h */ 255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 355714Skris * All rights reserved. 455714Skris * 555714Skris * This package is an SSL implementation written 655714Skris * by Eric Young (eay@cryptsoft.com). 755714Skris * The implementation was written so as to conform with Netscapes SSL. 855714Skris * 955714Skris * This library is free for commercial and non-commercial use as long as 1055714Skris * the following conditions are aheared to. The following conditions 1155714Skris * apply to all code found in this distribution, be it the RC4, RSA, 1255714Skris * lhash, DES, etc., code; not just the SSL code. The SSL documentation 1355714Skris * included with this distribution is covered by the same copyright terms 1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com). 1555714Skris * 1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in 1755714Skris * the code are not to be removed. 1855714Skris * If this package is used in a product, Eric Young should be given attribution 1955714Skris * as the author of the parts of the library used. 2055714Skris * This can be in the form of a textual message at program startup or 2155714Skris * in documentation (online or textual) provided with the package. 2255714Skris * 2355714Skris * Redistribution and use in source and binary forms, with or without 2455714Skris * modification, are permitted provided that the following conditions 2555714Skris * are met: 2655714Skris * 1. Redistributions of source code must retain the copyright 2755714Skris * notice, this list of conditions and the following disclaimer. 2855714Skris * 2. Redistributions in binary form must reproduce the above copyright 2955714Skris * notice, this list of conditions and the following disclaimer in the 3055714Skris * documentation and/or other materials provided with the distribution. 3155714Skris * 3. All advertising materials mentioning features or use of this software 3255714Skris * must display the following acknowledgement: 3355714Skris * "This product includes cryptographic software written by 3455714Skris * Eric Young (eay@cryptsoft.com)" 3555714Skris * The word 'cryptographic' can be left out if the rouines from the library 3655714Skris * being used are not cryptographic related :-). 3755714Skris * 4. If you include any Windows specific code (or a derivative thereof) from 3855714Skris * the apps directory (application code) you must include an acknowledgement: 3955714Skris * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 4055714Skris * 4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4455714Skris * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5155714Skris * SUCH DAMAGE. 5255714Skris * 5355714Skris * The licence and distribution terms for any publically available version or 5455714Skris * derivative of this code cannot be changed. i.e. this code cannot simply be 5555714Skris * copied and put under another distribution licence 5655714Skris * [including the GNU Public Licence.] 5755714Skris */ 5855714Skris 5955714Skris#ifndef HEADER_BIO_H 6055714Skris#define HEADER_BIO_H 6155714Skris 6268651Skris#ifndef NO_FP_API 6368651Skris# include <stdio.h> 6468651Skris#endif 6568651Skris#include <stdarg.h> 6668651Skris 6768651Skris#include <openssl/crypto.h> 6868651Skris 6955714Skris#ifdef __cplusplus 7055714Skrisextern "C" { 7155714Skris#endif 7255714Skris 7355714Skris/* These are the 'types' of BIOs */ 7455714Skris#define BIO_TYPE_NONE 0 7555714Skris#define BIO_TYPE_MEM (1|0x0400) 7655714Skris#define BIO_TYPE_FILE (2|0x0400) 7755714Skris 7855714Skris#define BIO_TYPE_FD (4|0x0400|0x0100) 7955714Skris#define BIO_TYPE_SOCKET (5|0x0400|0x0100) 8055714Skris#define BIO_TYPE_NULL (6|0x0400) 8155714Skris#define BIO_TYPE_SSL (7|0x0200) 8259191Skris#define BIO_TYPE_MD (8|0x0200) /* passive filter */ 8355714Skris#define BIO_TYPE_BUFFER (9|0x0200) /* filter */ 8455714Skris#define BIO_TYPE_CIPHER (10|0x0200) /* filter */ 8555714Skris#define BIO_TYPE_BASE64 (11|0x0200) /* filter */ 8655714Skris#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ 8755714Skris#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ 8855714Skris#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ 8955714Skris#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ 9055714Skris#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ 9155714Skris#define BIO_TYPE_NULL_FILTER (17|0x0200) 9255714Skris#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ 9355714Skris#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ 9468651Skris#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ 9555714Skris 9655714Skris#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ 9755714Skris#define BIO_TYPE_FILTER 0x0200 9855714Skris#define BIO_TYPE_SOURCE_SINK 0x0400 9955714Skris 10055714Skris/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. 10155714Skris * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ 10255714Skris#define BIO_NOCLOSE 0x00 10355714Skris#define BIO_CLOSE 0x01 10455714Skris 10555714Skris/* These are used in the following macros and are passed to 10655714Skris * BIO_ctrl() */ 10755714Skris#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ 10855714Skris#define BIO_CTRL_EOF 2 /* opt - are we at the eof */ 10955714Skris#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ 11055714Skris#define BIO_CTRL_SET 4 /* man - set the 'IO' type */ 11155714Skris#define BIO_CTRL_GET 5 /* man - get the 'IO' type */ 11255714Skris#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ 11355714Skris#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ 11455714Skris#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ 11555714Skris#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ 11655714Skris#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ 11755714Skris#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ 11855714Skris#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ 11955714Skris#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ 12055714Skris/* callback is int cb(BIO *bio,state,ret); */ 12155714Skris#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ 12255714Skris#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ 12355714Skris 12455714Skris#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ 12555714Skris 12655714Skris/* modifiers */ 12755714Skris#define BIO_FP_READ 0x02 12855714Skris#define BIO_FP_WRITE 0x04 12955714Skris#define BIO_FP_APPEND 0x08 13055714Skris#define BIO_FP_TEXT 0x10 13155714Skris 13255714Skris#define BIO_FLAGS_READ 0x01 13355714Skris#define BIO_FLAGS_WRITE 0x02 13455714Skris#define BIO_FLAGS_IO_SPECIAL 0x04 13555714Skris#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) 13655714Skris#define BIO_FLAGS_SHOULD_RETRY 0x08 13755714Skris 13855714Skris/* Used in BIO_gethostbyname() */ 13955714Skris#define BIO_GHBN_CTRL_HITS 1 14055714Skris#define BIO_GHBN_CTRL_MISSES 2 14155714Skris#define BIO_GHBN_CTRL_CACHE_SIZE 3 14255714Skris#define BIO_GHBN_CTRL_GET_ENTRY 4 14355714Skris#define BIO_GHBN_CTRL_FLUSH 5 14455714Skris 14555714Skris/* Mostly used in the SSL BIO */ 14655714Skris/* Not used anymore 14755714Skris * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 14855714Skris * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 14955714Skris * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 15055714Skris */ 15155714Skris 15255714Skris#define BIO_FLAGS_BASE64_NO_NL 0x100 15355714Skris 15459191Skris/* This is used with memory BIOs: it means we shouldn't free up or change the 15559191Skris * data in any way. 15659191Skris */ 15759191Skris#define BIO_FLAGS_MEM_RDONLY 0x200 15859191Skris 15955714Skris#define BIO_set_flags(b,f) ((b)->flags|=(f)) 16055714Skris#define BIO_get_flags(b) ((b)->flags) 16155714Skris#define BIO_set_retry_special(b) \ 16255714Skris ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) 16355714Skris#define BIO_set_retry_read(b) \ 16455714Skris ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) 16555714Skris#define BIO_set_retry_write(b) \ 16655714Skris ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) 16755714Skris 16855714Skris/* These are normally used internally in BIOs */ 16955714Skris#define BIO_clear_flags(b,f) ((b)->flags&= ~(f)) 17055714Skris#define BIO_clear_retry_flags(b) \ 17155714Skris ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 17255714Skris#define BIO_get_retry_flags(b) \ 17355714Skris ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 17455714Skris 17559191Skris/* These should be used by the application to tell why we should retry */ 17655714Skris#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) 17755714Skris#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) 17855714Skris#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) 17955714Skris#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS) 18055714Skris#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY) 18155714Skris 18255714Skris/* The next two are used in conjunction with the 18355714Skris * BIO_should_io_special() condition. After this returns true, 18455714Skris * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO 18555714Skris * stack and return the 'reason' for the special and the offending BIO. 18655714Skris * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ 18755714Skris/* Returned from the SSL bio when the certificate retrieval code had an error */ 18855714Skris#define BIO_RR_SSL_X509_LOOKUP 0x01 18955714Skris/* Returned from the connect BIO when a connect would have blocked */ 19055714Skris#define BIO_RR_CONNECT 0x02 19155714Skris 19255714Skris/* These are passed by the BIO callback */ 19355714Skris#define BIO_CB_FREE 0x01 19455714Skris#define BIO_CB_READ 0x02 19555714Skris#define BIO_CB_WRITE 0x03 19655714Skris#define BIO_CB_PUTS 0x04 19755714Skris#define BIO_CB_GETS 0x05 19855714Skris#define BIO_CB_CTRL 0x06 19955714Skris 20055714Skris/* The callback is called before and after the underling operation, 20155714Skris * The BIO_CB_RETURN flag indicates if it is after the call */ 20255714Skris#define BIO_CB_RETURN 0x80 20355714Skris#define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) 20455714Skris#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) 20555714Skris#define BIO_cb_post(a) ((a)&BIO_CB_RETURN) 20655714Skris 20755714Skris#define BIO_set_callback(b,cb) ((b)->callback=(cb)) 20855714Skris#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg)) 20955714Skris#define BIO_get_callback_arg(b) ((b)->cb_arg) 21055714Skris#define BIO_get_callback(b) ((b)->callback) 21155714Skris#define BIO_method_name(b) ((b)->method->name) 21255714Skris#define BIO_method_type(b) ((b)->method->type) 21355714Skris 21468651Skristypedef struct bio_st BIO; 21568651Skris 21668651Skristypedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); 21768651Skris 21855714Skris#ifndef WIN16 21955714Skristypedef struct bio_method_st 22055714Skris { 22155714Skris int type; 22255714Skris const char *name; 22368651Skris int (*bwrite)(BIO *, const char *, int); 22468651Skris int (*bread)(BIO *, char *, int); 22568651Skris int (*bputs)(BIO *, const char *); 22668651Skris int (*bgets)(BIO *, char *, int); 22768651Skris long (*ctrl)(BIO *, int, long, void *); 22868651Skris int (*create)(BIO *); 22968651Skris int (*destroy)(BIO *); 23068651Skris long (*callback_ctrl)(BIO *, int, bio_info_cb *); 23155714Skris } BIO_METHOD; 23255714Skris#else 23355714Skristypedef struct bio_method_st 23455714Skris { 23555714Skris int type; 23655714Skris const char *name; 23755714Skris int (_far *bwrite)(); 23855714Skris int (_far *bread)(); 23955714Skris int (_far *bputs)(); 24055714Skris int (_far *bgets)(); 24155714Skris long (_far *ctrl)(); 24255714Skris int (_far *create)(); 24355714Skris int (_far *destroy)(); 24459191Skris long (_fat *callback_ctrl)(); 24555714Skris } BIO_METHOD; 24655714Skris#endif 24755714Skris 24868651Skrisstruct bio_st 24955714Skris { 25055714Skris BIO_METHOD *method; 25155714Skris /* bio, mode, argp, argi, argl, ret */ 25255714Skris long (*callback)(struct bio_st *,int,const char *,int, long,long); 25355714Skris char *cb_arg; /* first argument for the callback */ 25455714Skris 25555714Skris int init; 25655714Skris int shutdown; 25755714Skris int flags; /* extra storage */ 25855714Skris int retry_reason; 25955714Skris int num; 26055714Skris void *ptr; 26155714Skris struct bio_st *next_bio; /* used by filter BIOs */ 26255714Skris struct bio_st *prev_bio; /* used by filter BIOs */ 26355714Skris int references; 26455714Skris unsigned long num_read; 26555714Skris unsigned long num_write; 26655714Skris 26755714Skris CRYPTO_EX_DATA ex_data; 26868651Skris }; 26955714Skris 27068651SkrisDECLARE_STACK_OF(BIO) 27168651Skris 27255714Skristypedef struct bio_f_buffer_ctx_struct 27355714Skris { 27455714Skris /* BIO *bio; */ /* this is now in the BIO struct */ 27555714Skris int ibuf_size; /* how big is the input buffer */ 27655714Skris int obuf_size; /* how big is the output buffer */ 27755714Skris 27855714Skris char *ibuf; /* the char array */ 27955714Skris int ibuf_len; /* how many bytes are in it */ 28055714Skris int ibuf_off; /* write/read offset */ 28155714Skris 28255714Skris char *obuf; /* the char array */ 28355714Skris int obuf_len; /* how many bytes are in it */ 28455714Skris int obuf_off; /* write/read offset */ 28555714Skris } BIO_F_BUFFER_CTX; 28655714Skris 28755714Skris/* connect BIO stuff */ 28855714Skris#define BIO_CONN_S_BEFORE 1 28955714Skris#define BIO_CONN_S_GET_IP 2 29055714Skris#define BIO_CONN_S_GET_PORT 3 29155714Skris#define BIO_CONN_S_CREATE_SOCKET 4 29255714Skris#define BIO_CONN_S_CONNECT 5 29355714Skris#define BIO_CONN_S_OK 6 29455714Skris#define BIO_CONN_S_BLOCKED_CONNECT 7 29555714Skris#define BIO_CONN_S_NBIO 8 29655714Skris/*#define BIO_CONN_get_param_hostname BIO_ctrl */ 29755714Skris 29855714Skris#define BIO_C_SET_CONNECT 100 29955714Skris#define BIO_C_DO_STATE_MACHINE 101 30055714Skris#define BIO_C_SET_NBIO 102 30155714Skris#define BIO_C_SET_PROXY_PARAM 103 30255714Skris#define BIO_C_SET_FD 104 30355714Skris#define BIO_C_GET_FD 105 30455714Skris#define BIO_C_SET_FILE_PTR 106 30555714Skris#define BIO_C_GET_FILE_PTR 107 30655714Skris#define BIO_C_SET_FILENAME 108 30755714Skris#define BIO_C_SET_SSL 109 30855714Skris#define BIO_C_GET_SSL 110 30955714Skris#define BIO_C_SET_MD 111 31055714Skris#define BIO_C_GET_MD 112 31155714Skris#define BIO_C_GET_CIPHER_STATUS 113 31255714Skris#define BIO_C_SET_BUF_MEM 114 31355714Skris#define BIO_C_GET_BUF_MEM_PTR 115 31455714Skris#define BIO_C_GET_BUFF_NUM_LINES 116 31555714Skris#define BIO_C_SET_BUFF_SIZE 117 31655714Skris#define BIO_C_SET_ACCEPT 118 31755714Skris#define BIO_C_SSL_MODE 119 31855714Skris#define BIO_C_GET_MD_CTX 120 31955714Skris#define BIO_C_GET_PROXY_PARAM 121 32055714Skris#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ 32155714Skris#define BIO_C_GET_CONNECT 123 32255714Skris#define BIO_C_GET_ACCEPT 124 32355714Skris#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 32455714Skris#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 32555714Skris#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 32655714Skris#define BIO_C_FILE_SEEK 128 32755714Skris#define BIO_C_GET_CIPHER_CTX 129 32855714Skris#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ 32955714Skris#define BIO_C_SET_BIND_MODE 131 33055714Skris#define BIO_C_GET_BIND_MODE 132 33155714Skris#define BIO_C_FILE_TELL 133 33255714Skris#define BIO_C_GET_SOCKS 134 33355714Skris#define BIO_C_SET_SOCKS 135 33455714Skris 33555714Skris#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ 33655714Skris#define BIO_C_GET_WRITE_BUF_SIZE 137 33755714Skris#define BIO_C_MAKE_BIO_PAIR 138 33855714Skris#define BIO_C_DESTROY_BIO_PAIR 139 33955714Skris#define BIO_C_GET_WRITE_GUARANTEE 140 34055714Skris#define BIO_C_GET_READ_REQUEST 141 34155714Skris#define BIO_C_SHUTDOWN_WR 142 34259191Skris#define BIO_C_NREAD0 143 34359191Skris#define BIO_C_NREAD 144 34459191Skris#define BIO_C_NWRITE0 145 34559191Skris#define BIO_C_NWRITE 146 34659191Skris#define BIO_C_RESET_READ_REQUEST 147 34755714Skris 34855714Skris 34959191Skris#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,arg) 35055714Skris#define BIO_get_app_data(s) BIO_get_ex_data(s,0) 35155714Skris 35255714Skris/* BIO_s_connect() and BIO_s_socks4a_connect() */ 35355714Skris#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) 35455714Skris#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) 35555714Skris#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) 35655714Skris#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) 35755714Skris#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) 35855714Skris#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) 35955714Skris#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) 36055714Skris#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) 36155714Skris 36255714Skris 36355714Skris#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) 36455714Skris 36555714Skris/* BIO_s_accept_socket() */ 36655714Skris#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) 36755714Skris#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) 36855714Skris/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ 36955714Skris#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) 37055714Skris#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) 37155714Skris 37255714Skris#define BIO_BIND_NORMAL 0 37355714Skris#define BIO_BIND_REUSEADDR_IF_UNUSED 1 37455714Skris#define BIO_BIND_REUSEADDR 2 37555714Skris#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) 37655714Skris#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) 37755714Skris 37855714Skris#define BIO_do_connect(b) BIO_do_handshake(b) 37955714Skris#define BIO_do_accept(b) BIO_do_handshake(b) 38055714Skris#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) 38155714Skris 38255714Skris/* BIO_s_proxy_client() */ 38355714Skris#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) 38455714Skris#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) 38555714Skris/* BIO_set_nbio(b,n) */ 38655714Skris#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) 38755714Skris/* BIO *BIO_get_filter_bio(BIO *bio); */ 38859191Skris#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)())) 38955714Skris#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) 39055714Skris#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) 39155714Skris 39255714Skris#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) 39355714Skris#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) 39455714Skris#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) 39555714Skris#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) 39655714Skris 39755714Skris#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) 39855714Skris#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) 39955714Skris 40055714Skris#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) 40155714Skris#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) 40255714Skris 40355714Skris#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) 40455714Skris#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) 40555714Skris 40655714Skris/* name is cast to lose const, but might be better to route through a function 40755714Skris so we can do it safely */ 40855714Skris#ifdef CONST_STRICT 40955714Skris/* If you are wondering why this isn't defined, its because CONST_STRICT is 41055714Skris * purely a compile-time kludge to allow const to be checked. 41155714Skris */ 41255714Skrisint BIO_read_filename(BIO *b,const char *name); 41355714Skris#else 41455714Skris#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 41555714Skris BIO_CLOSE|BIO_FP_READ,(char *)name) 41655714Skris#endif 41755714Skris#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 41855714Skris BIO_CLOSE|BIO_FP_WRITE,name) 41955714Skris#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 42055714Skris BIO_CLOSE|BIO_FP_APPEND,name) 42155714Skris#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 42255714Skris BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) 42355714Skris 42455714Skris/* WARNING WARNING, this ups the reference count on the read bio of the 42555714Skris * SSL structure. This is because the ssl read BIO is now pointed to by 42655714Skris * the next_bio field in the bio. So when you free the BIO, make sure 42755714Skris * you are doing a BIO_free_all() to catch the underlying BIO. */ 42855714Skris#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) 42955714Skris#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) 43055714Skris#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) 43155714Skris#define BIO_set_ssl_renegotiate_bytes(b,num) \ 43255714Skris BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); 43355714Skris#define BIO_get_num_renegotiates(b) \ 43455714Skris BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL); 43555714Skris#define BIO_set_ssl_renegotiate_timeout(b,seconds) \ 43655714Skris BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); 43755714Skris 43855714Skris/* defined in evp.h */ 43955714Skris/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ 44055714Skris 44155714Skris#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) 44255714Skris#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) 44355714Skris#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) 44455714Skris#define BIO_set_mem_eof_return(b,v) \ 44555714Skris BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) 44655714Skris 44755714Skris/* For the BIO_f_buffer() type */ 44855714Skris#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) 44955714Skris#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) 45055714Skris#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) 45155714Skris#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) 45255714Skris#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) 45355714Skris 45455714Skris/* Don't use the next one unless you know what you are doing :-) */ 45555714Skris#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) 45655714Skris 45755714Skris#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) 45855714Skris#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) 45955714Skris#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) 46055714Skris#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) 46155714Skris#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) 46255714Skris#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) 46355714Skris/* ...pending macros have inappropriate return type */ 46455714Skrissize_t BIO_ctrl_pending(BIO *b); 46555714Skrissize_t BIO_ctrl_wpending(BIO *b); 46655714Skris#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) 46768651Skris#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(bio_info_cb **)(cbp)) 46868651Skris#define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,(bio_info_cb *)(cb)) 46955714Skris 47055714Skris/* For the BIO_f_buffer() type */ 47155714Skris#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) 47255714Skris 47355714Skris/* For BIO_s_bio() */ 47455714Skris#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) 47555714Skris#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) 47655714Skris#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) 47755714Skris#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) 47868651Skris#define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL) 47955714Skris/* macros with inappropriate type -- but ...pending macros use int too: */ 48055714Skris#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) 48155714Skris#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) 48255714Skrissize_t BIO_ctrl_get_write_guarantee(BIO *b); 48355714Skrissize_t BIO_ctrl_get_read_request(BIO *b); 48459191Skrisint BIO_ctrl_reset_read_request(BIO *b); 48555714Skris 48655714Skris/* These two aren't currently implemented */ 48755714Skris/* int BIO_get_ex_num(BIO *bio); */ 48855714Skris/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ 48959191Skrisint BIO_set_ex_data(BIO *bio,int idx,void *data); 49059191Skrisvoid *BIO_get_ex_data(BIO *bio,int idx); 49159191Skrisint BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 49259191Skris CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 49359191Skrisunsigned long BIO_number_read(BIO *bio); 49459191Skrisunsigned long BIO_number_written(BIO *bio); 49555714Skris 49668651Skris# ifndef NO_FP_API 49755714Skris# if defined(WIN16) && defined(_WINDLL) 49855714SkrisBIO_METHOD *BIO_s_file_internal(void); 49955714SkrisBIO *BIO_new_file_internal(char *filename, char *mode); 50055714SkrisBIO *BIO_new_fp_internal(FILE *stream, int close_flag); 50155714Skris# define BIO_s_file BIO_s_file_internal 50255714Skris# define BIO_new_file BIO_new_file_internal 50355714Skris# define BIO_new_fp BIO_new_fp_internal 50455714Skris# else /* FP_API */ 50555714SkrisBIO_METHOD *BIO_s_file(void ); 50655714SkrisBIO *BIO_new_file(const char *filename, const char *mode); 50755714SkrisBIO *BIO_new_fp(FILE *stream, int close_flag); 50855714Skris# define BIO_s_file_internal BIO_s_file 50955714Skris# define BIO_new_file_internal BIO_new_file 51055714Skris# define BIO_new_fp_internal BIO_s_file 51155714Skris# endif /* FP_API */ 51268651Skris# endif 51355714SkrisBIO * BIO_new(BIO_METHOD *type); 51455714Skrisint BIO_set(BIO *a,BIO_METHOD *type); 51555714Skrisint BIO_free(BIO *a); 51668651Skrisvoid BIO_vfree(BIO *a); 51755714Skrisint BIO_read(BIO *b, void *data, int len); 51855714Skrisint BIO_gets(BIO *bp,char *buf, int size); 51959191Skrisint BIO_write(BIO *b, const void *data, int len); 52055714Skrisint BIO_puts(BIO *bp,const char *buf); 52155714Skrislong BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); 52268651Skrislong BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); 52355714Skrischar * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); 52455714Skrislong BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); 52555714SkrisBIO * BIO_push(BIO *b,BIO *append); 52655714SkrisBIO * BIO_pop(BIO *b); 52755714Skrisvoid BIO_free_all(BIO *a); 52855714SkrisBIO * BIO_find_type(BIO *b,int bio_type); 52968651SkrisBIO * BIO_next(BIO *b); 53055714SkrisBIO * BIO_get_retry_BIO(BIO *bio, int *reason); 53155714Skrisint BIO_get_retry_reason(BIO *bio); 53255714SkrisBIO * BIO_dup_chain(BIO *in); 53355714Skris 53459191Skrisint BIO_nread0(BIO *bio, char **buf); 53559191Skrisint BIO_nread(BIO *bio, char **buf, int num); 53659191Skrisint BIO_nwrite0(BIO *bio, char **buf); 53759191Skrisint BIO_nwrite(BIO *bio, char **buf, int num); 53859191Skris 53955714Skris#ifndef WIN16 54055714Skrislong BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, 54155714Skris long argl,long ret); 54255714Skris#else 54355714Skrislong _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, 54455714Skris long argl,long ret); 54555714Skris#endif 54655714Skris 54755714SkrisBIO_METHOD *BIO_s_mem(void); 54859191SkrisBIO *BIO_new_mem_buf(void *buf, int len); 54955714SkrisBIO_METHOD *BIO_s_socket(void); 55055714SkrisBIO_METHOD *BIO_s_connect(void); 55155714SkrisBIO_METHOD *BIO_s_accept(void); 55255714SkrisBIO_METHOD *BIO_s_fd(void); 55355714SkrisBIO_METHOD *BIO_s_log(void); 55455714SkrisBIO_METHOD *BIO_s_bio(void); 55555714SkrisBIO_METHOD *BIO_s_null(void); 55655714SkrisBIO_METHOD *BIO_f_null(void); 55755714SkrisBIO_METHOD *BIO_f_buffer(void); 55868651Skris#ifdef VMS 55968651SkrisBIO_METHOD *BIO_f_linebuffer(void); 56068651Skris#endif 56155714SkrisBIO_METHOD *BIO_f_nbio_test(void); 56255714Skris/* BIO_METHOD *BIO_f_ber(void); */ 56355714Skris 56455714Skrisint BIO_sock_should_retry(int i); 56555714Skrisint BIO_sock_non_fatal_error(int error); 56655714Skrisint BIO_fd_should_retry(int i); 56755714Skrisint BIO_fd_non_fatal_error(int error); 56855714Skrisint BIO_dump(BIO *b,const char *bytes,int len); 56968651Skrisint BIO_dump_indent(BIO *b,const char *bytes,int len,int indent); 57055714Skris 57155714Skrisstruct hostent *BIO_gethostbyname(const char *name); 57255714Skris/* We might want a thread-safe interface too: 57355714Skris * struct hostent *BIO_gethostbyname_r(const char *name, 57455714Skris * struct hostent *result, void *buffer, size_t buflen); 57555714Skris * or something similar (caller allocates a struct hostent, 57655714Skris * pointed to by "result", and additional buffer space for the various 57755714Skris * substructures; if the buffer does not suffice, NULL is returned 57855714Skris * and an appropriate error code is set). 57955714Skris */ 58055714Skrisint BIO_sock_error(int sock); 58155714Skrisint BIO_socket_ioctl(int fd, long type, unsigned long *arg); 58255714Skrisint BIO_socket_nbio(int fd,int mode); 58355714Skrisint BIO_get_port(const char *str, unsigned short *port_ptr); 58455714Skrisint BIO_get_host_ip(const char *str, unsigned char *ip); 58555714Skrisint BIO_get_accept_socket(char *host_port,int mode); 58655714Skrisint BIO_accept(int sock,char **ip_port); 58755714Skrisint BIO_sock_init(void ); 58855714Skrisvoid BIO_sock_cleanup(void); 58955714Skrisint BIO_set_tcp_ndelay(int sock,int turn_on); 59055714Skris 59155714Skrisvoid ERR_load_BIO_strings(void ); 59255714Skris 59355714SkrisBIO *BIO_new_socket(int sock, int close_flag); 59455714SkrisBIO *BIO_new_fd(int fd, int close_flag); 59555714SkrisBIO *BIO_new_connect(char *host_port); 59655714SkrisBIO *BIO_new_accept(char *host_port); 59755714Skris 59855714Skrisint BIO_new_bio_pair(BIO **bio1, size_t writebuf1, 59955714Skris BIO **bio2, size_t writebuf2); 60055714Skris/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. 60155714Skris * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. 60255714Skris * Size 0 uses default value. 60355714Skris */ 60455714Skris 60555714Skrisvoid BIO_copy_next_retry(BIO *b); 60655714Skris 60755714Skrislong BIO_ghbn_ctrl(int cmd,int iarg,char *parg); 60855714Skris 60968651Skrisint BIO_printf(BIO *bio, const char *format, ...); 61068651Skrisint BIO_vprintf(BIO *bio, const char *format, va_list args); 61168651Skrisint BIO_snprintf(char *buf, size_t n, const char *format, ...); 61268651Skrisint BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args); 61355714Skris 61455714Skris/* BEGIN ERROR CODES */ 61555714Skris/* The following lines are auto generated by the script mkerr.pl. Any changes 61655714Skris * made after this point may be overwritten when the script is next run. 61755714Skris */ 61855714Skris 61955714Skris/* Error codes for the BIO functions. */ 62055714Skris 62155714Skris/* Function codes. */ 62255714Skris#define BIO_F_ACPT_STATE 100 62355714Skris#define BIO_F_BIO_ACCEPT 101 62455714Skris#define BIO_F_BIO_BER_GET_HEADER 102 62555714Skris#define BIO_F_BIO_CTRL 103 62655714Skris#define BIO_F_BIO_GETHOSTBYNAME 120 62755714Skris#define BIO_F_BIO_GETS 104 62855714Skris#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 62955714Skris#define BIO_F_BIO_GET_HOST_IP 106 63055714Skris#define BIO_F_BIO_GET_PORT 107 63155714Skris#define BIO_F_BIO_MAKE_PAIR 121 63255714Skris#define BIO_F_BIO_NEW 108 63355714Skris#define BIO_F_BIO_NEW_FILE 109 63459191Skris#define BIO_F_BIO_NEW_MEM_BUF 126 63559191Skris#define BIO_F_BIO_NREAD 123 63659191Skris#define BIO_F_BIO_NREAD0 124 63759191Skris#define BIO_F_BIO_NWRITE 125 63859191Skris#define BIO_F_BIO_NWRITE0 122 63955714Skris#define BIO_F_BIO_PUTS 110 64055714Skris#define BIO_F_BIO_READ 111 64155714Skris#define BIO_F_BIO_SOCK_INIT 112 64255714Skris#define BIO_F_BIO_WRITE 113 64355714Skris#define BIO_F_BUFFER_CTRL 114 64459191Skris#define BIO_F_CONN_CTRL 127 64555714Skris#define BIO_F_CONN_STATE 115 64655714Skris#define BIO_F_FILE_CTRL 116 64768651Skris#define BIO_F_LINEBUFFER_CTRL 129 64868651Skris#define BIO_F_MEM_READ 128 64955714Skris#define BIO_F_MEM_WRITE 117 65055714Skris#define BIO_F_SSL_NEW 118 65155714Skris#define BIO_F_WSASTARTUP 119 65255714Skris 65355714Skris/* Reason codes. */ 65455714Skris#define BIO_R_ACCEPT_ERROR 100 65555714Skris#define BIO_R_BAD_FOPEN_MODE 101 65655714Skris#define BIO_R_BAD_HOSTNAME_LOOKUP 102 65755714Skris#define BIO_R_BROKEN_PIPE 124 65855714Skris#define BIO_R_CONNECT_ERROR 103 65968651Skris#define BIO_R_EOF_ON_MEMORY_BIO 127 66055714Skris#define BIO_R_ERROR_SETTING_NBIO 104 66155714Skris#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 66255714Skris#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 66355714Skris#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 66455714Skris#define BIO_R_INVALID_ARGUMENT 125 66555714Skris#define BIO_R_INVALID_IP_ADDRESS 108 66655714Skris#define BIO_R_IN_USE 123 66755714Skris#define BIO_R_KEEPALIVE 109 66855714Skris#define BIO_R_NBIO_CONNECT_ERROR 110 66955714Skris#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 67055714Skris#define BIO_R_NO_HOSTNAME_SPECIFIED 112 67155714Skris#define BIO_R_NO_PORT_DEFINED 113 67255714Skris#define BIO_R_NO_PORT_SPECIFIED 114 67355714Skris#define BIO_R_NULL_PARAMETER 115 67455714Skris#define BIO_R_TAG_MISMATCH 116 67555714Skris#define BIO_R_UNABLE_TO_BIND_SOCKET 117 67655714Skris#define BIO_R_UNABLE_TO_CREATE_SOCKET 118 67755714Skris#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 67855714Skris#define BIO_R_UNINITIALIZED 120 67955714Skris#define BIO_R_UNSUPPORTED_METHOD 121 68059191Skris#define BIO_R_WRITE_TO_READ_ONLY_BIO 126 68155714Skris#define BIO_R_WSASTARTUP 122 68255714Skris 68355714Skris#ifdef __cplusplus 68455714Skris} 68555714Skris#endif 68655714Skris#endif 68755714Skris 688