bio.h revision 55714
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 6255714Skris#ifdef __cplusplus 6355714Skrisextern "C" { 6455714Skris#endif 6555714Skris 6655714Skris#include <stdio.h> 6755714Skris#include <stdlib.h> 6855714Skris#include <openssl/crypto.h> 6955714Skris 7055714Skris/* These are the 'types' of BIOs */ 7155714Skris#define BIO_TYPE_NONE 0 7255714Skris#define BIO_TYPE_MEM (1|0x0400) 7355714Skris#define BIO_TYPE_FILE (2|0x0400) 7455714Skris 7555714Skris#define BIO_TYPE_FD (4|0x0400|0x0100) 7655714Skris#define BIO_TYPE_SOCKET (5|0x0400|0x0100) 7755714Skris#define BIO_TYPE_NULL (6|0x0400) 7855714Skris#define BIO_TYPE_SSL (7|0x0200) 7955714Skris#define BIO_TYPE_MD (8|0x0200) /* pasive filter */ 8055714Skris#define BIO_TYPE_BUFFER (9|0x0200) /* filter */ 8155714Skris#define BIO_TYPE_CIPHER (10|0x0200) /* filter */ 8255714Skris#define BIO_TYPE_BASE64 (11|0x0200) /* filter */ 8355714Skris#define BIO_TYPE_CONNECT (12|0x0400|0x0100) /* socket - connect */ 8455714Skris#define BIO_TYPE_ACCEPT (13|0x0400|0x0100) /* socket for accept */ 8555714Skris#define BIO_TYPE_PROXY_CLIENT (14|0x0200) /* client proxy BIO */ 8655714Skris#define BIO_TYPE_PROXY_SERVER (15|0x0200) /* server proxy BIO */ 8755714Skris#define BIO_TYPE_NBIO_TEST (16|0x0200) /* server proxy BIO */ 8855714Skris#define BIO_TYPE_NULL_FILTER (17|0x0200) 8955714Skris#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ 9055714Skris#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ 9155714Skris 9255714Skris#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ 9355714Skris#define BIO_TYPE_FILTER 0x0200 9455714Skris#define BIO_TYPE_SOURCE_SINK 0x0400 9555714Skris 9655714Skris/* BIO_FILENAME_READ|BIO_CLOSE to open or close on free. 9755714Skris * BIO_set_fp(in,stdin,BIO_NOCLOSE); */ 9855714Skris#define BIO_NOCLOSE 0x00 9955714Skris#define BIO_CLOSE 0x01 10055714Skris 10155714Skris/* These are used in the following macros and are passed to 10255714Skris * BIO_ctrl() */ 10355714Skris#define BIO_CTRL_RESET 1 /* opt - rewind/zero etc */ 10455714Skris#define BIO_CTRL_EOF 2 /* opt - are we at the eof */ 10555714Skris#define BIO_CTRL_INFO 3 /* opt - extra tit-bits */ 10655714Skris#define BIO_CTRL_SET 4 /* man - set the 'IO' type */ 10755714Skris#define BIO_CTRL_GET 5 /* man - get the 'IO' type */ 10855714Skris#define BIO_CTRL_PUSH 6 /* opt - internal, used to signify change */ 10955714Skris#define BIO_CTRL_POP 7 /* opt - internal, used to signify change */ 11055714Skris#define BIO_CTRL_GET_CLOSE 8 /* man - set the 'close' on free */ 11155714Skris#define BIO_CTRL_SET_CLOSE 9 /* man - set the 'close' on free */ 11255714Skris#define BIO_CTRL_PENDING 10 /* opt - is their more data buffered */ 11355714Skris#define BIO_CTRL_FLUSH 11 /* opt - 'flush' buffered output */ 11455714Skris#define BIO_CTRL_DUP 12 /* man - extra stuff for 'duped' BIO */ 11555714Skris#define BIO_CTRL_WPENDING 13 /* opt - number of bytes still to write */ 11655714Skris/* callback is int cb(BIO *bio,state,ret); */ 11755714Skris#define BIO_CTRL_SET_CALLBACK 14 /* opt - set callback function */ 11855714Skris#define BIO_CTRL_GET_CALLBACK 15 /* opt - set callback function */ 11955714Skris 12055714Skris#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ 12155714Skris 12255714Skris/* modifiers */ 12355714Skris#define BIO_FP_READ 0x02 12455714Skris#define BIO_FP_WRITE 0x04 12555714Skris#define BIO_FP_APPEND 0x08 12655714Skris#define BIO_FP_TEXT 0x10 12755714Skris 12855714Skris#define BIO_FLAGS_READ 0x01 12955714Skris#define BIO_FLAGS_WRITE 0x02 13055714Skris#define BIO_FLAGS_IO_SPECIAL 0x04 13155714Skris#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) 13255714Skris#define BIO_FLAGS_SHOULD_RETRY 0x08 13355714Skris 13455714Skris/* Used in BIO_gethostbyname() */ 13555714Skris#define BIO_GHBN_CTRL_HITS 1 13655714Skris#define BIO_GHBN_CTRL_MISSES 2 13755714Skris#define BIO_GHBN_CTRL_CACHE_SIZE 3 13855714Skris#define BIO_GHBN_CTRL_GET_ENTRY 4 13955714Skris#define BIO_GHBN_CTRL_FLUSH 5 14055714Skris 14155714Skris/* Mostly used in the SSL BIO */ 14255714Skris/* Not used anymore 14355714Skris * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10 14455714Skris * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20 14555714Skris * #define BIO_FLAGS_PROTOCOL_STARTUP 0x40 14655714Skris */ 14755714Skris 14855714Skris#define BIO_FLAGS_BASE64_NO_NL 0x100 14955714Skris 15055714Skris#define BIO_set_flags(b,f) ((b)->flags|=(f)) 15155714Skris#define BIO_get_flags(b) ((b)->flags) 15255714Skris#define BIO_set_retry_special(b) \ 15355714Skris ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) 15455714Skris#define BIO_set_retry_read(b) \ 15555714Skris ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) 15655714Skris#define BIO_set_retry_write(b) \ 15755714Skris ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) 15855714Skris 15955714Skris/* These are normally used internally in BIOs */ 16055714Skris#define BIO_clear_flags(b,f) ((b)->flags&= ~(f)) 16155714Skris#define BIO_clear_retry_flags(b) \ 16255714Skris ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 16355714Skris#define BIO_get_retry_flags(b) \ 16455714Skris ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 16555714Skris 16655714Skris/* These shouldbe used by the application to tell why we should retry */ 16755714Skris#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ) 16855714Skris#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE) 16955714Skris#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL) 17055714Skris#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS) 17155714Skris#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY) 17255714Skris 17355714Skris/* The next two are used in conjunction with the 17455714Skris * BIO_should_io_special() condition. After this returns true, 17555714Skris * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO 17655714Skris * stack and return the 'reason' for the special and the offending BIO. 17755714Skris * Given a BIO, BIO_get_retry_reason(bio) will return the code. */ 17855714Skris/* Returned from the SSL bio when the certificate retrieval code had an error */ 17955714Skris#define BIO_RR_SSL_X509_LOOKUP 0x01 18055714Skris/* Returned from the connect BIO when a connect would have blocked */ 18155714Skris#define BIO_RR_CONNECT 0x02 18255714Skris 18355714Skris/* These are passed by the BIO callback */ 18455714Skris#define BIO_CB_FREE 0x01 18555714Skris#define BIO_CB_READ 0x02 18655714Skris#define BIO_CB_WRITE 0x03 18755714Skris#define BIO_CB_PUTS 0x04 18855714Skris#define BIO_CB_GETS 0x05 18955714Skris#define BIO_CB_CTRL 0x06 19055714Skris 19155714Skris/* The callback is called before and after the underling operation, 19255714Skris * The BIO_CB_RETURN flag indicates if it is after the call */ 19355714Skris#define BIO_CB_RETURN 0x80 19455714Skris#define BIO_CB_return(a) ((a)|BIO_CB_RETURN)) 19555714Skris#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) 19655714Skris#define BIO_cb_post(a) ((a)&BIO_CB_RETURN) 19755714Skris 19855714Skris#define BIO_set_callback(b,cb) ((b)->callback=(cb)) 19955714Skris#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg)) 20055714Skris#define BIO_get_callback_arg(b) ((b)->cb_arg) 20155714Skris#define BIO_get_callback(b) ((b)->callback) 20255714Skris#define BIO_method_name(b) ((b)->method->name) 20355714Skris#define BIO_method_type(b) ((b)->method->type) 20455714Skris 20555714Skris#ifndef WIN16 20655714Skristypedef struct bio_method_st 20755714Skris { 20855714Skris int type; 20955714Skris const char *name; 21055714Skris int (*bwrite)(); 21155714Skris int (*bread)(); 21255714Skris int (*bputs)(); 21355714Skris int (*bgets)(); 21455714Skris long (*ctrl)(); 21555714Skris int (*create)(); 21655714Skris int (*destroy)(); 21755714Skris } BIO_METHOD; 21855714Skris#else 21955714Skristypedef struct bio_method_st 22055714Skris { 22155714Skris int type; 22255714Skris const char *name; 22355714Skris int (_far *bwrite)(); 22455714Skris int (_far *bread)(); 22555714Skris int (_far *bputs)(); 22655714Skris int (_far *bgets)(); 22755714Skris long (_far *ctrl)(); 22855714Skris int (_far *create)(); 22955714Skris int (_far *destroy)(); 23055714Skris } BIO_METHOD; 23155714Skris#endif 23255714Skris 23355714Skristypedef struct bio_st 23455714Skris { 23555714Skris BIO_METHOD *method; 23655714Skris /* bio, mode, argp, argi, argl, ret */ 23755714Skris long (*callback)(struct bio_st *,int,const char *,int, long,long); 23855714Skris char *cb_arg; /* first argument for the callback */ 23955714Skris 24055714Skris int init; 24155714Skris int shutdown; 24255714Skris int flags; /* extra storage */ 24355714Skris int retry_reason; 24455714Skris int num; 24555714Skris void *ptr; 24655714Skris struct bio_st *next_bio; /* used by filter BIOs */ 24755714Skris struct bio_st *prev_bio; /* used by filter BIOs */ 24855714Skris int references; 24955714Skris unsigned long num_read; 25055714Skris unsigned long num_write; 25155714Skris 25255714Skris CRYPTO_EX_DATA ex_data; 25355714Skris } BIO; 25455714Skris 25555714Skristypedef struct bio_f_buffer_ctx_struct 25655714Skris { 25755714Skris /* BIO *bio; */ /* this is now in the BIO struct */ 25855714Skris int ibuf_size; /* how big is the input buffer */ 25955714Skris int obuf_size; /* how big is the output buffer */ 26055714Skris 26155714Skris char *ibuf; /* the char array */ 26255714Skris int ibuf_len; /* how many bytes are in it */ 26355714Skris int ibuf_off; /* write/read offset */ 26455714Skris 26555714Skris char *obuf; /* the char array */ 26655714Skris int obuf_len; /* how many bytes are in it */ 26755714Skris int obuf_off; /* write/read offset */ 26855714Skris } BIO_F_BUFFER_CTX; 26955714Skris 27055714Skris/* connect BIO stuff */ 27155714Skris#define BIO_CONN_S_BEFORE 1 27255714Skris#define BIO_CONN_S_GET_IP 2 27355714Skris#define BIO_CONN_S_GET_PORT 3 27455714Skris#define BIO_CONN_S_CREATE_SOCKET 4 27555714Skris#define BIO_CONN_S_CONNECT 5 27655714Skris#define BIO_CONN_S_OK 6 27755714Skris#define BIO_CONN_S_BLOCKED_CONNECT 7 27855714Skris#define BIO_CONN_S_NBIO 8 27955714Skris/*#define BIO_CONN_get_param_hostname BIO_ctrl */ 28055714Skris 28155714Skris#define BIO_number_read(b) ((b)->num_read) 28255714Skris#define BIO_number_written(b) ((b)->num_write) 28355714Skris 28455714Skris#define BIO_C_SET_CONNECT 100 28555714Skris#define BIO_C_DO_STATE_MACHINE 101 28655714Skris#define BIO_C_SET_NBIO 102 28755714Skris#define BIO_C_SET_PROXY_PARAM 103 28855714Skris#define BIO_C_SET_FD 104 28955714Skris#define BIO_C_GET_FD 105 29055714Skris#define BIO_C_SET_FILE_PTR 106 29155714Skris#define BIO_C_GET_FILE_PTR 107 29255714Skris#define BIO_C_SET_FILENAME 108 29355714Skris#define BIO_C_SET_SSL 109 29455714Skris#define BIO_C_GET_SSL 110 29555714Skris#define BIO_C_SET_MD 111 29655714Skris#define BIO_C_GET_MD 112 29755714Skris#define BIO_C_GET_CIPHER_STATUS 113 29855714Skris#define BIO_C_SET_BUF_MEM 114 29955714Skris#define BIO_C_GET_BUF_MEM_PTR 115 30055714Skris#define BIO_C_GET_BUFF_NUM_LINES 116 30155714Skris#define BIO_C_SET_BUFF_SIZE 117 30255714Skris#define BIO_C_SET_ACCEPT 118 30355714Skris#define BIO_C_SSL_MODE 119 30455714Skris#define BIO_C_GET_MD_CTX 120 30555714Skris#define BIO_C_GET_PROXY_PARAM 121 30655714Skris#define BIO_C_SET_BUFF_READ_DATA 122 /* data to read first */ 30755714Skris#define BIO_C_GET_CONNECT 123 30855714Skris#define BIO_C_GET_ACCEPT 124 30955714Skris#define BIO_C_SET_SSL_RENEGOTIATE_BYTES 125 31055714Skris#define BIO_C_GET_SSL_NUM_RENEGOTIATES 126 31155714Skris#define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT 127 31255714Skris#define BIO_C_FILE_SEEK 128 31355714Skris#define BIO_C_GET_CIPHER_CTX 129 31455714Skris#define BIO_C_SET_BUF_MEM_EOF_RETURN 130/*return end of input value*/ 31555714Skris#define BIO_C_SET_BIND_MODE 131 31655714Skris#define BIO_C_GET_BIND_MODE 132 31755714Skris#define BIO_C_FILE_TELL 133 31855714Skris#define BIO_C_GET_SOCKS 134 31955714Skris#define BIO_C_SET_SOCKS 135 32055714Skris 32155714Skris#define BIO_C_SET_WRITE_BUF_SIZE 136/* for BIO_s_bio */ 32255714Skris#define BIO_C_GET_WRITE_BUF_SIZE 137 32355714Skris#define BIO_C_MAKE_BIO_PAIR 138 32455714Skris#define BIO_C_DESTROY_BIO_PAIR 139 32555714Skris#define BIO_C_GET_WRITE_GUARANTEE 140 32655714Skris#define BIO_C_GET_READ_REQUEST 141 32755714Skris#define BIO_C_SHUTDOWN_WR 142 32855714Skris 32955714Skris 33055714Skris#define BIO_set_app_data(s,arg) BIO_set_ex_data(s,0,(char *)arg) 33155714Skris#define BIO_get_app_data(s) BIO_get_ex_data(s,0) 33255714Skris 33355714Skris/* BIO_s_connect() and BIO_s_socks4a_connect() */ 33455714Skris#define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name) 33555714Skris#define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port) 33655714Skris#define BIO_set_conn_ip(b,ip) BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip) 33755714Skris#define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port) 33855714Skris#define BIO_get_conn_hostname(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0) 33955714Skris#define BIO_get_conn_port(b) BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1) 34055714Skris#define BIO_get_conn_ip(b,ip) BIO_ptr_ctrl(b,BIO_C_SET_CONNECT,2) 34155714Skris#define BIO_get_conn_int_port(b,port) BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,port) 34255714Skris 34355714Skris 34455714Skris#define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) 34555714Skris 34655714Skris/* BIO_s_accept_socket() */ 34755714Skris#define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name) 34855714Skris#define BIO_get_accept_port(b) BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0) 34955714Skris/* #define BIO_set_nbio(b,n) BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */ 35055714Skris#define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?"a":NULL) 35155714Skris#define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio) 35255714Skris 35355714Skris#define BIO_BIND_NORMAL 0 35455714Skris#define BIO_BIND_REUSEADDR_IF_UNUSED 1 35555714Skris#define BIO_BIND_REUSEADDR 2 35655714Skris#define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL) 35755714Skris#define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL) 35855714Skris 35955714Skris#define BIO_do_connect(b) BIO_do_handshake(b) 36055714Skris#define BIO_do_accept(b) BIO_do_handshake(b) 36155714Skris#define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL) 36255714Skris 36355714Skris/* BIO_s_proxy_client() */ 36455714Skris#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) 36555714Skris#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) 36655714Skris/* BIO_set_nbio(b,n) */ 36755714Skris#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) 36855714Skris/* BIO *BIO_get_filter_bio(BIO *bio); */ 36955714Skris#define BIO_set_proxy_cb(b,cb) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(char *)(cb)) 37055714Skris#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) 37155714Skris#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) 37255714Skris 37355714Skris#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) 37455714Skris#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) 37555714Skris#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) 37655714Skris#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) 37755714Skris 37855714Skris#define BIO_set_fd(b,fd,c) BIO_int_ctrl(b,BIO_C_SET_FD,c,fd) 37955714Skris#define BIO_get_fd(b,c) BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c) 38055714Skris 38155714Skris#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) 38255714Skris#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) 38355714Skris 38455714Skris#define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL) 38555714Skris#define BIO_tell(b) (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL) 38655714Skris 38755714Skris/* name is cast to lose const, but might be better to route through a function 38855714Skris so we can do it safely */ 38955714Skris#ifdef CONST_STRICT 39055714Skris/* If you are wondering why this isn't defined, its because CONST_STRICT is 39155714Skris * purely a compile-time kludge to allow const to be checked. 39255714Skris */ 39355714Skrisint BIO_read_filename(BIO *b,const char *name); 39455714Skris#else 39555714Skris#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 39655714Skris BIO_CLOSE|BIO_FP_READ,(char *)name) 39755714Skris#endif 39855714Skris#define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 39955714Skris BIO_CLOSE|BIO_FP_WRITE,name) 40055714Skris#define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 40155714Skris BIO_CLOSE|BIO_FP_APPEND,name) 40255714Skris#define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \ 40355714Skris BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name) 40455714Skris 40555714Skris/* WARNING WARNING, this ups the reference count on the read bio of the 40655714Skris * SSL structure. This is because the ssl read BIO is now pointed to by 40755714Skris * the next_bio field in the bio. So when you free the BIO, make sure 40855714Skris * you are doing a BIO_free_all() to catch the underlying BIO. */ 40955714Skris#define BIO_set_ssl(b,ssl,c) BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl) 41055714Skris#define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp) 41155714Skris#define BIO_set_ssl_mode(b,client) BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL) 41255714Skris#define BIO_set_ssl_renegotiate_bytes(b,num) \ 41355714Skris BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL); 41455714Skris#define BIO_get_num_renegotiates(b) \ 41555714Skris BIO_ctrl(b,BIO_C_SET_SSL_NUM_RENEGOTIATES,0,NULL); 41655714Skris#define BIO_set_ssl_renegotiate_timeout(b,seconds) \ 41755714Skris BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL); 41855714Skris 41955714Skris/* defined in evp.h */ 42055714Skris/* #define BIO_set_md(b,md) BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */ 42155714Skris 42255714Skris#define BIO_get_mem_data(b,pp) BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp) 42355714Skris#define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm) 42455714Skris#define BIO_get_mem_ptr(b,pp) BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp) 42555714Skris#define BIO_set_mem_eof_return(b,v) \ 42655714Skris BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL) 42755714Skris 42855714Skris/* For the BIO_f_buffer() type */ 42955714Skris#define BIO_get_buffer_num_lines(b) BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL) 43055714Skris#define BIO_set_buffer_size(b,size) BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL) 43155714Skris#define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0) 43255714Skris#define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1) 43355714Skris#define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf) 43455714Skris 43555714Skris/* Don't use the next one unless you know what you are doing :-) */ 43655714Skris#define BIO_dup_state(b,ret) BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret)) 43755714Skris 43855714Skris#define BIO_reset(b) (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL) 43955714Skris#define BIO_eof(b) (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL) 44055714Skris#define BIO_set_close(b,c) (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL) 44155714Skris#define BIO_get_close(b) (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL) 44255714Skris#define BIO_pending(b) (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL) 44355714Skris#define BIO_wpending(b) (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) 44455714Skris/* ...pending macros have inappropriate return type */ 44555714Skrissize_t BIO_ctrl_pending(BIO *b); 44655714Skrissize_t BIO_ctrl_wpending(BIO *b); 44755714Skris#define BIO_flush(b) (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL) 44855714Skris#define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0,(char *)cbp) 44955714Skris#define BIO_set_info_callback(b,cb) (int)BIO_ctrl(b,BIO_CTRL_SET_CALLBACK,0,(char *)cb) 45055714Skris 45155714Skris/* For the BIO_f_buffer() type */ 45255714Skris#define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL) 45355714Skris 45455714Skris/* For BIO_s_bio() */ 45555714Skris#define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL) 45655714Skris#define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL) 45755714Skris#define BIO_make_bio_pair(b1,b2) (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2) 45855714Skris#define BIO_destroy_bio_pair(b) (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL) 45955714Skris/* macros with inappropriate type -- but ...pending macros use int too: */ 46055714Skris#define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL) 46155714Skris#define BIO_get_read_request(b) (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL) 46255714Skrissize_t BIO_ctrl_get_write_guarantee(BIO *b); 46355714Skrissize_t BIO_ctrl_get_read_request(BIO *b); 46455714Skris 46555714Skris 46655714Skris 46755714Skris#ifdef NO_STDIO 46855714Skris#define NO_FP_API 46955714Skris#endif 47055714Skris 47155714Skris 47255714Skris/* These two aren't currently implemented */ 47355714Skris/* int BIO_get_ex_num(BIO *bio); */ 47455714Skris/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ 47555714Skrisint BIO_set_ex_data(BIO *bio,int idx,char *data); 47655714Skrischar *BIO_get_ex_data(BIO *bio,int idx); 47755714Skrisint BIO_get_ex_new_index(long argl, char *argp, int (*new_func)(), 47855714Skris int (*dup_func)(), void (*free_func)()); 47955714Skris 48055714Skris# if defined(WIN16) && defined(_WINDLL) 48155714SkrisBIO_METHOD *BIO_s_file_internal(void); 48255714SkrisBIO *BIO_new_file_internal(char *filename, char *mode); 48355714SkrisBIO *BIO_new_fp_internal(FILE *stream, int close_flag); 48455714Skris# define BIO_s_file BIO_s_file_internal 48555714Skris# define BIO_new_file BIO_new_file_internal 48655714Skris# define BIO_new_fp BIO_new_fp_internal 48755714Skris# else /* FP_API */ 48855714SkrisBIO_METHOD *BIO_s_file(void ); 48955714SkrisBIO *BIO_new_file(const char *filename, const char *mode); 49055714SkrisBIO *BIO_new_fp(FILE *stream, int close_flag); 49155714Skris# define BIO_s_file_internal BIO_s_file 49255714Skris# define BIO_new_file_internal BIO_new_file 49355714Skris# define BIO_new_fp_internal BIO_s_file 49455714Skris# endif /* FP_API */ 49555714SkrisBIO * BIO_new(BIO_METHOD *type); 49655714Skrisint BIO_set(BIO *a,BIO_METHOD *type); 49755714Skrisint BIO_free(BIO *a); 49855714Skrisint BIO_read(BIO *b, void *data, int len); 49955714Skrisint BIO_gets(BIO *bp,char *buf, int size); 50055714Skrisint BIO_write(BIO *b, const char *data, int len); 50155714Skrisint BIO_puts(BIO *bp,const char *buf); 50255714Skrislong BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); 50355714Skrischar * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); 50455714Skrislong BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); 50555714SkrisBIO * BIO_push(BIO *b,BIO *append); 50655714SkrisBIO * BIO_pop(BIO *b); 50755714Skrisvoid BIO_free_all(BIO *a); 50855714SkrisBIO * BIO_find_type(BIO *b,int bio_type); 50955714SkrisBIO * BIO_get_retry_BIO(BIO *bio, int *reason); 51055714Skrisint BIO_get_retry_reason(BIO *bio); 51155714SkrisBIO * BIO_dup_chain(BIO *in); 51255714Skris 51355714Skris#ifndef WIN16 51455714Skrislong BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, 51555714Skris long argl,long ret); 51655714Skris#else 51755714Skrislong _far _loadds BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi, 51855714Skris long argl,long ret); 51955714Skris#endif 52055714Skris 52155714SkrisBIO_METHOD *BIO_s_mem(void); 52255714SkrisBIO_METHOD *BIO_s_socket(void); 52355714SkrisBIO_METHOD *BIO_s_connect(void); 52455714SkrisBIO_METHOD *BIO_s_accept(void); 52555714SkrisBIO_METHOD *BIO_s_fd(void); 52655714SkrisBIO_METHOD *BIO_s_log(void); 52755714SkrisBIO_METHOD *BIO_s_bio(void); 52855714SkrisBIO_METHOD *BIO_s_null(void); 52955714SkrisBIO_METHOD *BIO_f_null(void); 53055714SkrisBIO_METHOD *BIO_f_buffer(void); 53155714SkrisBIO_METHOD *BIO_f_nbio_test(void); 53255714Skris/* BIO_METHOD *BIO_f_ber(void); */ 53355714Skris 53455714Skrisint BIO_sock_should_retry(int i); 53555714Skrisint BIO_sock_non_fatal_error(int error); 53655714Skrisint BIO_fd_should_retry(int i); 53755714Skrisint BIO_fd_non_fatal_error(int error); 53855714Skrisint BIO_dump(BIO *b,const char *bytes,int len); 53955714Skris 54055714Skrisstruct hostent *BIO_gethostbyname(const char *name); 54155714Skris/* We might want a thread-safe interface too: 54255714Skris * struct hostent *BIO_gethostbyname_r(const char *name, 54355714Skris * struct hostent *result, void *buffer, size_t buflen); 54455714Skris * or something similar (caller allocates a struct hostent, 54555714Skris * pointed to by "result", and additional buffer space for the various 54655714Skris * substructures; if the buffer does not suffice, NULL is returned 54755714Skris * and an appropriate error code is set). 54855714Skris */ 54955714Skrisint BIO_sock_error(int sock); 55055714Skrisint BIO_socket_ioctl(int fd, long type, unsigned long *arg); 55155714Skrisint BIO_socket_nbio(int fd,int mode); 55255714Skrisint BIO_get_port(const char *str, unsigned short *port_ptr); 55355714Skrisint BIO_get_host_ip(const char *str, unsigned char *ip); 55455714Skrisint BIO_get_accept_socket(char *host_port,int mode); 55555714Skrisint BIO_accept(int sock,char **ip_port); 55655714Skrisint BIO_sock_init(void ); 55755714Skrisvoid BIO_sock_cleanup(void); 55855714Skrisint BIO_set_tcp_ndelay(int sock,int turn_on); 55955714Skris 56055714Skrisvoid ERR_load_BIO_strings(void ); 56155714Skris 56255714SkrisBIO *BIO_new_socket(int sock, int close_flag); 56355714SkrisBIO *BIO_new_fd(int fd, int close_flag); 56455714SkrisBIO *BIO_new_connect(char *host_port); 56555714SkrisBIO *BIO_new_accept(char *host_port); 56655714Skris 56755714Skrisint BIO_new_bio_pair(BIO **bio1, size_t writebuf1, 56855714Skris BIO **bio2, size_t writebuf2); 56955714Skris/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints. 57055714Skris * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. 57155714Skris * Size 0 uses default value. 57255714Skris */ 57355714Skris 57455714Skrisvoid BIO_copy_next_retry(BIO *b); 57555714Skris 57655714Skrislong BIO_ghbn_ctrl(int cmd,int iarg,char *parg); 57755714Skris 57855714Skrisint BIO_printf(BIO *bio, ...); 57955714Skris 58055714Skris/* BEGIN ERROR CODES */ 58155714Skris/* The following lines are auto generated by the script mkerr.pl. Any changes 58255714Skris * made after this point may be overwritten when the script is next run. 58355714Skris */ 58455714Skris 58555714Skris/* Error codes for the BIO functions. */ 58655714Skris 58755714Skris/* Function codes. */ 58855714Skris#define BIO_F_ACPT_STATE 100 58955714Skris#define BIO_F_BIO_ACCEPT 101 59055714Skris#define BIO_F_BIO_BER_GET_HEADER 102 59155714Skris#define BIO_F_BIO_CTRL 103 59255714Skris#define BIO_F_BIO_GETHOSTBYNAME 120 59355714Skris#define BIO_F_BIO_GETS 104 59455714Skris#define BIO_F_BIO_GET_ACCEPT_SOCKET 105 59555714Skris#define BIO_F_BIO_GET_HOST_IP 106 59655714Skris#define BIO_F_BIO_GET_PORT 107 59755714Skris#define BIO_F_BIO_MAKE_PAIR 121 59855714Skris#define BIO_F_BIO_NEW 108 59955714Skris#define BIO_F_BIO_NEW_FILE 109 60055714Skris#define BIO_F_BIO_PUTS 110 60155714Skris#define BIO_F_BIO_READ 111 60255714Skris#define BIO_F_BIO_SOCK_INIT 112 60355714Skris#define BIO_F_BIO_WRITE 113 60455714Skris#define BIO_F_BUFFER_CTRL 114 60555714Skris#define BIO_F_CONN_STATE 115 60655714Skris#define BIO_F_FILE_CTRL 116 60755714Skris#define BIO_F_MEM_WRITE 117 60855714Skris#define BIO_F_SSL_NEW 118 60955714Skris#define BIO_F_WSASTARTUP 119 61055714Skris 61155714Skris/* Reason codes. */ 61255714Skris#define BIO_R_ACCEPT_ERROR 100 61355714Skris#define BIO_R_BAD_FOPEN_MODE 101 61455714Skris#define BIO_R_BAD_HOSTNAME_LOOKUP 102 61555714Skris#define BIO_R_BROKEN_PIPE 124 61655714Skris#define BIO_R_CONNECT_ERROR 103 61755714Skris#define BIO_R_ERROR_SETTING_NBIO 104 61855714Skris#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET 105 61955714Skris#define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET 106 62055714Skris#define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET 107 62155714Skris#define BIO_R_INVALID_ARGUMENT 125 62255714Skris#define BIO_R_INVALID_IP_ADDRESS 108 62355714Skris#define BIO_R_IN_USE 123 62455714Skris#define BIO_R_KEEPALIVE 109 62555714Skris#define BIO_R_NBIO_CONNECT_ERROR 110 62655714Skris#define BIO_R_NO_ACCEPT_PORT_SPECIFIED 111 62755714Skris#define BIO_R_NO_HOSTNAME_SPECIFIED 112 62855714Skris#define BIO_R_NO_PORT_DEFINED 113 62955714Skris#define BIO_R_NO_PORT_SPECIFIED 114 63055714Skris#define BIO_R_NULL_PARAMETER 115 63155714Skris#define BIO_R_TAG_MISMATCH 116 63255714Skris#define BIO_R_UNABLE_TO_BIND_SOCKET 117 63355714Skris#define BIO_R_UNABLE_TO_CREATE_SOCKET 118 63455714Skris#define BIO_R_UNABLE_TO_LISTEN_SOCKET 119 63555714Skris#define BIO_R_UNINITIALIZED 120 63655714Skris#define BIO_R_UNSUPPORTED_METHOD 121 63755714Skris#define BIO_R_WSASTARTUP 122 63855714Skris 63955714Skris#ifdef __cplusplus 64055714Skris} 64155714Skris#endif 64255714Skris#endif 64355714Skris 644