xref: /openbsd/lib/libcrypto/bio/bio.h (revision 5db89a4f)
1*5db89a4fStb /* $OpenBSD: bio.h,v 1.35 2018/02/20 17:55:26 tb Exp $ */
25b37fcf3Sryker /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
35b37fcf3Sryker  * All rights reserved.
45b37fcf3Sryker  *
55b37fcf3Sryker  * This package is an SSL implementation written
65b37fcf3Sryker  * by Eric Young (eay@cryptsoft.com).
75b37fcf3Sryker  * The implementation was written so as to conform with Netscapes SSL.
85b37fcf3Sryker  *
95b37fcf3Sryker  * This library is free for commercial and non-commercial use as long as
105b37fcf3Sryker  * the following conditions are aheared to.  The following conditions
115b37fcf3Sryker  * apply to all code found in this distribution, be it the RC4, RSA,
125b37fcf3Sryker  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
135b37fcf3Sryker  * included with this distribution is covered by the same copyright terms
145b37fcf3Sryker  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
155b37fcf3Sryker  *
165b37fcf3Sryker  * Copyright remains Eric Young's, and as such any Copyright notices in
175b37fcf3Sryker  * the code are not to be removed.
185b37fcf3Sryker  * If this package is used in a product, Eric Young should be given attribution
195b37fcf3Sryker  * as the author of the parts of the library used.
205b37fcf3Sryker  * This can be in the form of a textual message at program startup or
215b37fcf3Sryker  * in documentation (online or textual) provided with the package.
225b37fcf3Sryker  *
235b37fcf3Sryker  * Redistribution and use in source and binary forms, with or without
245b37fcf3Sryker  * modification, are permitted provided that the following conditions
255b37fcf3Sryker  * are met:
265b37fcf3Sryker  * 1. Redistributions of source code must retain the copyright
275b37fcf3Sryker  *    notice, this list of conditions and the following disclaimer.
285b37fcf3Sryker  * 2. Redistributions in binary form must reproduce the above copyright
295b37fcf3Sryker  *    notice, this list of conditions and the following disclaimer in the
305b37fcf3Sryker  *    documentation and/or other materials provided with the distribution.
315b37fcf3Sryker  * 3. All advertising materials mentioning features or use of this software
325b37fcf3Sryker  *    must display the following acknowledgement:
335b37fcf3Sryker  *    "This product includes cryptographic software written by
345b37fcf3Sryker  *     Eric Young (eay@cryptsoft.com)"
355b37fcf3Sryker  *    The word 'cryptographic' can be left out if the rouines from the library
365b37fcf3Sryker  *    being used are not cryptographic related :-).
375b37fcf3Sryker  * 4. If you include any Windows specific code (or a derivative thereof) from
385b37fcf3Sryker  *    the apps directory (application code) you must include an acknowledgement:
395b37fcf3Sryker  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
405b37fcf3Sryker  *
415b37fcf3Sryker  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
425b37fcf3Sryker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
435b37fcf3Sryker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
445b37fcf3Sryker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
455b37fcf3Sryker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
465b37fcf3Sryker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
475b37fcf3Sryker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
485b37fcf3Sryker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
495b37fcf3Sryker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
505b37fcf3Sryker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
515b37fcf3Sryker  * SUCH DAMAGE.
525b37fcf3Sryker  *
535b37fcf3Sryker  * The licence and distribution terms for any publically available version or
545b37fcf3Sryker  * derivative of this code cannot be changed.  i.e. this code cannot simply be
555b37fcf3Sryker  * copied and put under another distribution licence
565b37fcf3Sryker  * [including the GNU Public Licence.]
575b37fcf3Sryker  */
585b37fcf3Sryker 
595b37fcf3Sryker #ifndef HEADER_BIO_H
605b37fcf3Sryker #define HEADER_BIO_H
6140c1866aSbeck #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__OpenBSD__)
62361740acSbeck #define __bounded__(x, y, z)
63361740acSbeck #endif
6420175b85Sjsing #include <openssl/opensslconf.h>
654fcf65c5Sdjm 
66c109e398Sbeck # include <stdio.h>
67c109e398Sbeck #include <stdarg.h>
68c109e398Sbeck 
69c109e398Sbeck #include <openssl/crypto.h>
70c109e398Sbeck 
715cdd308eSdjm 
725b37fcf3Sryker #ifdef  __cplusplus
735b37fcf3Sryker extern "C" {
745b37fcf3Sryker #endif
755b37fcf3Sryker 
765b37fcf3Sryker /* These are the 'types' of BIOs */
775b37fcf3Sryker #define BIO_TYPE_NONE		0
785b37fcf3Sryker #define BIO_TYPE_MEM		(1|0x0400)
795b37fcf3Sryker #define BIO_TYPE_FILE		(2|0x0400)
805b37fcf3Sryker 
815b37fcf3Sryker #define BIO_TYPE_FD		(4|0x0400|0x0100)
825b37fcf3Sryker #define BIO_TYPE_SOCKET		(5|0x0400|0x0100)
835b37fcf3Sryker #define BIO_TYPE_NULL		(6|0x0400)
845b37fcf3Sryker #define BIO_TYPE_SSL		(7|0x0200)
85ba5406e9Sbeck #define BIO_TYPE_MD		(8|0x0200)		/* passive filter */
865b37fcf3Sryker #define BIO_TYPE_BUFFER		(9|0x0200)		/* filter */
875b37fcf3Sryker #define BIO_TYPE_CIPHER		(10|0x0200)		/* filter */
885b37fcf3Sryker #define BIO_TYPE_BASE64		(11|0x0200)		/* filter */
895b37fcf3Sryker #define BIO_TYPE_CONNECT	(12|0x0400|0x0100)	/* socket - connect */
905b37fcf3Sryker #define BIO_TYPE_ACCEPT		(13|0x0400|0x0100)	/* socket for accept */
915b37fcf3Sryker #define BIO_TYPE_PROXY_CLIENT	(14|0x0200)		/* client proxy BIO */
925b37fcf3Sryker #define BIO_TYPE_PROXY_SERVER	(15|0x0200)		/* server proxy BIO */
935b37fcf3Sryker #define BIO_TYPE_NBIO_TEST	(16|0x0200)		/* server proxy BIO */
945b37fcf3Sryker #define BIO_TYPE_NULL_FILTER	(17|0x0200)
95913ec974Sbeck #define BIO_TYPE_BER		(18|0x0200)		/* BER -> bin filter */
96913ec974Sbeck #define BIO_TYPE_BIO		(19|0x0400)		/* (half a) BIO pair */
97c109e398Sbeck #define BIO_TYPE_LINEBUFFER	(20|0x0200)		/* filter */
984fcf65c5Sdjm #define BIO_TYPE_DGRAM		(21|0x0400|0x0100)
990a5d6edeSdjm #define BIO_TYPE_ASN1 		(22|0x0200)		/* filter */
1004fcf65c5Sdjm #define BIO_TYPE_COMP 		(23|0x0200)		/* filter */
1015b37fcf3Sryker 
1025b37fcf3Sryker #define BIO_TYPE_DESCRIPTOR	0x0100	/* socket, fd, connect or accept */
1035b37fcf3Sryker #define BIO_TYPE_FILTER		0x0200
1045b37fcf3Sryker #define BIO_TYPE_SOURCE_SINK	0x0400
1055b37fcf3Sryker 
1061a692109Sjsing /*
1071a692109Sjsing  * BIO_TYPE_START is the first user-allocated BIO type. No pre-defined type,
1081a692109Sjsing  * flag bits aside, may exceed this value.
1091a692109Sjsing  */
1101a692109Sjsing #define BIO_TYPE_START 128
1111a692109Sjsing 
1125b37fcf3Sryker /* BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
1135b37fcf3Sryker  * BIO_set_fp(in,stdin,BIO_NOCLOSE); */
1145b37fcf3Sryker #define BIO_NOCLOSE		0x00
1155b37fcf3Sryker #define BIO_CLOSE		0x01
1165b37fcf3Sryker 
1175b37fcf3Sryker /* These are used in the following macros and are passed to
1185b37fcf3Sryker  * BIO_ctrl() */
1195b37fcf3Sryker #define BIO_CTRL_RESET		1  /* opt - rewind/zero etc */
1205b37fcf3Sryker #define BIO_CTRL_EOF		2  /* opt - are we at the eof */
1215b37fcf3Sryker #define BIO_CTRL_INFO		3  /* opt - extra tit-bits */
1225b37fcf3Sryker #define BIO_CTRL_SET		4  /* man - set the 'IO' type */
1235b37fcf3Sryker #define BIO_CTRL_GET		5  /* man - get the 'IO' type */
1245b37fcf3Sryker #define BIO_CTRL_PUSH		6  /* opt - internal, used to signify change */
1255b37fcf3Sryker #define BIO_CTRL_POP		7  /* opt - internal, used to signify change */
1265b37fcf3Sryker #define BIO_CTRL_GET_CLOSE	8  /* man - set the 'close' on free */
1275b37fcf3Sryker #define BIO_CTRL_SET_CLOSE	9  /* man - set the 'close' on free */
1285b37fcf3Sryker #define BIO_CTRL_PENDING	10  /* opt - is their more data buffered */
1295b37fcf3Sryker #define BIO_CTRL_FLUSH		11  /* opt - 'flush' buffered output */
1305b37fcf3Sryker #define BIO_CTRL_DUP		12  /* man - extra stuff for 'duped' BIO */
1315b37fcf3Sryker #define BIO_CTRL_WPENDING	13  /* opt - number of bytes still to write */
1325b37fcf3Sryker /* callback is int cb(BIO *bio,state,ret); */
1335b37fcf3Sryker #define BIO_CTRL_SET_CALLBACK	14  /* opt - set callback function */
1345b37fcf3Sryker #define BIO_CTRL_GET_CALLBACK	15  /* opt - set callback function */
1355b37fcf3Sryker 
1365b37fcf3Sryker #define BIO_CTRL_SET_FILENAME	30	/* BIO_s_file special */
1375b37fcf3Sryker 
1384fcf65c5Sdjm /* dgram BIO stuff */
1394fcf65c5Sdjm #define BIO_CTRL_DGRAM_CONNECT       31  /* BIO dgram special */
1404fcf65c5Sdjm #define BIO_CTRL_DGRAM_SET_CONNECTED 32  /* allow for an externally
1414fcf65c5Sdjm 					  * connected socket to be
1424fcf65c5Sdjm 					  * passed in */
1434fcf65c5Sdjm #define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */
1444fcf65c5Sdjm #define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */
1454fcf65c5Sdjm #define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */
1464fcf65c5Sdjm #define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */
1474fcf65c5Sdjm 
1484fcf65c5Sdjm #define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */
1494fcf65c5Sdjm #define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */
1504fcf65c5Sdjm 
1514fcf65c5Sdjm /* #ifdef IP_MTU_DISCOVER */
1524fcf65c5Sdjm #define BIO_CTRL_DGRAM_MTU_DISCOVER       39 /* set DF bit on egress packets */
1534fcf65c5Sdjm /* #endif */
1544fcf65c5Sdjm 
1554fcf65c5Sdjm #define BIO_CTRL_DGRAM_QUERY_MTU          40 /* as kernel for current MTU */
1565cdd308eSdjm #define BIO_CTRL_DGRAM_GET_FALLBACK_MTU   47
1574fcf65c5Sdjm #define BIO_CTRL_DGRAM_GET_MTU            41 /* get cached value for MTU */
1584fcf65c5Sdjm #define BIO_CTRL_DGRAM_SET_MTU            42 /* set cached value for
1594fcf65c5Sdjm 					      * MTU. want to use this
1604fcf65c5Sdjm 					      * if asking the kernel
1614fcf65c5Sdjm 					      * fails */
1624fcf65c5Sdjm 
1634fcf65c5Sdjm #define BIO_CTRL_DGRAM_MTU_EXCEEDED       43 /* check whether the MTU
1644fcf65c5Sdjm 					      * was exceed in the
1654fcf65c5Sdjm 					      * previous write
1664fcf65c5Sdjm 					      * operation */
1674fcf65c5Sdjm 
1680a5d6edeSdjm #define BIO_CTRL_DGRAM_GET_PEER           46
1694fcf65c5Sdjm #define BIO_CTRL_DGRAM_SET_PEER           44 /* Destination for the data */
1704fcf65c5Sdjm 
1710a5d6edeSdjm #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT   45 /* Next DTLS handshake timeout to
1720a5d6edeSdjm                                               * adjust socket timeouts */
1734fcf65c5Sdjm 
1745cdd308eSdjm 
1755b37fcf3Sryker /* modifiers */
1765b37fcf3Sryker #define BIO_FP_READ		0x02
1775b37fcf3Sryker #define BIO_FP_WRITE		0x04
1785b37fcf3Sryker #define BIO_FP_APPEND		0x08
1795b37fcf3Sryker #define BIO_FP_TEXT		0x10
1805b37fcf3Sryker 
1815b37fcf3Sryker #define BIO_FLAGS_READ		0x01
1825b37fcf3Sryker #define BIO_FLAGS_WRITE		0x02
1835b37fcf3Sryker #define BIO_FLAGS_IO_SPECIAL	0x04
1845b37fcf3Sryker #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
1855b37fcf3Sryker #define BIO_FLAGS_SHOULD_RETRY	0x08
1865b37fcf3Sryker 
1875b37fcf3Sryker /* Used in BIO_gethostbyname() */
1885b37fcf3Sryker #define BIO_GHBN_CTRL_HITS		1
1895b37fcf3Sryker #define BIO_GHBN_CTRL_MISSES		2
1905b37fcf3Sryker #define BIO_GHBN_CTRL_CACHE_SIZE	3
1915b37fcf3Sryker #define BIO_GHBN_CTRL_GET_ENTRY		4
1925b37fcf3Sryker #define BIO_GHBN_CTRL_FLUSH		5
1935b37fcf3Sryker 
1945b37fcf3Sryker /* Mostly used in the SSL BIO */
1955b37fcf3Sryker /* Not used anymore
1965b37fcf3Sryker  * #define BIO_FLAGS_PROTOCOL_DELAYED_READ 0x10
1975b37fcf3Sryker  * #define BIO_FLAGS_PROTOCOL_DELAYED_WRITE 0x20
1985b37fcf3Sryker  * #define BIO_FLAGS_PROTOCOL_STARTUP	0x40
1995b37fcf3Sryker  */
2005b37fcf3Sryker 
2015b37fcf3Sryker #define BIO_FLAGS_BASE64_NO_NL	0x100
2025b37fcf3Sryker 
203ba5406e9Sbeck /* This is used with memory BIOs: it means we shouldn't free up or change the
204ba5406e9Sbeck  * data in any way.
205ba5406e9Sbeck  */
206ba5406e9Sbeck #define BIO_FLAGS_MEM_RDONLY	0x200
207ba5406e9Sbeck 
2084fcf65c5Sdjm typedef struct bio_st BIO;
2094fcf65c5Sdjm 
2104fcf65c5Sdjm void BIO_set_flags(BIO *b, int flags);
2114fcf65c5Sdjm int  BIO_test_flags(const BIO *b, int flags);
2124fcf65c5Sdjm void BIO_clear_flags(BIO *b, int flags);
2134fcf65c5Sdjm 
2144fcf65c5Sdjm #define BIO_get_flags(b) BIO_test_flags(b, ~(0x0))
2155b37fcf3Sryker #define BIO_set_retry_special(b) \
2164fcf65c5Sdjm 		BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
2175b37fcf3Sryker #define BIO_set_retry_read(b) \
2184fcf65c5Sdjm 		BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
2195b37fcf3Sryker #define BIO_set_retry_write(b) \
2204fcf65c5Sdjm 		BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
2215b37fcf3Sryker 
2225b37fcf3Sryker /* These are normally used internally in BIOs */
2235b37fcf3Sryker #define BIO_clear_retry_flags(b) \
2244fcf65c5Sdjm 		BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
2255b37fcf3Sryker #define BIO_get_retry_flags(b) \
2264fcf65c5Sdjm 		BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
2275b37fcf3Sryker 
2285b37fcf3Sryker /* These should be used by the application to tell why we should retry */
2294fcf65c5Sdjm #define BIO_should_read(a)		BIO_test_flags(a, BIO_FLAGS_READ)
2304fcf65c5Sdjm #define BIO_should_write(a)		BIO_test_flags(a, BIO_FLAGS_WRITE)
2314fcf65c5Sdjm #define BIO_should_io_special(a)	BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL)
2324fcf65c5Sdjm #define BIO_retry_type(a)		BIO_test_flags(a, BIO_FLAGS_RWS)
2334fcf65c5Sdjm #define BIO_should_retry(a)		BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY)
2345b37fcf3Sryker 
235da347917Sbeck /* The next three are used in conjunction with the
2365b37fcf3Sryker  * BIO_should_io_special() condition.  After this returns true,
2375b37fcf3Sryker  * BIO *BIO_get_retry_BIO(BIO *bio, int *reason); will walk the BIO
2385b37fcf3Sryker  * stack and return the 'reason' for the special and the offending BIO.
2395b37fcf3Sryker  * Given a BIO, BIO_get_retry_reason(bio) will return the code. */
2405b37fcf3Sryker /* Returned from the SSL bio when the certificate retrieval code had an error */
2415b37fcf3Sryker #define BIO_RR_SSL_X509_LOOKUP		0x01
2425b37fcf3Sryker /* Returned from the connect BIO when a connect would have blocked */
2435b37fcf3Sryker #define BIO_RR_CONNECT			0x02
244da347917Sbeck /* Returned from the accept BIO when an accept would have blocked */
245da347917Sbeck #define BIO_RR_ACCEPT			0x03
2465b37fcf3Sryker 
2475b37fcf3Sryker /* These are passed by the BIO callback */
2485b37fcf3Sryker #define BIO_CB_FREE	0x01
2495b37fcf3Sryker #define BIO_CB_READ	0x02
2505b37fcf3Sryker #define BIO_CB_WRITE	0x03
2515b37fcf3Sryker #define BIO_CB_PUTS	0x04
2525b37fcf3Sryker #define BIO_CB_GETS	0x05
2535b37fcf3Sryker #define BIO_CB_CTRL	0x06
2545b37fcf3Sryker 
2555b37fcf3Sryker /* The callback is called before and after the underling operation,
2565b37fcf3Sryker  * The BIO_CB_RETURN flag indicates if it is after the call */
2575b37fcf3Sryker #define BIO_CB_RETURN	0x80
2585b37fcf3Sryker #define BIO_CB_return(a) ((a)|BIO_CB_RETURN))
2595b37fcf3Sryker #define BIO_cb_pre(a)	(!((a)&BIO_CB_RETURN))
2605b37fcf3Sryker #define BIO_cb_post(a)	((a)&BIO_CB_RETURN)
2615b37fcf3Sryker 
262c3d505beSjsing long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *,
263c3d505beSjsing     int, long, long);
2644fcf65c5Sdjm void BIO_set_callback(BIO *b,
2654fcf65c5Sdjm     long (*callback)(struct bio_st *, int, const char *, int, long, long));
2664fcf65c5Sdjm char *BIO_get_callback_arg(const BIO *b);
2674fcf65c5Sdjm void BIO_set_callback_arg(BIO *b, char *arg);
2685b37fcf3Sryker 
2694fcf65c5Sdjm const char * BIO_method_name(const BIO *b);
2704fcf65c5Sdjm int BIO_method_type(const BIO *b);
271c109e398Sbeck 
272c109e398Sbeck typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
273c109e398Sbeck 
274c3d505beSjsing typedef struct bio_method_st {
2755b37fcf3Sryker 	int type;
276913ec974Sbeck 	const char *name;
277c109e398Sbeck 	int (*bwrite)(BIO *, const char *, int);
278c109e398Sbeck 	int (*bread)(BIO *, char *, int);
279c109e398Sbeck 	int (*bputs)(BIO *, const char *);
280c109e398Sbeck 	int (*bgets)(BIO *, char *, int);
281c109e398Sbeck 	long (*ctrl)(BIO *, int, long, void *);
282c109e398Sbeck 	int (*create)(BIO *);
283c109e398Sbeck 	int (*destroy)(BIO *);
284c109e398Sbeck 	long (*callback_ctrl)(BIO *, int, bio_info_cb *);
2855b37fcf3Sryker } BIO_METHOD;
2865b37fcf3Sryker 
287c3d505beSjsing struct bio_st {
2885b37fcf3Sryker 	BIO_METHOD *method;
2895b37fcf3Sryker 	/* bio, mode, argp, argi, argl, ret */
290913ec974Sbeck 	long (*callback)(struct bio_st *, int, const char *, int, long, long);
2915b37fcf3Sryker 	char *cb_arg; /* first argument for the callback */
2925b37fcf3Sryker 
2935b37fcf3Sryker 	int init;
2945b37fcf3Sryker 	int shutdown;
2955b37fcf3Sryker 	int flags;	/* extra storage */
2965b37fcf3Sryker 	int retry_reason;
2975b37fcf3Sryker 	int num;
298913ec974Sbeck 	void *ptr;
2995b37fcf3Sryker 	struct bio_st *next_bio;	/* used by filter BIOs */
3005b37fcf3Sryker 	struct bio_st *prev_bio;	/* used by filter BIOs */
3015b37fcf3Sryker 	int references;
3025b37fcf3Sryker 	unsigned long num_read;
3035b37fcf3Sryker 	unsigned long num_write;
3045b37fcf3Sryker 
3055b37fcf3Sryker 	CRYPTO_EX_DATA ex_data;
306c109e398Sbeck };
307c109e398Sbeck 
308c109e398Sbeck DECLARE_STACK_OF(BIO)
3095b37fcf3Sryker 
310c3d505beSjsing typedef struct bio_f_buffer_ctx_struct {
31117150393Sdjm 	/* Buffers are setup like this:
31217150393Sdjm 	 *
31317150393Sdjm 	 * <---------------------- size ----------------------->
31417150393Sdjm 	 * +---------------------------------------------------+
31517150393Sdjm 	 * | consumed | remaining          | free space        |
31617150393Sdjm 	 * +---------------------------------------------------+
31717150393Sdjm 	 * <-- off --><------- len ------->
31817150393Sdjm 	 */
31917150393Sdjm 
3205b37fcf3Sryker 	/* BIO *bio; */ /* this is now in the BIO struct */
3215b37fcf3Sryker 	int ibuf_size;	/* how big is the input buffer */
3225b37fcf3Sryker 	int obuf_size;	/* how big is the output buffer */
3235b37fcf3Sryker 
3245b37fcf3Sryker 	char *ibuf;	/* the char array */
3255b37fcf3Sryker 	int ibuf_len;	/* how many bytes are in it */
3265b37fcf3Sryker 	int ibuf_off;	/* write/read offset */
3275b37fcf3Sryker 
3285b37fcf3Sryker 	char *obuf;	/* the char array */
3295b37fcf3Sryker 	int obuf_len;	/* how many bytes are in it */
3305b37fcf3Sryker 	int obuf_off;	/* write/read offset */
3315b37fcf3Sryker } BIO_F_BUFFER_CTX;
3325b37fcf3Sryker 
3330a5d6edeSdjm /* Prefix and suffix callback in ASN1 BIO */
3340a5d6edeSdjm typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg);
3350a5d6edeSdjm 
33697c7ad8eStb /* BIO_METHOD accessors */
33797c7ad8eStb BIO_METHOD *BIO_meth_new(int type, const char *name);
33897c7ad8eStb void BIO_meth_free(BIO_METHOD *biom);
33997c7ad8eStb int BIO_meth_set_write(BIO_METHOD *biom,
34097c7ad8eStb     int (*write)(BIO *, const char *, int));
34197c7ad8eStb int BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int));
34297c7ad8eStb int BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *));
343f02021ddStb int BIO_meth_set_gets(BIO_METHOD *biom, int (*gets)(BIO *, char *, int));
34497c7ad8eStb int BIO_meth_set_ctrl(BIO_METHOD *biom,
34597c7ad8eStb     int long (*ctrl)(BIO *, int, long, void *));
34697c7ad8eStb int BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *));
34797c7ad8eStb int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *));
3485cdd308eSdjm 
3495b37fcf3Sryker /* connect BIO stuff */
3505b37fcf3Sryker #define BIO_CONN_S_BEFORE		1
3515b37fcf3Sryker #define BIO_CONN_S_GET_IP		2
3525b37fcf3Sryker #define BIO_CONN_S_GET_PORT		3
3535b37fcf3Sryker #define BIO_CONN_S_CREATE_SOCKET	4
3545b37fcf3Sryker #define BIO_CONN_S_CONNECT		5
3555b37fcf3Sryker #define BIO_CONN_S_OK			6
3565b37fcf3Sryker #define BIO_CONN_S_BLOCKED_CONNECT	7
3575b37fcf3Sryker #define BIO_CONN_S_NBIO			8
358913ec974Sbeck /*#define BIO_CONN_get_param_hostname	BIO_ctrl */
3595b37fcf3Sryker 
3605b37fcf3Sryker #define BIO_C_SET_CONNECT			100
3615b37fcf3Sryker #define BIO_C_DO_STATE_MACHINE			101
3625b37fcf3Sryker #define BIO_C_SET_NBIO				102
3635b37fcf3Sryker #define BIO_C_SET_PROXY_PARAM			103
3645b37fcf3Sryker #define BIO_C_SET_FD				104
3655b37fcf3Sryker #define BIO_C_GET_FD				105
3665b37fcf3Sryker #define BIO_C_SET_FILE_PTR			106
3675b37fcf3Sryker #define BIO_C_GET_FILE_PTR			107
3685b37fcf3Sryker #define BIO_C_SET_FILENAME			108
3695b37fcf3Sryker #define BIO_C_SET_SSL				109
3705b37fcf3Sryker #define BIO_C_GET_SSL				110
3715b37fcf3Sryker #define BIO_C_SET_MD				111
3725b37fcf3Sryker #define BIO_C_GET_MD				112
3735b37fcf3Sryker #define BIO_C_GET_CIPHER_STATUS			113
3745b37fcf3Sryker #define BIO_C_SET_BUF_MEM			114
3755b37fcf3Sryker #define BIO_C_GET_BUF_MEM_PTR			115
3765b37fcf3Sryker #define BIO_C_GET_BUFF_NUM_LINES		116
3775b37fcf3Sryker #define BIO_C_SET_BUFF_SIZE			117
3785b37fcf3Sryker #define BIO_C_SET_ACCEPT			118
3795b37fcf3Sryker #define BIO_C_SSL_MODE				119
3805b37fcf3Sryker #define BIO_C_GET_MD_CTX			120
3815b37fcf3Sryker #define BIO_C_GET_PROXY_PARAM			121
3825b37fcf3Sryker #define BIO_C_SET_BUFF_READ_DATA		122 /* data to read first */
3835b37fcf3Sryker #define BIO_C_GET_CONNECT			123
3845b37fcf3Sryker #define BIO_C_GET_ACCEPT			124
3855b37fcf3Sryker #define BIO_C_SET_SSL_RENEGOTIATE_BYTES		125
3865b37fcf3Sryker #define BIO_C_GET_SSL_NUM_RENEGOTIATES		126
3875b37fcf3Sryker #define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT	127
388913ec974Sbeck #define BIO_C_FILE_SEEK				128
389913ec974Sbeck #define BIO_C_GET_CIPHER_CTX			129
390913ec974Sbeck #define BIO_C_SET_BUF_MEM_EOF_RETURN		130/*return end of input value*/
391913ec974Sbeck #define BIO_C_SET_BIND_MODE			131
392913ec974Sbeck #define BIO_C_GET_BIND_MODE			132
393913ec974Sbeck #define BIO_C_FILE_TELL				133
394913ec974Sbeck #define BIO_C_GET_SOCKS				134
395913ec974Sbeck #define BIO_C_SET_SOCKS				135
396913ec974Sbeck 
397913ec974Sbeck #define BIO_C_SET_WRITE_BUF_SIZE		136/* for BIO_s_bio */
398913ec974Sbeck #define BIO_C_GET_WRITE_BUF_SIZE		137
399913ec974Sbeck #define BIO_C_MAKE_BIO_PAIR			138
400913ec974Sbeck #define BIO_C_DESTROY_BIO_PAIR			139
401913ec974Sbeck #define BIO_C_GET_WRITE_GUARANTEE		140
402913ec974Sbeck #define BIO_C_GET_READ_REQUEST			141
403913ec974Sbeck #define BIO_C_SHUTDOWN_WR			142
404ba5406e9Sbeck #define BIO_C_NREAD0				143
405ba5406e9Sbeck #define BIO_C_NREAD				144
406ba5406e9Sbeck #define BIO_C_NWRITE0				145
407ba5406e9Sbeck #define BIO_C_NWRITE				146
408ba5406e9Sbeck #define BIO_C_RESET_READ_REQUEST		147
40940d8aef3Sdjm #define BIO_C_SET_MD_CTX			148
410913ec974Sbeck 
4110a5d6edeSdjm #define BIO_C_SET_PREFIX			149
4120a5d6edeSdjm #define BIO_C_GET_PREFIX			150
4130a5d6edeSdjm #define BIO_C_SET_SUFFIX			151
4140a5d6edeSdjm #define BIO_C_GET_SUFFIX			152
4150a5d6edeSdjm 
4160a5d6edeSdjm #define BIO_C_SET_EX_ARG			153
4170a5d6edeSdjm #define BIO_C_GET_EX_ARG			154
4185b37fcf3Sryker 
419ba5406e9Sbeck #define BIO_set_app_data(s,arg)		BIO_set_ex_data(s,0,arg)
4205b37fcf3Sryker #define BIO_get_app_data(s)		BIO_get_ex_data(s,0)
4215b37fcf3Sryker 
422913ec974Sbeck /* BIO_s_connect() and BIO_s_socks4a_connect() */
4235b37fcf3Sryker #define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0,(char *)name)
4245b37fcf3Sryker #define BIO_set_conn_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,1,(char *)port)
4255b37fcf3Sryker #define BIO_set_conn_ip(b,ip)	  BIO_ctrl(b,BIO_C_SET_CONNECT,2,(char *)ip)
4265b37fcf3Sryker #define BIO_set_conn_int_port(b,port) BIO_ctrl(b,BIO_C_SET_CONNECT,3,(char *)port)
4275b37fcf3Sryker #define BIO_get_conn_hostname(b)  BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0)
4285b37fcf3Sryker #define BIO_get_conn_port(b)      BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1)
429da347917Sbeck #define BIO_get_conn_ip(b) 		 BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2)
4300a5d6edeSdjm #define BIO_get_conn_int_port(b) BIO_int_ctrl(b,BIO_C_GET_CONNECT,3,0)
431913ec974Sbeck 
4325b37fcf3Sryker 
4335b37fcf3Sryker #define BIO_set_nbio(b,n)	BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
4345b37fcf3Sryker 
4355b37fcf3Sryker /* BIO_s_accept_socket() */
4365b37fcf3Sryker #define BIO_set_accept_port(b,name) BIO_ctrl(b,BIO_C_SET_ACCEPT,0,(char *)name)
4375b37fcf3Sryker #define BIO_get_accept_port(b)	BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0)
4385b37fcf3Sryker /* #define BIO_set_nbio(b,n)	BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
4390a5d6edeSdjm #define BIO_set_nbio_accept(b,n) BIO_ctrl(b,BIO_C_SET_ACCEPT,1,(n)?(void *)"a":NULL)
4405b37fcf3Sryker #define BIO_set_accept_bios(b,bio) BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(char *)bio)
4415b37fcf3Sryker 
442913ec974Sbeck #define BIO_BIND_NORMAL			0
443913ec974Sbeck #define BIO_BIND_REUSEADDR_IF_UNUSED	1
444913ec974Sbeck #define BIO_BIND_REUSEADDR		2
445913ec974Sbeck #define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
446913ec974Sbeck #define BIO_get_bind_mode(b,mode) BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
447913ec974Sbeck 
4485b37fcf3Sryker #define BIO_do_connect(b)	BIO_do_handshake(b)
4495b37fcf3Sryker #define BIO_do_accept(b)	BIO_do_handshake(b)
4505b37fcf3Sryker #define BIO_do_handshake(b)	BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
4515b37fcf3Sryker 
4525b37fcf3Sryker /* BIO_s_proxy_client() */
4535b37fcf3Sryker #define BIO_set_url(b,url)	BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url))
4545b37fcf3Sryker #define BIO_set_proxies(b,p)	BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p))
4555b37fcf3Sryker /* BIO_set_nbio(b,n) */
4565b37fcf3Sryker #define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s))
4575b37fcf3Sryker /* BIO *BIO_get_filter_bio(BIO *bio); */
458ba5406e9Sbeck #define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)()))
4595b37fcf3Sryker #define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk)
4605b37fcf3Sryker #define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool)
4615b37fcf3Sryker 
4625b37fcf3Sryker #define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp)
4635b37fcf3Sryker #define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p))
4645b37fcf3Sryker #define BIO_get_url(b,url)	BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url))
4655b37fcf3Sryker #define BIO_get_no_connect_return(b)	BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL)
4665b37fcf3Sryker 
4675b37fcf3Sryker #define BIO_set_fd(b,fd,c)	BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
4685b37fcf3Sryker #define BIO_get_fd(b,c)		BIO_ctrl(b,BIO_C_GET_FD,0,(char *)c)
4695b37fcf3Sryker 
4705b37fcf3Sryker #define BIO_set_fp(b,fp,c)	BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp)
4715b37fcf3Sryker #define BIO_get_fp(b,fpp)	BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp)
4725b37fcf3Sryker 
473913ec974Sbeck #define BIO_seek(b,ofs)	(int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
474913ec974Sbeck #define BIO_tell(b)	(int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
475913ec974Sbeck 
476913ec974Sbeck /* name is cast to lose const, but might be better to route through a function
477913ec974Sbeck    so we can do it safely */
4785b37fcf3Sryker #define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
479913ec974Sbeck 		BIO_CLOSE|BIO_FP_READ,(char *)name)
4805b37fcf3Sryker #define BIO_write_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
4815b37fcf3Sryker 		BIO_CLOSE|BIO_FP_WRITE,name)
4825b37fcf3Sryker #define BIO_append_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
4835b37fcf3Sryker 		BIO_CLOSE|BIO_FP_APPEND,name)
484913ec974Sbeck #define BIO_rw_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
485913ec974Sbeck 		BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
4865b37fcf3Sryker 
4875b37fcf3Sryker /* WARNING WARNING, this ups the reference count on the read bio of the
4885b37fcf3Sryker  * SSL structure.  This is because the ssl read BIO is now pointed to by
4895b37fcf3Sryker  * the next_bio field in the bio.  So when you free the BIO, make sure
4905b37fcf3Sryker  * you are doing a BIO_free_all() to catch the underlying BIO. */
4915b37fcf3Sryker #define BIO_set_ssl(b,ssl,c)	BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)ssl)
4925b37fcf3Sryker #define BIO_get_ssl(b,sslp)	BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)sslp)
4935b37fcf3Sryker #define BIO_set_ssl_mode(b,client)	BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
4945b37fcf3Sryker #define BIO_set_ssl_renegotiate_bytes(b,num) \
495d94c81a7Sderaadt 	BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL)
4965b37fcf3Sryker #define BIO_get_num_renegotiates(b) \
497d94c81a7Sderaadt 	BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL)
4985b37fcf3Sryker #define BIO_set_ssl_renegotiate_timeout(b,seconds) \
499d94c81a7Sderaadt 	BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL)
5005b37fcf3Sryker 
5015b37fcf3Sryker /* defined in evp.h */
5025b37fcf3Sryker /* #define BIO_set_md(b,md)	BIO_ctrl(b,BIO_C_SET_MD,1,(char *)md) */
5035b37fcf3Sryker 
504913ec974Sbeck #define BIO_get_mem_data(b,pp)	BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)pp)
5055b37fcf3Sryker #define BIO_set_mem_buf(b,bm,c)	BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)bm)
5065b37fcf3Sryker #define BIO_get_mem_ptr(b,pp)	BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0,(char *)pp)
507913ec974Sbeck #define BIO_set_mem_eof_return(b,v) \
508913ec974Sbeck 				BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
5095b37fcf3Sryker 
5105b37fcf3Sryker /* For the BIO_f_buffer() type */
5115b37fcf3Sryker #define BIO_get_buffer_num_lines(b)	BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
5125b37fcf3Sryker #define BIO_set_buffer_size(b,size)	BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
5135b37fcf3Sryker #define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
5145b37fcf3Sryker #define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
5155b37fcf3Sryker #define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
5165b37fcf3Sryker 
5175b37fcf3Sryker /* Don't use the next one unless you know what you are doing :-) */
5185b37fcf3Sryker #define BIO_dup_state(b,ret)	BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
5195b37fcf3Sryker 
5205b37fcf3Sryker #define BIO_reset(b)		(int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
5215b37fcf3Sryker #define BIO_eof(b)		(int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
5225b37fcf3Sryker #define BIO_set_close(b,c)	(int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
5235b37fcf3Sryker #define BIO_get_close(b)	(int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
5245b37fcf3Sryker #define BIO_pending(b)		(int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
5255b37fcf3Sryker #define BIO_wpending(b)		(int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
526913ec974Sbeck /* ...pending macros have inappropriate return type */
527913ec974Sbeck size_t BIO_ctrl_pending(BIO *b);
528913ec974Sbeck size_t BIO_ctrl_wpending(BIO *b);
5295b37fcf3Sryker #define BIO_flush(b)		(int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
530da347917Sbeck #define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
531da347917Sbeck 						   cbp)
532da347917Sbeck #define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
5335b37fcf3Sryker 
5345b37fcf3Sryker /* For the BIO_f_buffer() type */
5355b37fcf3Sryker #define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
5365b37fcf3Sryker 
537913ec974Sbeck /* For BIO_s_bio() */
538913ec974Sbeck #define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
539913ec974Sbeck #define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
540913ec974Sbeck #define BIO_make_bio_pair(b1,b2)   (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
541913ec974Sbeck #define BIO_destroy_bio_pair(b)    (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
542c109e398Sbeck #define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
543913ec974Sbeck /* macros with inappropriate type -- but ...pending macros use int too: */
544913ec974Sbeck #define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
545913ec974Sbeck #define BIO_get_read_request(b)    (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
546913ec974Sbeck size_t BIO_ctrl_get_write_guarantee(BIO *b);
547913ec974Sbeck size_t BIO_ctrl_get_read_request(BIO *b);
548ba5406e9Sbeck int BIO_ctrl_reset_read_request(BIO *b);
549913ec974Sbeck 
5504fcf65c5Sdjm /* ctrl macros for dgram */
5514fcf65c5Sdjm #define BIO_ctrl_dgram_connect(b,peer)  \
5524fcf65c5Sdjm                      (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer)
5534fcf65c5Sdjm #define BIO_ctrl_set_connected(b, state, peer) \
5544fcf65c5Sdjm          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, state, (char *)peer)
5554fcf65c5Sdjm #define BIO_dgram_recv_timedout(b) \
5564fcf65c5Sdjm          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL)
5574fcf65c5Sdjm #define BIO_dgram_send_timedout(b) \
5584fcf65c5Sdjm          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL)
5590a5d6edeSdjm #define BIO_dgram_get_peer(b,peer) \
5600a5d6edeSdjm          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)peer)
5614fcf65c5Sdjm #define BIO_dgram_set_peer(b,peer) \
5624fcf65c5Sdjm          (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)
5634fcf65c5Sdjm 
564913ec974Sbeck /* These two aren't currently implemented */
565913ec974Sbeck /* int BIO_get_ex_num(BIO *bio); */
566913ec974Sbeck /* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
567ba5406e9Sbeck int BIO_set_ex_data(BIO *bio, int idx, void *data);
568ba5406e9Sbeck void *BIO_get_ex_data(BIO *bio, int idx);
569c3d505beSjsing int
570c3d505beSjsing BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
571ba5406e9Sbeck CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
572ba5406e9Sbeck unsigned long BIO_number_read(BIO *bio);
573ba5406e9Sbeck unsigned long BIO_number_written(BIO *bio);
574913ec974Sbeck 
5750a5d6edeSdjm /* For BIO_f_asn1() */
576c3d505beSjsing int
577c3d505beSjsing BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
5780a5d6edeSdjm asn1_ps_func *prefix_free);
579c3d505beSjsing int
580c3d505beSjsing BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
5810a5d6edeSdjm asn1_ps_func **pprefix_free);
582c3d505beSjsing int
583c3d505beSjsing BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
5840a5d6edeSdjm asn1_ps_func *suffix_free);
585c3d505beSjsing int
586c3d505beSjsing BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
5870a5d6edeSdjm asn1_ps_func **psuffix_free);
5880a5d6edeSdjm 
5891a692109Sjsing int BIO_get_new_index(void);
5905b37fcf3Sryker BIO_METHOD *BIO_s_file(void );
591913ec974Sbeck BIO *BIO_new_file(const char *filename, const char *mode);
5925b37fcf3Sryker BIO *BIO_new_fp(FILE *stream, int close_flag);
5935b37fcf3Sryker # define BIO_s_file_internal	BIO_s_file
5945b37fcf3Sryker BIO *	BIO_new(BIO_METHOD *type);
5955b37fcf3Sryker int	BIO_set(BIO *a, BIO_METHOD *type);
5965b37fcf3Sryker int	BIO_free(BIO *a);
597b47f35fcStb void 	*BIO_get_data(BIO *a);
598b47f35fcStb void 	BIO_set_data(BIO *a, void *ptr);
599b47f35fcStb void 	BIO_set_init(BIO *a, int init);
600*5db89a4fStb int	BIO_get_shutdown(BIO *a);
601*5db89a4fStb void	BIO_set_shutdown(BIO *a, int shut);
602c109e398Sbeck void	BIO_vfree(BIO *a);
6038a890fdfStedu int	BIO_read(BIO *b, void *data, int len)
6048a890fdfStedu 		__attribute__((__bounded__(__buffer__,2,3)));
6058a890fdfStedu int	BIO_gets(BIO *bp, char *buf, int size)
6068a890fdfStedu 		__attribute__((__bounded__ (__string__,2,3)));
6078a890fdfStedu int	BIO_write(BIO *b, const void *data, int len)
6088a890fdfStedu 		__attribute__((__bounded__(__buffer__,2,3)));
609913ec974Sbeck int	BIO_puts(BIO *bp, const char *buf);
610767fe2ffSmarkus int	BIO_indent(BIO *b, int indent, int max);
611913ec974Sbeck long	BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
612c3d505beSjsing long	BIO_callback_ctrl(BIO *b, int cmd,
613c3d505beSjsing 	    void (*fp)(struct bio_st *, int, const char *, int, long, long));
6145b37fcf3Sryker char *	BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
6155b37fcf3Sryker long	BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
6165b37fcf3Sryker BIO *	BIO_push(BIO *b, BIO *append);
6175b37fcf3Sryker BIO *	BIO_pop(BIO *b);
6185b37fcf3Sryker void	BIO_free_all(BIO *a);
6195b37fcf3Sryker BIO *	BIO_find_type(BIO *b, int bio_type);
620c109e398Sbeck BIO *	BIO_next(BIO *b);
6215b37fcf3Sryker BIO *	BIO_get_retry_BIO(BIO *bio, int *reason);
6225b37fcf3Sryker int	BIO_get_retry_reason(BIO *bio);
6235b37fcf3Sryker BIO *	BIO_dup_chain(BIO *in);
6245b37fcf3Sryker 
625ba5406e9Sbeck int BIO_nread0(BIO *bio, char **buf);
626ba5406e9Sbeck int BIO_nread(BIO *bio, char **buf, int num);
627ba5406e9Sbeck int BIO_nwrite0(BIO *bio, char **buf);
628ba5406e9Sbeck int BIO_nwrite(BIO *bio, char **buf, int num);
629ba5406e9Sbeck 
630913ec974Sbeck long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
6315b37fcf3Sryker     long argl, long ret);
6325b37fcf3Sryker 
6335b37fcf3Sryker BIO_METHOD *BIO_s_mem(void);
634ba5406e9Sbeck BIO *BIO_new_mem_buf(void *buf, int len);
6355b37fcf3Sryker BIO_METHOD *BIO_s_socket(void);
6365b37fcf3Sryker BIO_METHOD *BIO_s_connect(void);
6375b37fcf3Sryker BIO_METHOD *BIO_s_accept(void);
6385b37fcf3Sryker BIO_METHOD *BIO_s_fd(void);
639913ec974Sbeck BIO_METHOD *BIO_s_log(void);
640913ec974Sbeck BIO_METHOD *BIO_s_bio(void);
6415b37fcf3Sryker BIO_METHOD *BIO_s_null(void);
6425b37fcf3Sryker BIO_METHOD *BIO_f_null(void);
6435b37fcf3Sryker BIO_METHOD *BIO_f_buffer(void);
644913ec974Sbeck BIO_METHOD *BIO_f_nbio_test(void);
6454fcf65c5Sdjm #ifndef OPENSSL_NO_DGRAM
6464fcf65c5Sdjm BIO_METHOD *BIO_s_datagram(void);
6474fcf65c5Sdjm #endif
6484fcf65c5Sdjm 
649913ec974Sbeck /* BIO_METHOD *BIO_f_ber(void); */
6505b37fcf3Sryker 
6515b37fcf3Sryker int BIO_sock_should_retry(int i);
652385ffcfeSdoug int BIO_sock_non_fatal_error(int _error);
653385ffcfeSdoug int BIO_dgram_non_fatal_error(int _error);
6544fcf65c5Sdjm 
6555b37fcf3Sryker int BIO_fd_should_retry(int i);
656385ffcfeSdoug int BIO_fd_non_fatal_error(int _error);
657c3d505beSjsing int
658c3d505beSjsing BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
6594fcf65c5Sdjm void *u, const char *s, int len);
660c3d505beSjsing int
661c3d505beSjsing BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
6624fcf65c5Sdjm void *u, const char *s, int len, int indent);
663913ec974Sbeck int BIO_dump(BIO *b, const char *bytes, int len);
664c109e398Sbeck int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent);
6654fcf65c5Sdjm int BIO_dump_fp(FILE *fp, const char *s, int len);
6664fcf65c5Sdjm int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
667913ec974Sbeck struct hostent *BIO_gethostbyname(const char *name);
668913ec974Sbeck /* We might want a thread-safe interface too:
669913ec974Sbeck  * struct hostent *BIO_gethostbyname_r(const char *name,
670913ec974Sbeck  *     struct hostent *result, void *buffer, size_t buflen);
671913ec974Sbeck  * or something similar (caller allocates a struct hostent,
672913ec974Sbeck  * pointed to by "result", and additional buffer space for the various
673913ec974Sbeck  * substructures; if the buffer does not suffice, NULL is returned
674913ec974Sbeck  * and an appropriate error code is set).
675913ec974Sbeck  */
6765b37fcf3Sryker int BIO_sock_error(int sock);
677767fe2ffSmarkus int BIO_socket_ioctl(int fd, long type, void *arg);
678913ec974Sbeck int BIO_socket_nbio(int fd, int mode);
679913ec974Sbeck int BIO_get_port(const char *str, unsigned short *port_ptr);
680913ec974Sbeck int BIO_get_host_ip(const char *str, unsigned char *ip);
681913ec974Sbeck int BIO_get_accept_socket(char *host_port, int mode);
6825b37fcf3Sryker int BIO_accept(int sock, char **ip_port);
6835b37fcf3Sryker int BIO_sock_init(void );
6845b37fcf3Sryker void BIO_sock_cleanup(void);
6855b37fcf3Sryker int BIO_set_tcp_ndelay(int sock, int turn_on);
6865b37fcf3Sryker 
6875b37fcf3Sryker BIO *BIO_new_socket(int sock, int close_flag);
6884fcf65c5Sdjm BIO *BIO_new_dgram(int fd, int close_flag);
6895b37fcf3Sryker BIO *BIO_new_fd(int fd, int close_flag);
6905b37fcf3Sryker BIO *BIO_new_connect(char *host_port);
6915b37fcf3Sryker BIO *BIO_new_accept(char *host_port);
6925b37fcf3Sryker 
693c3d505beSjsing int
694c3d505beSjsing BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
695913ec974Sbeck BIO **bio2, size_t writebuf2);
696913ec974Sbeck /* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
697913ec974Sbeck  * Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
698913ec974Sbeck  * Size 0 uses default value.
699913ec974Sbeck  */
700913ec974Sbeck 
7015b37fcf3Sryker void BIO_copy_next_retry(BIO *b);
7025b37fcf3Sryker 
703767fe2ffSmarkus /*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/
7045b37fcf3Sryker 
705c3d505beSjsing int
706c3d505beSjsing BIO_printf(BIO *bio, const char *format, ...)
707ab588a6aSguenther 	__attribute__((__format__(__printf__, 2, 3), __nonnull__(2)));
708c3d505beSjsing int
709c3d505beSjsing BIO_vprintf(BIO *bio, const char *format, va_list args)
710ab588a6aSguenther 	__attribute__((__format__(__printf__, 2, 0), __nonnull__(2)));
711c3d505beSjsing int
712c3d505beSjsing BIO_snprintf(char *buf, size_t n, const char *format, ...)
713ab588a6aSguenther 	__attribute__((__deprecated__, __format__(__printf__, 3, 4),
714ab588a6aSguenther 	    __nonnull__(3)));
715c3d505beSjsing int
716c3d505beSjsing BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
717ab588a6aSguenther 	__attribute__((__deprecated__, __format__(__printf__, 3, 0),
718ab588a6aSguenther 	    __nonnull__(3)));
7195b37fcf3Sryker 
7205b37fcf3Sryker /* BEGIN ERROR CODES */
721913ec974Sbeck /* The following lines are auto generated by the script mkerr.pl. Any changes
722913ec974Sbeck  * made after this point may be overwritten when the script is next run.
723913ec974Sbeck  */
724da347917Sbeck void ERR_load_BIO_strings(void);
725913ec974Sbeck 
7265b37fcf3Sryker /* Error codes for the BIO functions. */
7275b37fcf3Sryker 
7285b37fcf3Sryker /* Function codes. */
7295b37fcf3Sryker #define BIO_F_ACPT_STATE				 100
7305b37fcf3Sryker #define BIO_F_BIO_ACCEPT				 101
731913ec974Sbeck #define BIO_F_BIO_BER_GET_HEADER			 102
7324fcf65c5Sdjm #define BIO_F_BIO_CALLBACK_CTRL				 131
733913ec974Sbeck #define BIO_F_BIO_CTRL					 103
734913ec974Sbeck #define BIO_F_BIO_GETHOSTBYNAME				 120
735913ec974Sbeck #define BIO_F_BIO_GETS					 104
736913ec974Sbeck #define BIO_F_BIO_GET_ACCEPT_SOCKET			 105
737913ec974Sbeck #define BIO_F_BIO_GET_HOST_IP				 106
738913ec974Sbeck #define BIO_F_BIO_GET_PORT				 107
739913ec974Sbeck #define BIO_F_BIO_MAKE_PAIR				 121
740913ec974Sbeck #define BIO_F_BIO_NEW					 108
741913ec974Sbeck #define BIO_F_BIO_NEW_FILE				 109
742ba5406e9Sbeck #define BIO_F_BIO_NEW_MEM_BUF				 126
743ba5406e9Sbeck #define BIO_F_BIO_NREAD					 123
744ba5406e9Sbeck #define BIO_F_BIO_NREAD0				 124
745ba5406e9Sbeck #define BIO_F_BIO_NWRITE				 125
746ba5406e9Sbeck #define BIO_F_BIO_NWRITE0				 122
747913ec974Sbeck #define BIO_F_BIO_PUTS					 110
748913ec974Sbeck #define BIO_F_BIO_READ					 111
749913ec974Sbeck #define BIO_F_BIO_SOCK_INIT				 112
750913ec974Sbeck #define BIO_F_BIO_WRITE					 113
751913ec974Sbeck #define BIO_F_BUFFER_CTRL				 114
752ba5406e9Sbeck #define BIO_F_CONN_CTRL					 127
753913ec974Sbeck #define BIO_F_CONN_STATE				 115
7545cdd308eSdjm #define BIO_F_DGRAM_SCTP_READ				 132
755913ec974Sbeck #define BIO_F_FILE_CTRL					 116
7561f9308f9Smarkus #define BIO_F_FILE_READ					 130
757c109e398Sbeck #define BIO_F_LINEBUFFER_CTRL				 129
758c109e398Sbeck #define BIO_F_MEM_READ					 128
759913ec974Sbeck #define BIO_F_MEM_WRITE					 117
760913ec974Sbeck #define BIO_F_SSL_NEW					 118
761913ec974Sbeck #define BIO_F_WSASTARTUP				 119
7625b37fcf3Sryker 
7635b37fcf3Sryker /* Reason codes. */
7645b37fcf3Sryker #define BIO_R_ACCEPT_ERROR				 100
7655b37fcf3Sryker #define BIO_R_BAD_FOPEN_MODE				 101
7665b37fcf3Sryker #define BIO_R_BAD_HOSTNAME_LOOKUP			 102
767913ec974Sbeck #define BIO_R_BROKEN_PIPE				 124
7685b37fcf3Sryker #define BIO_R_CONNECT_ERROR				 103
769c109e398Sbeck #define BIO_R_EOF_ON_MEMORY_BIO				 127
7705b37fcf3Sryker #define BIO_R_ERROR_SETTING_NBIO			 104
7715b37fcf3Sryker #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET	 105
7725b37fcf3Sryker #define BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET	 106
7735b37fcf3Sryker #define BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET		 107
774913ec974Sbeck #define BIO_R_INVALID_ARGUMENT				 125
7755b37fcf3Sryker #define BIO_R_INVALID_IP_ADDRESS			 108
776e5e87f23Sjsing #define BIO_R_INVALID_PORT_NUMBER			 129
777913ec974Sbeck #define BIO_R_IN_USE					 123
7785b37fcf3Sryker #define BIO_R_KEEPALIVE					 109
7795b37fcf3Sryker #define BIO_R_NBIO_CONNECT_ERROR			 110
7805b37fcf3Sryker #define BIO_R_NO_ACCEPT_PORT_SPECIFIED			 111
781913ec974Sbeck #define BIO_R_NO_HOSTNAME_SPECIFIED			 112
7825b37fcf3Sryker #define BIO_R_NO_PORT_DEFINED				 113
7835b37fcf3Sryker #define BIO_R_NO_PORT_SPECIFIED				 114
784da347917Sbeck #define BIO_R_NO_SUCH_FILE				 128
7855b37fcf3Sryker #define BIO_R_NULL_PARAMETER				 115
786913ec974Sbeck #define BIO_R_TAG_MISMATCH				 116
787913ec974Sbeck #define BIO_R_UNABLE_TO_BIND_SOCKET			 117
788913ec974Sbeck #define BIO_R_UNABLE_TO_CREATE_SOCKET			 118
789913ec974Sbeck #define BIO_R_UNABLE_TO_LISTEN_SOCKET			 119
790913ec974Sbeck #define BIO_R_UNINITIALIZED				 120
791913ec974Sbeck #define BIO_R_UNSUPPORTED_METHOD			 121
792ba5406e9Sbeck #define BIO_R_WRITE_TO_READ_ONLY_BIO			 126
793913ec974Sbeck #define BIO_R_WSASTARTUP				 122
7945b37fcf3Sryker 
7955b37fcf3Sryker #ifdef  __cplusplus
7965b37fcf3Sryker }
7975b37fcf3Sryker #endif
7985b37fcf3Sryker #endif
799