166bae5e7Schristos/*
266bae5e7Schristos * {- join("\n * ", @autowarntext) -}
366bae5e7Schristos *
466bae5e7Schristos * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
566bae5e7Schristos *
666bae5e7Schristos * Licensed under the Apache License 2.0 (the "License").  You may not use
766bae5e7Schristos * this file except in compliance with the License.  You can obtain a copy
866bae5e7Schristos * in the file LICENSE in the source distribution or at
966bae5e7Schristos * https://www.openssl.org/source/license.html
1066bae5e7Schristos */
1166bae5e7Schristos{-
1266bae5e7Schristosuse OpenSSL::stackhash qw(generate_stack_macros);
1366bae5e7Schristos-}
1466bae5e7Schristos
1566bae5e7Schristos#ifndef OPENSSL_BIO_H
1666bae5e7Schristos# define OPENSSL_BIO_H
1766bae5e7Schristos# pragma once
1866bae5e7Schristos
1966bae5e7Schristos# include <openssl/macros.h>
2066bae5e7Schristos# ifndef OPENSSL_NO_DEPRECATED_3_0
2166bae5e7Schristos#  define HEADER_BIO_H
2266bae5e7Schristos# endif
2366bae5e7Schristos
2466bae5e7Schristos# include <openssl/e_os2.h>
2566bae5e7Schristos
2666bae5e7Schristos# ifndef OPENSSL_NO_STDIO
2766bae5e7Schristos#  include <stdio.h>
2866bae5e7Schristos# endif
2966bae5e7Schristos# include <stdarg.h>
3066bae5e7Schristos
3166bae5e7Schristos# include <openssl/crypto.h>
3266bae5e7Schristos# include <openssl/bioerr.h>
3366bae5e7Schristos# include <openssl/core.h>
3466bae5e7Schristos
3566bae5e7Schristos#ifdef  __cplusplus
3666bae5e7Schristosextern "C" {
3766bae5e7Schristos#endif
3866bae5e7Schristos
3966bae5e7Schristos/* There are the classes of BIOs */
4066bae5e7Schristos# define BIO_TYPE_DESCRIPTOR     0x0100 /* socket, fd, connect or accept */
4166bae5e7Schristos# define BIO_TYPE_FILTER         0x0200
4266bae5e7Schristos# define BIO_TYPE_SOURCE_SINK    0x0400
4366bae5e7Schristos
4466bae5e7Schristos/* These are the 'types' of BIOs */
4566bae5e7Schristos# define BIO_TYPE_NONE             0
4666bae5e7Schristos# define BIO_TYPE_MEM            ( 1|BIO_TYPE_SOURCE_SINK)
4766bae5e7Schristos# define BIO_TYPE_FILE           ( 2|BIO_TYPE_SOURCE_SINK)
4866bae5e7Schristos
4966bae5e7Schristos# define BIO_TYPE_FD             ( 4|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
5066bae5e7Schristos# define BIO_TYPE_SOCKET         ( 5|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
5166bae5e7Schristos# define BIO_TYPE_NULL           ( 6|BIO_TYPE_SOURCE_SINK)
5266bae5e7Schristos# define BIO_TYPE_SSL            ( 7|BIO_TYPE_FILTER)
5366bae5e7Schristos# define BIO_TYPE_MD             ( 8|BIO_TYPE_FILTER)
5466bae5e7Schristos# define BIO_TYPE_BUFFER         ( 9|BIO_TYPE_FILTER)
5566bae5e7Schristos# define BIO_TYPE_CIPHER         (10|BIO_TYPE_FILTER)
5666bae5e7Schristos# define BIO_TYPE_BASE64         (11|BIO_TYPE_FILTER)
5766bae5e7Schristos# define BIO_TYPE_CONNECT        (12|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
5866bae5e7Schristos# define BIO_TYPE_ACCEPT         (13|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
5966bae5e7Schristos
6066bae5e7Schristos# define BIO_TYPE_NBIO_TEST      (16|BIO_TYPE_FILTER)/* server proxy BIO */
6166bae5e7Schristos# define BIO_TYPE_NULL_FILTER    (17|BIO_TYPE_FILTER)
6266bae5e7Schristos# define BIO_TYPE_BIO            (19|BIO_TYPE_SOURCE_SINK)/* half a BIO pair */
6366bae5e7Schristos# define BIO_TYPE_LINEBUFFER     (20|BIO_TYPE_FILTER)
6466bae5e7Schristos# define BIO_TYPE_DGRAM          (21|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
6566bae5e7Schristos# define BIO_TYPE_ASN1           (22|BIO_TYPE_FILTER)
6666bae5e7Schristos# define BIO_TYPE_COMP           (23|BIO_TYPE_FILTER)
6766bae5e7Schristos# ifndef OPENSSL_NO_SCTP
6866bae5e7Schristos#  define BIO_TYPE_DGRAM_SCTP    (24|BIO_TYPE_SOURCE_SINK|BIO_TYPE_DESCRIPTOR)
6966bae5e7Schristos# endif
7066bae5e7Schristos# define BIO_TYPE_CORE_TO_PROV   (25|BIO_TYPE_SOURCE_SINK)
7166bae5e7Schristos
7266bae5e7Schristos#define BIO_TYPE_START           128
7366bae5e7Schristos
7466bae5e7Schristos/*
7566bae5e7Schristos * BIO_FILENAME_READ|BIO_CLOSE to open or close on free.
7666bae5e7Schristos * BIO_set_fp(in,stdin,BIO_NOCLOSE);
7766bae5e7Schristos */
7866bae5e7Schristos# define BIO_NOCLOSE             0x00
7966bae5e7Schristos# define BIO_CLOSE               0x01
8066bae5e7Schristos
8166bae5e7Schristos/*
8266bae5e7Schristos * These are used in the following macros and are passed to BIO_ctrl()
8366bae5e7Schristos */
8466bae5e7Schristos# define BIO_CTRL_RESET          1/* opt - rewind/zero etc */
8566bae5e7Schristos# define BIO_CTRL_EOF            2/* opt - are we at the eof */
8666bae5e7Schristos# define BIO_CTRL_INFO           3/* opt - extra tit-bits */
8766bae5e7Schristos# define BIO_CTRL_SET            4/* man - set the 'IO' type */
8866bae5e7Schristos# define BIO_CTRL_GET            5/* man - get the 'IO' type */
8966bae5e7Schristos# define BIO_CTRL_PUSH           6/* opt - internal, used to signify change */
9066bae5e7Schristos# define BIO_CTRL_POP            7/* opt - internal, used to signify change */
9166bae5e7Schristos# define BIO_CTRL_GET_CLOSE      8/* man - set the 'close' on free */
9266bae5e7Schristos# define BIO_CTRL_SET_CLOSE      9/* man - set the 'close' on free */
9366bae5e7Schristos# define BIO_CTRL_PENDING        10/* opt - is their more data buffered */
9466bae5e7Schristos# define BIO_CTRL_FLUSH          11/* opt - 'flush' buffered output */
9566bae5e7Schristos# define BIO_CTRL_DUP            12/* man - extra stuff for 'duped' BIO */
9666bae5e7Schristos# define BIO_CTRL_WPENDING       13/* opt - number of bytes still to write */
9766bae5e7Schristos# define BIO_CTRL_SET_CALLBACK   14/* opt - set callback function */
9866bae5e7Schristos# define BIO_CTRL_GET_CALLBACK   15/* opt - set callback function */
9966bae5e7Schristos
10066bae5e7Schristos# define BIO_CTRL_PEEK           29/* BIO_f_buffer special */
10166bae5e7Schristos# define BIO_CTRL_SET_FILENAME   30/* BIO_s_file special */
10266bae5e7Schristos
10366bae5e7Schristos/* dgram BIO stuff */
10466bae5e7Schristos# define BIO_CTRL_DGRAM_CONNECT       31/* BIO dgram special */
10566bae5e7Schristos# define BIO_CTRL_DGRAM_SET_CONNECTED 32/* allow for an externally connected
10666bae5e7Schristos                                         * socket to be passed in */
10766bae5e7Schristos# define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33/* setsockopt, essentially */
10866bae5e7Schristos# define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34/* getsockopt, essentially */
10966bae5e7Schristos# define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35/* setsockopt, essentially */
11066bae5e7Schristos# define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36/* getsockopt, essentially */
11166bae5e7Schristos
11266bae5e7Schristos# define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37/* flag whether the last */
11366bae5e7Schristos# define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38/* I/O operation timed out */
11466bae5e7Schristos
11566bae5e7Schristos/* #ifdef IP_MTU_DISCOVER */
11666bae5e7Schristos# define BIO_CTRL_DGRAM_MTU_DISCOVER       39/* set DF bit on egress packets */
11766bae5e7Schristos/* #endif */
11866bae5e7Schristos
11966bae5e7Schristos# define BIO_CTRL_DGRAM_QUERY_MTU          40/* as kernel for current MTU */
12066bae5e7Schristos# define BIO_CTRL_DGRAM_GET_FALLBACK_MTU   47
12166bae5e7Schristos# define BIO_CTRL_DGRAM_GET_MTU            41/* get cached value for MTU */
12266bae5e7Schristos# define BIO_CTRL_DGRAM_SET_MTU            42/* set cached value for MTU.
12366bae5e7Schristos                                              * want to use this if asking
12466bae5e7Schristos                                              * the kernel fails */
12566bae5e7Schristos
12666bae5e7Schristos# define BIO_CTRL_DGRAM_MTU_EXCEEDED       43/* check whether the MTU was
12766bae5e7Schristos                                              * exceed in the previous write
12866bae5e7Schristos                                              * operation */
12966bae5e7Schristos
13066bae5e7Schristos# define BIO_CTRL_DGRAM_GET_PEER           46
13166bae5e7Schristos# define BIO_CTRL_DGRAM_SET_PEER           44/* Destination for the data */
13266bae5e7Schristos
13366bae5e7Schristos# define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT   45/* Next DTLS handshake timeout
13466bae5e7Schristos                                              * to adjust socket timeouts */
13566bae5e7Schristos# define BIO_CTRL_DGRAM_SET_DONT_FRAG      48
13666bae5e7Schristos
13766bae5e7Schristos# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD   49
13866bae5e7Schristos
13966bae5e7Schristos/* Deliberately outside of OPENSSL_NO_SCTP - used in bss_dgram.c */
14066bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE    50
14166bae5e7Schristos# ifndef OPENSSL_NO_SCTP
14266bae5e7Schristos/* SCTP stuff */
14366bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY                51
14466bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY               52
14566bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD               53
14666bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO         60
14766bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO         61
14866bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO         62
14966bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO         63
15066bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_GET_PRINFO                  64
15166bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_SET_PRINFO                  65
15266bae5e7Schristos#  define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN               70
15366bae5e7Schristos# endif
15466bae5e7Schristos
15566bae5e7Schristos# define BIO_CTRL_DGRAM_SET_PEEK_MODE      71
15666bae5e7Schristos
15766bae5e7Schristos/*
15866bae5e7Schristos * internal BIO:
15966bae5e7Schristos * # define BIO_CTRL_SET_KTLS_SEND                 72
16066bae5e7Schristos * # define BIO_CTRL_SET_KTLS_SEND_CTRL_MSG        74
16166bae5e7Schristos * # define BIO_CTRL_CLEAR_KTLS_CTRL_MSG           75
16266bae5e7Schristos */
16366bae5e7Schristos
16466bae5e7Schristos# define BIO_CTRL_GET_KTLS_SEND                 73
16566bae5e7Schristos# define BIO_CTRL_GET_KTLS_RECV                 76
16666bae5e7Schristos
16766bae5e7Schristos# define BIO_CTRL_DGRAM_SCTP_WAIT_FOR_DRY       77
16866bae5e7Schristos# define BIO_CTRL_DGRAM_SCTP_MSG_WAITING        78
16966bae5e7Schristos
17066bae5e7Schristos/* BIO_f_prefix controls */
17166bae5e7Schristos# define BIO_CTRL_SET_PREFIX                    79
17266bae5e7Schristos# define BIO_CTRL_SET_INDENT                    80
17366bae5e7Schristos# define BIO_CTRL_GET_INDENT                    81
17466bae5e7Schristos
17566bae5e7Schristos# ifndef OPENSSL_NO_KTLS
17666bae5e7Schristos#  define BIO_get_ktls_send(b)         \
17766bae5e7Schristos     (BIO_ctrl(b, BIO_CTRL_GET_KTLS_SEND, 0, NULL) > 0)
17866bae5e7Schristos#  define BIO_get_ktls_recv(b)         \
17966bae5e7Schristos     (BIO_ctrl(b, BIO_CTRL_GET_KTLS_RECV, 0, NULL) > 0)
18066bae5e7Schristos# else
18166bae5e7Schristos#  define BIO_get_ktls_send(b)  (0)
18266bae5e7Schristos#  define BIO_get_ktls_recv(b)  (0)
18366bae5e7Schristos# endif
18466bae5e7Schristos
18566bae5e7Schristos/* modifiers */
18666bae5e7Schristos# define BIO_FP_READ             0x02
18766bae5e7Schristos# define BIO_FP_WRITE            0x04
18866bae5e7Schristos# define BIO_FP_APPEND           0x08
18966bae5e7Schristos# define BIO_FP_TEXT             0x10
19066bae5e7Schristos
19166bae5e7Schristos# define BIO_FLAGS_READ          0x01
19266bae5e7Schristos# define BIO_FLAGS_WRITE         0x02
19366bae5e7Schristos# define BIO_FLAGS_IO_SPECIAL    0x04
19466bae5e7Schristos# define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
19566bae5e7Schristos# define BIO_FLAGS_SHOULD_RETRY  0x08
19666bae5e7Schristos# ifndef OPENSSL_NO_DEPRECATED_3_0
19766bae5e7Schristos/* This #define was replaced by an internal constant and should not be used. */
19866bae5e7Schristos#  define BIO_FLAGS_UPLINK       0
19966bae5e7Schristos# endif
20066bae5e7Schristos
20166bae5e7Schristos# define BIO_FLAGS_BASE64_NO_NL  0x100
20266bae5e7Schristos
20366bae5e7Schristos/*
20466bae5e7Schristos * This is used with memory BIOs:
20566bae5e7Schristos * BIO_FLAGS_MEM_RDONLY means we shouldn't free up or change the data in any way;
20666bae5e7Schristos * BIO_FLAGS_NONCLEAR_RST means we shouldn't clear data on reset.
20766bae5e7Schristos */
20866bae5e7Schristos# define BIO_FLAGS_MEM_RDONLY    0x200
20966bae5e7Schristos# define BIO_FLAGS_NONCLEAR_RST  0x400
21066bae5e7Schristos# define BIO_FLAGS_IN_EOF        0x800
21166bae5e7Schristos
21266bae5e7Schristos/* the BIO FLAGS values 0x1000 to 0x4000 are reserved for internal KTLS flags */
21366bae5e7Schristos
21466bae5e7Schristostypedef union bio_addr_st BIO_ADDR;
21566bae5e7Schristostypedef struct bio_addrinfo_st BIO_ADDRINFO;
21666bae5e7Schristos
21766bae5e7Schristosint BIO_get_new_index(void);
21866bae5e7Schristosvoid BIO_set_flags(BIO *b, int flags);
21966bae5e7Schristosint BIO_test_flags(const BIO *b, int flags);
22066bae5e7Schristosvoid BIO_clear_flags(BIO *b, int flags);
22166bae5e7Schristos
22266bae5e7Schristos# define BIO_get_flags(b) BIO_test_flags(b, ~(0x0))
22366bae5e7Schristos# define BIO_set_retry_special(b) \
22466bae5e7Schristos                BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
22566bae5e7Schristos# define BIO_set_retry_read(b) \
22666bae5e7Schristos                BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
22766bae5e7Schristos# define BIO_set_retry_write(b) \
22866bae5e7Schristos                BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
22966bae5e7Schristos
23066bae5e7Schristos/* These are normally used internally in BIOs */
23166bae5e7Schristos# define BIO_clear_retry_flags(b) \
23266bae5e7Schristos                BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
23366bae5e7Schristos# define BIO_get_retry_flags(b) \
23466bae5e7Schristos                BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
23566bae5e7Schristos
23666bae5e7Schristos/* These should be used by the application to tell why we should retry */
23766bae5e7Schristos# define BIO_should_read(a)              BIO_test_flags(a, BIO_FLAGS_READ)
23866bae5e7Schristos# define BIO_should_write(a)             BIO_test_flags(a, BIO_FLAGS_WRITE)
23966bae5e7Schristos# define BIO_should_io_special(a)        BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL)
24066bae5e7Schristos# define BIO_retry_type(a)               BIO_test_flags(a, BIO_FLAGS_RWS)
24166bae5e7Schristos# define BIO_should_retry(a)             BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY)
24266bae5e7Schristos
24366bae5e7Schristos/*
24466bae5e7Schristos * The next three are used in conjunction with the BIO_should_io_special()
24566bae5e7Schristos * condition.  After this returns true, BIO *BIO_get_retry_BIO(BIO *bio, int
24666bae5e7Schristos * *reason); will walk the BIO stack and return the 'reason' for the special
24766bae5e7Schristos * and the offending BIO. Given a BIO, BIO_get_retry_reason(bio) will return
24866bae5e7Schristos * the code.
24966bae5e7Schristos */
25066bae5e7Schristos/*
25166bae5e7Schristos * Returned from the SSL bio when the certificate retrieval code had an error
25266bae5e7Schristos */
25366bae5e7Schristos# define BIO_RR_SSL_X509_LOOKUP          0x01
25466bae5e7Schristos/* Returned from the connect BIO when a connect would have blocked */
25566bae5e7Schristos# define BIO_RR_CONNECT                  0x02
25666bae5e7Schristos/* Returned from the accept BIO when an accept would have blocked */
25766bae5e7Schristos# define BIO_RR_ACCEPT                   0x03
25866bae5e7Schristos
25966bae5e7Schristos/* These are passed by the BIO callback */
26066bae5e7Schristos# define BIO_CB_FREE     0x01
26166bae5e7Schristos# define BIO_CB_READ     0x02
26266bae5e7Schristos# define BIO_CB_WRITE    0x03
26366bae5e7Schristos# define BIO_CB_PUTS     0x04
26466bae5e7Schristos# define BIO_CB_GETS     0x05
26566bae5e7Schristos# define BIO_CB_CTRL     0x06
26666bae5e7Schristos
26766bae5e7Schristos/*
26866bae5e7Schristos * The callback is called before and after the underling operation, The
26966bae5e7Schristos * BIO_CB_RETURN flag indicates if it is after the call
27066bae5e7Schristos */
27166bae5e7Schristos# define BIO_CB_RETURN   0x80
27266bae5e7Schristos# define BIO_CB_return(a) ((a)|BIO_CB_RETURN)
27366bae5e7Schristos# define BIO_cb_pre(a)   (!((a)&BIO_CB_RETURN))
27466bae5e7Schristos# define BIO_cb_post(a)  ((a)&BIO_CB_RETURN)
27566bae5e7Schristos
27666bae5e7Schristos# ifndef OPENSSL_NO_DEPRECATED_3_0
27766bae5e7Schristostypedef long (*BIO_callback_fn)(BIO *b, int oper, const char *argp, int argi,
27866bae5e7Schristos                                long argl, long ret);
27966bae5e7SchristosOSSL_DEPRECATEDIN_3_0 BIO_callback_fn BIO_get_callback(const BIO *b);
28066bae5e7SchristosOSSL_DEPRECATEDIN_3_0 void BIO_set_callback(BIO *b, BIO_callback_fn callback);
28166bae5e7SchristosOSSL_DEPRECATEDIN_3_0 long BIO_debug_callback(BIO *bio, int cmd,
28266bae5e7Schristos                                               const char *argp, int argi,
28366bae5e7Schristos                                               long argl, long ret);
28466bae5e7Schristos# endif
28566bae5e7Schristos
28666bae5e7Schristostypedef long (*BIO_callback_fn_ex)(BIO *b, int oper, const char *argp,
28766bae5e7Schristos                                   size_t len, int argi,
28866bae5e7Schristos                                   long argl, int ret, size_t *processed);
28966bae5e7SchristosBIO_callback_fn_ex BIO_get_callback_ex(const BIO *b);
29066bae5e7Schristosvoid BIO_set_callback_ex(BIO *b, BIO_callback_fn_ex callback);
29166bae5e7Schristoslong BIO_debug_callback_ex(BIO *bio, int oper, const char *argp, size_t len,
29266bae5e7Schristos                           int argi, long argl, int ret, size_t *processed);
29366bae5e7Schristos
29466bae5e7Schristoschar *BIO_get_callback_arg(const BIO *b);
29566bae5e7Schristosvoid BIO_set_callback_arg(BIO *b, char *arg);
29666bae5e7Schristos
29766bae5e7Schristostypedef struct bio_method_st BIO_METHOD;
29866bae5e7Schristos
29966bae5e7Schristosconst char *BIO_method_name(const BIO *b);
30066bae5e7Schristosint BIO_method_type(const BIO *b);
30166bae5e7Schristos
30266bae5e7Schristostypedef int BIO_info_cb(BIO *, int, int);
30366bae5e7Schristostypedef BIO_info_cb bio_info_cb;  /* backward compatibility */
30466bae5e7Schristos
30566bae5e7Schristos{-
30666bae5e7Schristos    generate_stack_macros("BIO");
30766bae5e7Schristos-}
30866bae5e7Schristos
30966bae5e7Schristos
31066bae5e7Schristos/* Prefix and suffix callback in ASN1 BIO */
31166bae5e7Schristostypedef int asn1_ps_func (BIO *b, unsigned char **pbuf, int *plen,
31266bae5e7Schristos                          void *parg);
31366bae5e7Schristos
31466bae5e7Schristostypedef void (*BIO_dgram_sctp_notification_handler_fn) (BIO *b,
31566bae5e7Schristos                                                        void *context,
31666bae5e7Schristos                                                        void *buf);
31766bae5e7Schristos# ifndef OPENSSL_NO_SCTP
31866bae5e7Schristos/* SCTP parameter structs */
31966bae5e7Schristosstruct bio_dgram_sctp_sndinfo {
32066bae5e7Schristos    uint16_t snd_sid;
32166bae5e7Schristos    uint16_t snd_flags;
32266bae5e7Schristos    uint32_t snd_ppid;
32366bae5e7Schristos    uint32_t snd_context;
32466bae5e7Schristos};
32566bae5e7Schristos
32666bae5e7Schristosstruct bio_dgram_sctp_rcvinfo {
32766bae5e7Schristos    uint16_t rcv_sid;
32866bae5e7Schristos    uint16_t rcv_ssn;
32966bae5e7Schristos    uint16_t rcv_flags;
33066bae5e7Schristos    uint32_t rcv_ppid;
33166bae5e7Schristos    uint32_t rcv_tsn;
33266bae5e7Schristos    uint32_t rcv_cumtsn;
33366bae5e7Schristos    uint32_t rcv_context;
33466bae5e7Schristos};
33566bae5e7Schristos
33666bae5e7Schristosstruct bio_dgram_sctp_prinfo {
33766bae5e7Schristos    uint16_t pr_policy;
33866bae5e7Schristos    uint32_t pr_value;
33966bae5e7Schristos};
34066bae5e7Schristos# endif
34166bae5e7Schristos
34266bae5e7Schristos/*
34366bae5e7Schristos * #define BIO_CONN_get_param_hostname BIO_ctrl
34466bae5e7Schristos */
34566bae5e7Schristos
34666bae5e7Schristos# define BIO_C_SET_CONNECT                       100
34766bae5e7Schristos# define BIO_C_DO_STATE_MACHINE                  101
34866bae5e7Schristos# define BIO_C_SET_NBIO                          102
34966bae5e7Schristos/* # define BIO_C_SET_PROXY_PARAM                   103 */
35066bae5e7Schristos# define BIO_C_SET_FD                            104
35166bae5e7Schristos# define BIO_C_GET_FD                            105
35266bae5e7Schristos# define BIO_C_SET_FILE_PTR                      106
35366bae5e7Schristos# define BIO_C_GET_FILE_PTR                      107
35466bae5e7Schristos# define BIO_C_SET_FILENAME                      108
35566bae5e7Schristos# define BIO_C_SET_SSL                           109
35666bae5e7Schristos# define BIO_C_GET_SSL                           110
35766bae5e7Schristos# define BIO_C_SET_MD                            111
35866bae5e7Schristos# define BIO_C_GET_MD                            112
35966bae5e7Schristos# define BIO_C_GET_CIPHER_STATUS                 113
36066bae5e7Schristos# define BIO_C_SET_BUF_MEM                       114
36166bae5e7Schristos# define BIO_C_GET_BUF_MEM_PTR                   115
36266bae5e7Schristos# define BIO_C_GET_BUFF_NUM_LINES                116
36366bae5e7Schristos# define BIO_C_SET_BUFF_SIZE                     117
36466bae5e7Schristos# define BIO_C_SET_ACCEPT                        118
36566bae5e7Schristos# define BIO_C_SSL_MODE                          119
36666bae5e7Schristos# define BIO_C_GET_MD_CTX                        120
36766bae5e7Schristos/* # define BIO_C_GET_PROXY_PARAM                   121 */
36866bae5e7Schristos# define BIO_C_SET_BUFF_READ_DATA                122/* data to read first */
36966bae5e7Schristos# define BIO_C_GET_CONNECT                       123
37066bae5e7Schristos# define BIO_C_GET_ACCEPT                        124
37166bae5e7Schristos# define BIO_C_SET_SSL_RENEGOTIATE_BYTES         125
37266bae5e7Schristos# define BIO_C_GET_SSL_NUM_RENEGOTIATES          126
37366bae5e7Schristos# define BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT       127
37466bae5e7Schristos# define BIO_C_FILE_SEEK                         128
37566bae5e7Schristos# define BIO_C_GET_CIPHER_CTX                    129
37666bae5e7Schristos# define BIO_C_SET_BUF_MEM_EOF_RETURN            130/* return end of input
37766bae5e7Schristos                                                     * value */
37866bae5e7Schristos# define BIO_C_SET_BIND_MODE                     131
37966bae5e7Schristos# define BIO_C_GET_BIND_MODE                     132
38066bae5e7Schristos# define BIO_C_FILE_TELL                         133
38166bae5e7Schristos# define BIO_C_GET_SOCKS                         134
38266bae5e7Schristos# define BIO_C_SET_SOCKS                         135
38366bae5e7Schristos
38466bae5e7Schristos# define BIO_C_SET_WRITE_BUF_SIZE                136/* for BIO_s_bio */
38566bae5e7Schristos# define BIO_C_GET_WRITE_BUF_SIZE                137
38666bae5e7Schristos# define BIO_C_MAKE_BIO_PAIR                     138
38766bae5e7Schristos# define BIO_C_DESTROY_BIO_PAIR                  139
38866bae5e7Schristos# define BIO_C_GET_WRITE_GUARANTEE               140
38966bae5e7Schristos# define BIO_C_GET_READ_REQUEST                  141
39066bae5e7Schristos# define BIO_C_SHUTDOWN_WR                       142
39166bae5e7Schristos# define BIO_C_NREAD0                            143
39266bae5e7Schristos# define BIO_C_NREAD                             144
39366bae5e7Schristos# define BIO_C_NWRITE0                           145
39466bae5e7Schristos# define BIO_C_NWRITE                            146
39566bae5e7Schristos# define BIO_C_RESET_READ_REQUEST                147
39666bae5e7Schristos# define BIO_C_SET_MD_CTX                        148
39766bae5e7Schristos
39866bae5e7Schristos# define BIO_C_SET_PREFIX                        149
39966bae5e7Schristos# define BIO_C_GET_PREFIX                        150
40066bae5e7Schristos# define BIO_C_SET_SUFFIX                        151
40166bae5e7Schristos# define BIO_C_GET_SUFFIX                        152
40266bae5e7Schristos
40366bae5e7Schristos# define BIO_C_SET_EX_ARG                        153
40466bae5e7Schristos# define BIO_C_GET_EX_ARG                        154
40566bae5e7Schristos
40666bae5e7Schristos# define BIO_C_SET_CONNECT_MODE                  155
40766bae5e7Schristos
40866bae5e7Schristos# define BIO_set_app_data(s,arg)         BIO_set_ex_data(s,0,arg)
40966bae5e7Schristos# define BIO_get_app_data(s)             BIO_get_ex_data(s,0)
41066bae5e7Schristos
41166bae5e7Schristos# define BIO_set_nbio(b,n)             BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL)
41266bae5e7Schristos
41366bae5e7Schristos# ifndef OPENSSL_NO_SOCK
41466bae5e7Schristos/* IP families we support, for BIO_s_connect() and BIO_s_accept() */
41566bae5e7Schristos/* Note: the underlying operating system may not support some of them */
41666bae5e7Schristos#  define BIO_FAMILY_IPV4                         4
41766bae5e7Schristos#  define BIO_FAMILY_IPV6                         6
41866bae5e7Schristos#  define BIO_FAMILY_IPANY                        256
41966bae5e7Schristos
42066bae5e7Schristos/* BIO_s_connect() */
42166bae5e7Schristos#  define BIO_set_conn_hostname(b,name) BIO_ctrl(b,BIO_C_SET_CONNECT,0, \
42266bae5e7Schristos                                                 (char *)(name))
42366bae5e7Schristos#  define BIO_set_conn_port(b,port)     BIO_ctrl(b,BIO_C_SET_CONNECT,1, \
42466bae5e7Schristos                                                 (char *)(port))
42566bae5e7Schristos#  define BIO_set_conn_address(b,addr)  BIO_ctrl(b,BIO_C_SET_CONNECT,2, \
42666bae5e7Schristos                                                 (char *)(addr))
42766bae5e7Schristos#  define BIO_set_conn_ip_family(b,f)   BIO_int_ctrl(b,BIO_C_SET_CONNECT,3,f)
42866bae5e7Schristos#  define BIO_get_conn_hostname(b)      ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,0))
42966bae5e7Schristos#  define BIO_get_conn_port(b)          ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,1))
43066bae5e7Schristos#  define BIO_get_conn_address(b)       ((const BIO_ADDR *)BIO_ptr_ctrl(b,BIO_C_GET_CONNECT,2))
43166bae5e7Schristos#  define BIO_get_conn_ip_family(b)     BIO_ctrl(b,BIO_C_GET_CONNECT,3,NULL)
43266bae5e7Schristos#  define BIO_set_conn_mode(b,n)        BIO_ctrl(b,BIO_C_SET_CONNECT_MODE,(n),NULL)
43366bae5e7Schristos
43466bae5e7Schristos/* BIO_s_accept() */
43566bae5e7Schristos#  define BIO_set_accept_name(b,name)   BIO_ctrl(b,BIO_C_SET_ACCEPT,0, \
43666bae5e7Schristos                                                 (char *)(name))
43766bae5e7Schristos#  define BIO_set_accept_port(b,port)   BIO_ctrl(b,BIO_C_SET_ACCEPT,1, \
43866bae5e7Schristos                                                 (char *)(port))
43966bae5e7Schristos#  define BIO_get_accept_name(b)        ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,0))
44066bae5e7Schristos#  define BIO_get_accept_port(b)        ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,1))
44166bae5e7Schristos#  define BIO_get_peer_name(b)          ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,2))
44266bae5e7Schristos#  define BIO_get_peer_port(b)          ((const char *)BIO_ptr_ctrl(b,BIO_C_GET_ACCEPT,3))
44366bae5e7Schristos/* #define BIO_set_nbio(b,n)    BIO_ctrl(b,BIO_C_SET_NBIO,(n),NULL) */
44466bae5e7Schristos#  define BIO_set_nbio_accept(b,n)      BIO_ctrl(b,BIO_C_SET_ACCEPT,2,(n)?(void *)"a":NULL)
44566bae5e7Schristos#  define BIO_set_accept_bios(b,bio)    BIO_ctrl(b,BIO_C_SET_ACCEPT,3, \
44666bae5e7Schristos                                                 (char *)(bio))
44766bae5e7Schristos#  define BIO_set_accept_ip_family(b,f) BIO_int_ctrl(b,BIO_C_SET_ACCEPT,4,f)
44866bae5e7Schristos#  define BIO_get_accept_ip_family(b)   BIO_ctrl(b,BIO_C_GET_ACCEPT,4,NULL)
44966bae5e7Schristos
45066bae5e7Schristos/* Aliases kept for backward compatibility */
45166bae5e7Schristos#  define BIO_BIND_NORMAL                 0
45266bae5e7Schristos#  define BIO_BIND_REUSEADDR              BIO_SOCK_REUSEADDR
45366bae5e7Schristos#  define BIO_BIND_REUSEADDR_IF_UNUSED    BIO_SOCK_REUSEADDR
45466bae5e7Schristos#  define BIO_set_bind_mode(b,mode) BIO_ctrl(b,BIO_C_SET_BIND_MODE,mode,NULL)
45566bae5e7Schristos#  define BIO_get_bind_mode(b)    BIO_ctrl(b,BIO_C_GET_BIND_MODE,0,NULL)
45666bae5e7Schristos# endif /* OPENSSL_NO_SOCK */
45766bae5e7Schristos
45866bae5e7Schristos# define BIO_do_connect(b)       BIO_do_handshake(b)
45966bae5e7Schristos# define BIO_do_accept(b)        BIO_do_handshake(b)
46066bae5e7Schristos
46166bae5e7Schristos# define BIO_do_handshake(b)     BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)
46266bae5e7Schristos
46366bae5e7Schristos/* BIO_s_datagram(), BIO_s_fd(), BIO_s_socket(), BIO_s_accept() and BIO_s_connect() */
46466bae5e7Schristos# define BIO_set_fd(b,fd,c)      BIO_int_ctrl(b,BIO_C_SET_FD,c,fd)
46566bae5e7Schristos# define BIO_get_fd(b,c)         BIO_ctrl(b,BIO_C_GET_FD,0,(char *)(c))
46666bae5e7Schristos
46766bae5e7Schristos/* BIO_s_file() */
46866bae5e7Schristos# define BIO_set_fp(b,fp,c)      BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)(fp))
46966bae5e7Schristos# define BIO_get_fp(b,fpp)       BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)(fpp))
47066bae5e7Schristos
47166bae5e7Schristos/* BIO_s_fd() and BIO_s_file() */
47266bae5e7Schristos# define BIO_seek(b,ofs) (int)BIO_ctrl(b,BIO_C_FILE_SEEK,ofs,NULL)
47366bae5e7Schristos# define BIO_tell(b)     (int)BIO_ctrl(b,BIO_C_FILE_TELL,0,NULL)
47466bae5e7Schristos
47566bae5e7Schristos/*
47666bae5e7Schristos * name is cast to lose const, but might be better to route through a
47766bae5e7Schristos * function so we can do it safely
47866bae5e7Schristos */
47966bae5e7Schristos# ifdef CONST_STRICT
48066bae5e7Schristos/*
48166bae5e7Schristos * If you are wondering why this isn't defined, its because CONST_STRICT is
48266bae5e7Schristos * purely a compile-time kludge to allow const to be checked.
48366bae5e7Schristos */
48466bae5e7Schristosint BIO_read_filename(BIO *b, const char *name);
48566bae5e7Schristos# else
48666bae5e7Schristos#  define BIO_read_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
487*5b10f583Schristos                BIO_CLOSE|BIO_FP_READ,(char *)(intptr_t)(name))
48866bae5e7Schristos# endif
48966bae5e7Schristos# define BIO_write_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
49066bae5e7Schristos                BIO_CLOSE|BIO_FP_WRITE,name)
49166bae5e7Schristos# define BIO_append_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
49266bae5e7Schristos                BIO_CLOSE|BIO_FP_APPEND,name)
49366bae5e7Schristos# define BIO_rw_filename(b,name) (int)BIO_ctrl(b,BIO_C_SET_FILENAME, \
49466bae5e7Schristos                BIO_CLOSE|BIO_FP_READ|BIO_FP_WRITE,name)
49566bae5e7Schristos
49666bae5e7Schristos/*
49766bae5e7Schristos * WARNING WARNING, this ups the reference count on the read bio of the SSL
49866bae5e7Schristos * structure.  This is because the ssl read BIO is now pointed to by the
49966bae5e7Schristos * next_bio field in the bio.  So when you free the BIO, make sure you are
50066bae5e7Schristos * doing a BIO_free_all() to catch the underlying BIO.
50166bae5e7Schristos */
50266bae5e7Schristos# define BIO_set_ssl(b,ssl,c)    BIO_ctrl(b,BIO_C_SET_SSL,c,(char *)(ssl))
50366bae5e7Schristos# define BIO_get_ssl(b,sslp)     BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)(sslp))
50466bae5e7Schristos# define BIO_set_ssl_mode(b,client)      BIO_ctrl(b,BIO_C_SSL_MODE,client,NULL)
50566bae5e7Schristos# define BIO_set_ssl_renegotiate_bytes(b,num) \
50666bae5e7Schristos        BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_BYTES,num,NULL)
50766bae5e7Schristos# define BIO_get_num_renegotiates(b) \
50866bae5e7Schristos        BIO_ctrl(b,BIO_C_GET_SSL_NUM_RENEGOTIATES,0,NULL)
50966bae5e7Schristos# define BIO_set_ssl_renegotiate_timeout(b,seconds) \
51066bae5e7Schristos        BIO_ctrl(b,BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT,seconds,NULL)
51166bae5e7Schristos
51266bae5e7Schristos/* defined in evp.h */
51366bae5e7Schristos/* #define BIO_set_md(b,md)     BIO_ctrl(b,BIO_C_SET_MD,1,(char *)(md)) */
51466bae5e7Schristos
51566bae5e7Schristos# define BIO_get_mem_data(b,pp)  BIO_ctrl(b,BIO_CTRL_INFO,0,(char *)(pp))
51666bae5e7Schristos# define BIO_set_mem_buf(b,bm,c) BIO_ctrl(b,BIO_C_SET_BUF_MEM,c,(char *)(bm))
51766bae5e7Schristos# define BIO_get_mem_ptr(b,pp)   BIO_ctrl(b,BIO_C_GET_BUF_MEM_PTR,0, \
51866bae5e7Schristos                                          (char *)(pp))
51966bae5e7Schristos# define BIO_set_mem_eof_return(b,v) \
52066bae5e7Schristos                                BIO_ctrl(b,BIO_C_SET_BUF_MEM_EOF_RETURN,v,NULL)
52166bae5e7Schristos
52266bae5e7Schristos/* For the BIO_f_buffer() type */
52366bae5e7Schristos# define BIO_get_buffer_num_lines(b)     BIO_ctrl(b,BIO_C_GET_BUFF_NUM_LINES,0,NULL)
52466bae5e7Schristos# define BIO_set_buffer_size(b,size)     BIO_ctrl(b,BIO_C_SET_BUFF_SIZE,size,NULL)
52566bae5e7Schristos# define BIO_set_read_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,0)
52666bae5e7Schristos# define BIO_set_write_buffer_size(b,size) BIO_int_ctrl(b,BIO_C_SET_BUFF_SIZE,size,1)
52766bae5e7Schristos# define BIO_set_buffer_read_data(b,buf,num) BIO_ctrl(b,BIO_C_SET_BUFF_READ_DATA,num,buf)
52866bae5e7Schristos
52966bae5e7Schristos/* Don't use the next one unless you know what you are doing :-) */
53066bae5e7Schristos# define BIO_dup_state(b,ret)    BIO_ctrl(b,BIO_CTRL_DUP,0,(char *)(ret))
53166bae5e7Schristos
53266bae5e7Schristos# define BIO_reset(b)            (int)BIO_ctrl(b,BIO_CTRL_RESET,0,NULL)
53366bae5e7Schristos# define BIO_eof(b)              (int)BIO_ctrl(b,BIO_CTRL_EOF,0,NULL)
53466bae5e7Schristos# define BIO_set_close(b,c)      (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
53566bae5e7Schristos# define BIO_get_close(b)        (int)BIO_ctrl(b,BIO_CTRL_GET_CLOSE,0,NULL)
53666bae5e7Schristos# define BIO_pending(b)          (int)BIO_ctrl(b,BIO_CTRL_PENDING,0,NULL)
53766bae5e7Schristos# define BIO_wpending(b)         (int)BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL)
53866bae5e7Schristos/* ...pending macros have inappropriate return type */
53966bae5e7Schristossize_t BIO_ctrl_pending(BIO *b);
54066bae5e7Schristossize_t BIO_ctrl_wpending(BIO *b);
54166bae5e7Schristos# define BIO_flush(b)            (int)BIO_ctrl(b,BIO_CTRL_FLUSH,0,NULL)
54266bae5e7Schristos# define BIO_get_info_callback(b,cbp) (int)BIO_ctrl(b,BIO_CTRL_GET_CALLBACK,0, \
54366bae5e7Schristos                                                   cbp)
54466bae5e7Schristos# define BIO_set_info_callback(b,cb) (int)BIO_callback_ctrl(b,BIO_CTRL_SET_CALLBACK,cb)
54566bae5e7Schristos
54666bae5e7Schristos/* For the BIO_f_buffer() type */
54766bae5e7Schristos# define BIO_buffer_get_num_lines(b) BIO_ctrl(b,BIO_CTRL_GET,0,NULL)
54866bae5e7Schristos# define BIO_buffer_peek(b,s,l) BIO_ctrl(b,BIO_CTRL_PEEK,(l),(s))
54966bae5e7Schristos
55066bae5e7Schristos/* For BIO_s_bio() */
55166bae5e7Schristos# define BIO_set_write_buf_size(b,size) (int)BIO_ctrl(b,BIO_C_SET_WRITE_BUF_SIZE,size,NULL)
55266bae5e7Schristos# define BIO_get_write_buf_size(b,size) (size_t)BIO_ctrl(b,BIO_C_GET_WRITE_BUF_SIZE,size,NULL)
55366bae5e7Schristos# define BIO_make_bio_pair(b1,b2)   (int)BIO_ctrl(b1,BIO_C_MAKE_BIO_PAIR,0,b2)
55466bae5e7Schristos# define BIO_destroy_bio_pair(b)    (int)BIO_ctrl(b,BIO_C_DESTROY_BIO_PAIR,0,NULL)
55566bae5e7Schristos# define BIO_shutdown_wr(b) (int)BIO_ctrl(b, BIO_C_SHUTDOWN_WR, 0, NULL)
55666bae5e7Schristos/* macros with inappropriate type -- but ...pending macros use int too: */
55766bae5e7Schristos# define BIO_get_write_guarantee(b) (int)BIO_ctrl(b,BIO_C_GET_WRITE_GUARANTEE,0,NULL)
55866bae5e7Schristos# define BIO_get_read_request(b)    (int)BIO_ctrl(b,BIO_C_GET_READ_REQUEST,0,NULL)
55966bae5e7Schristossize_t BIO_ctrl_get_write_guarantee(BIO *b);
56066bae5e7Schristossize_t BIO_ctrl_get_read_request(BIO *b);
56166bae5e7Schristosint BIO_ctrl_reset_read_request(BIO *b);
56266bae5e7Schristos
56366bae5e7Schristos/* ctrl macros for dgram */
56466bae5e7Schristos# define BIO_ctrl_dgram_connect(b,peer)  \
56566bae5e7Schristos                     (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)(peer))
56666bae5e7Schristos# define BIO_ctrl_set_connected(b,peer) \
56766bae5e7Schristos         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, 0, (char *)(peer))
56866bae5e7Schristos# define BIO_dgram_recv_timedout(b) \
56966bae5e7Schristos         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL)
57066bae5e7Schristos# define BIO_dgram_send_timedout(b) \
57166bae5e7Schristos         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL)
57266bae5e7Schristos# define BIO_dgram_get_peer(b,peer) \
57366bae5e7Schristos         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_PEER, 0, (char *)(peer))
57466bae5e7Schristos# define BIO_dgram_set_peer(b,peer) \
57566bae5e7Schristos         (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)(peer))
57666bae5e7Schristos# define BIO_dgram_get_mtu_overhead(b) \
57766bae5e7Schristos         (unsigned int)BIO_ctrl((b), BIO_CTRL_DGRAM_GET_MTU_OVERHEAD, 0, NULL)
57866bae5e7Schristos
57966bae5e7Schristos/* ctrl macros for BIO_f_prefix */
58066bae5e7Schristos# define BIO_set_prefix(b,p) BIO_ctrl((b), BIO_CTRL_SET_PREFIX, 0, (void *)(p))
58166bae5e7Schristos# define BIO_set_indent(b,i) BIO_ctrl((b), BIO_CTRL_SET_INDENT, (i), NULL)
58266bae5e7Schristos# define BIO_get_indent(b) BIO_ctrl((b), BIO_CTRL_GET_INDENT, 0, NULL)
58366bae5e7Schristos
58466bae5e7Schristos#define BIO_get_ex_new_index(l, p, newf, dupf, freef) \
58566bae5e7Schristos    CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, l, p, newf, dupf, freef)
58666bae5e7Schristosint BIO_set_ex_data(BIO *bio, int idx, void *data);
58766bae5e7Schristosvoid *BIO_get_ex_data(const BIO *bio, int idx);
58866bae5e7Schristosuint64_t BIO_number_read(BIO *bio);
58966bae5e7Schristosuint64_t BIO_number_written(BIO *bio);
59066bae5e7Schristos
59166bae5e7Schristos/* For BIO_f_asn1() */
59266bae5e7Schristosint BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
59366bae5e7Schristos                        asn1_ps_func *prefix_free);
59466bae5e7Schristosint BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
59566bae5e7Schristos                        asn1_ps_func **pprefix_free);
59666bae5e7Schristosint BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
59766bae5e7Schristos                        asn1_ps_func *suffix_free);
59866bae5e7Schristosint BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
59966bae5e7Schristos                        asn1_ps_func **psuffix_free);
60066bae5e7Schristos
60166bae5e7Schristosconst BIO_METHOD *BIO_s_file(void);
60266bae5e7SchristosBIO *BIO_new_file(const char *filename, const char *mode);
60366bae5e7SchristosBIO *BIO_new_from_core_bio(OSSL_LIB_CTX *libctx, OSSL_CORE_BIO *corebio);
60466bae5e7Schristos# ifndef OPENSSL_NO_STDIO
60566bae5e7SchristosBIO *BIO_new_fp(FILE *stream, int close_flag);
60666bae5e7Schristos# endif
60766bae5e7SchristosBIO *BIO_new_ex(OSSL_LIB_CTX *libctx, const BIO_METHOD *method);
60866bae5e7SchristosBIO *BIO_new(const BIO_METHOD *type);
60966bae5e7Schristosint BIO_free(BIO *a);
61066bae5e7Schristosvoid BIO_set_data(BIO *a, void *ptr);
61166bae5e7Schristosvoid *BIO_get_data(BIO *a);
61266bae5e7Schristosvoid BIO_set_init(BIO *a, int init);
61366bae5e7Schristosint BIO_get_init(BIO *a);
61466bae5e7Schristosvoid BIO_set_shutdown(BIO *a, int shut);
61566bae5e7Schristosint BIO_get_shutdown(BIO *a);
61666bae5e7Schristosvoid BIO_vfree(BIO *a);
61766bae5e7Schristosint BIO_up_ref(BIO *a);
61866bae5e7Schristosint BIO_read(BIO *b, void *data, int dlen);
61966bae5e7Schristosint BIO_read_ex(BIO *b, void *data, size_t dlen, size_t *readbytes);
62066bae5e7Schristosint BIO_gets(BIO *bp, char *buf, int size);
62166bae5e7Schristosint BIO_get_line(BIO *bio, char *buf, int size);
62266bae5e7Schristosint BIO_write(BIO *b, const void *data, int dlen);
62366bae5e7Schristosint BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written);
62466bae5e7Schristosint BIO_puts(BIO *bp, const char *buf);
62566bae5e7Schristosint BIO_indent(BIO *b, int indent, int max);
62666bae5e7Schristoslong BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
62766bae5e7Schristoslong BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp);
62866bae5e7Schristosvoid *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
62966bae5e7Schristoslong BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
63066bae5e7SchristosBIO *BIO_push(BIO *b, BIO *append);
63166bae5e7SchristosBIO *BIO_pop(BIO *b);
63266bae5e7Schristosvoid BIO_free_all(BIO *a);
63366bae5e7SchristosBIO *BIO_find_type(BIO *b, int bio_type);
63466bae5e7SchristosBIO *BIO_next(BIO *b);
63566bae5e7Schristosvoid BIO_set_next(BIO *b, BIO *next);
63666bae5e7SchristosBIO *BIO_get_retry_BIO(BIO *bio, int *reason);
63766bae5e7Schristosint BIO_get_retry_reason(BIO *bio);
63866bae5e7Schristosvoid BIO_set_retry_reason(BIO *bio, int reason);
63966bae5e7SchristosBIO *BIO_dup_chain(BIO *in);
64066bae5e7Schristos
64166bae5e7Schristosint BIO_nread0(BIO *bio, char **buf);
64266bae5e7Schristosint BIO_nread(BIO *bio, char **buf, int num);
64366bae5e7Schristosint BIO_nwrite0(BIO *bio, char **buf);
64466bae5e7Schristosint BIO_nwrite(BIO *bio, char **buf, int num);
64566bae5e7Schristos
64666bae5e7Schristosconst BIO_METHOD *BIO_s_mem(void);
64766bae5e7Schristosconst BIO_METHOD *BIO_s_secmem(void);
64866bae5e7SchristosBIO *BIO_new_mem_buf(const void *buf, int len);
64966bae5e7Schristos# ifndef OPENSSL_NO_SOCK
65066bae5e7Schristosconst BIO_METHOD *BIO_s_socket(void);
65166bae5e7Schristosconst BIO_METHOD *BIO_s_connect(void);
65266bae5e7Schristosconst BIO_METHOD *BIO_s_accept(void);
65366bae5e7Schristos# endif
65466bae5e7Schristosconst BIO_METHOD *BIO_s_fd(void);
65566bae5e7Schristosconst BIO_METHOD *BIO_s_log(void);
65666bae5e7Schristosconst BIO_METHOD *BIO_s_bio(void);
65766bae5e7Schristosconst BIO_METHOD *BIO_s_null(void);
65866bae5e7Schristosconst BIO_METHOD *BIO_f_null(void);
65966bae5e7Schristosconst BIO_METHOD *BIO_f_buffer(void);
66066bae5e7Schristosconst BIO_METHOD *BIO_f_readbuffer(void);
66166bae5e7Schristosconst BIO_METHOD *BIO_f_linebuffer(void);
66266bae5e7Schristosconst BIO_METHOD *BIO_f_nbio_test(void);
66366bae5e7Schristosconst BIO_METHOD *BIO_f_prefix(void);
66466bae5e7Schristosconst BIO_METHOD *BIO_s_core(void);
66566bae5e7Schristos# ifndef OPENSSL_NO_DGRAM
66666bae5e7Schristosconst BIO_METHOD *BIO_s_datagram(void);
66766bae5e7Schristosint BIO_dgram_non_fatal_error(int error);
66866bae5e7SchristosBIO *BIO_new_dgram(int fd, int close_flag);
66966bae5e7Schristos#  ifndef OPENSSL_NO_SCTP
67066bae5e7Schristosconst BIO_METHOD *BIO_s_datagram_sctp(void);
67166bae5e7SchristosBIO *BIO_new_dgram_sctp(int fd, int close_flag);
67266bae5e7Schristosint BIO_dgram_is_sctp(BIO *bio);
67366bae5e7Schristosint BIO_dgram_sctp_notification_cb(BIO *b,
67466bae5e7Schristos                BIO_dgram_sctp_notification_handler_fn handle_notifications,
67566bae5e7Schristos                void *context);
67666bae5e7Schristosint BIO_dgram_sctp_wait_for_dry(BIO *b);
67766bae5e7Schristosint BIO_dgram_sctp_msg_waiting(BIO *b);
67866bae5e7Schristos#  endif
67966bae5e7Schristos# endif
68066bae5e7Schristos
68166bae5e7Schristos# ifndef OPENSSL_NO_SOCK
68266bae5e7Schristosint BIO_sock_should_retry(int i);
68366bae5e7Schristosint BIO_sock_non_fatal_error(int error);
68466bae5e7Schristosint BIO_socket_wait(int fd, int for_read, time_t max_time);
68566bae5e7Schristos# endif
68666bae5e7Schristosint BIO_wait(BIO *bio, time_t max_time, unsigned int nap_milliseconds);
68766bae5e7Schristosint BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds);
68866bae5e7Schristos
68966bae5e7Schristosint BIO_fd_should_retry(int i);
69066bae5e7Schristosint BIO_fd_non_fatal_error(int error);
69166bae5e7Schristosint BIO_dump_cb(int (*cb) (const void *data, size_t len, void *u),
69266bae5e7Schristos                void *u, const void *s, int len);
69366bae5e7Schristosint BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),
69466bae5e7Schristos                       void *u, const void *s, int len, int indent);
69566bae5e7Schristosint BIO_dump(BIO *b, const void *bytes, int len);
69666bae5e7Schristosint BIO_dump_indent(BIO *b, const void *bytes, int len, int indent);
69766bae5e7Schristos# ifndef OPENSSL_NO_STDIO
69866bae5e7Schristosint BIO_dump_fp(FILE *fp, const void *s, int len);
69966bae5e7Schristosint BIO_dump_indent_fp(FILE *fp, const void *s, int len, int indent);
70066bae5e7Schristos# endif
70166bae5e7Schristosint BIO_hex_string(BIO *out, int indent, int width, const void *data,
70266bae5e7Schristos                   int datalen);
70366bae5e7Schristos
70466bae5e7Schristos# ifndef OPENSSL_NO_SOCK
70566bae5e7SchristosBIO_ADDR *BIO_ADDR_new(void);
70666bae5e7Schristosint BIO_ADDR_rawmake(BIO_ADDR *ap, int family,
70766bae5e7Schristos                     const void *where, size_t wherelen, unsigned short port);
70866bae5e7Schristosvoid BIO_ADDR_free(BIO_ADDR *);
70966bae5e7Schristosvoid BIO_ADDR_clear(BIO_ADDR *ap);
71066bae5e7Schristosint BIO_ADDR_family(const BIO_ADDR *ap);
71166bae5e7Schristosint BIO_ADDR_rawaddress(const BIO_ADDR *ap, void *p, size_t *l);
71266bae5e7Schristosunsigned short BIO_ADDR_rawport(const BIO_ADDR *ap);
71366bae5e7Schristoschar *BIO_ADDR_hostname_string(const BIO_ADDR *ap, int numeric);
71466bae5e7Schristoschar *BIO_ADDR_service_string(const BIO_ADDR *ap, int numeric);
71566bae5e7Schristoschar *BIO_ADDR_path_string(const BIO_ADDR *ap);
71666bae5e7Schristos
71766bae5e7Schristosconst BIO_ADDRINFO *BIO_ADDRINFO_next(const BIO_ADDRINFO *bai);
71866bae5e7Schristosint BIO_ADDRINFO_family(const BIO_ADDRINFO *bai);
71966bae5e7Schristosint BIO_ADDRINFO_socktype(const BIO_ADDRINFO *bai);
72066bae5e7Schristosint BIO_ADDRINFO_protocol(const BIO_ADDRINFO *bai);
72166bae5e7Schristosconst BIO_ADDR *BIO_ADDRINFO_address(const BIO_ADDRINFO *bai);
72266bae5e7Schristosvoid BIO_ADDRINFO_free(BIO_ADDRINFO *bai);
72366bae5e7Schristos
72466bae5e7Schristosenum BIO_hostserv_priorities {
72566bae5e7Schristos    BIO_PARSE_PRIO_HOST, BIO_PARSE_PRIO_SERV
72666bae5e7Schristos};
72766bae5e7Schristosint BIO_parse_hostserv(const char *hostserv, char **host, char **service,
72866bae5e7Schristos                       enum BIO_hostserv_priorities hostserv_prio);
72966bae5e7Schristosenum BIO_lookup_type {
73066bae5e7Schristos    BIO_LOOKUP_CLIENT, BIO_LOOKUP_SERVER
73166bae5e7Schristos};
73266bae5e7Schristosint BIO_lookup(const char *host, const char *service,
73366bae5e7Schristos               enum BIO_lookup_type lookup_type,
73466bae5e7Schristos               int family, int socktype, BIO_ADDRINFO **res);
73566bae5e7Schristosint BIO_lookup_ex(const char *host, const char *service,
73666bae5e7Schristos                  int lookup_type, int family, int socktype, int protocol,
73766bae5e7Schristos                  BIO_ADDRINFO **res);
73866bae5e7Schristosint BIO_sock_error(int sock);
73966bae5e7Schristosint BIO_socket_ioctl(int fd, long type, void *arg);
74066bae5e7Schristosint BIO_socket_nbio(int fd, int mode);
74166bae5e7Schristosint BIO_sock_init(void);
74266bae5e7Schristos# ifndef OPENSSL_NO_DEPRECATED_1_1_0
74366bae5e7Schristos#  define BIO_sock_cleanup() while(0) continue
74466bae5e7Schristos# endif
74566bae5e7Schristosint BIO_set_tcp_ndelay(int sock, int turn_on);
74666bae5e7Schristos# ifndef OPENSSL_NO_DEPRECATED_1_1_0
74766bae5e7SchristosOSSL_DEPRECATEDIN_1_1_0 struct hostent *BIO_gethostbyname(const char *name);
74866bae5e7SchristosOSSL_DEPRECATEDIN_1_1_0 int BIO_get_port(const char *str, unsigned short *port_ptr);
74966bae5e7SchristosOSSL_DEPRECATEDIN_1_1_0 int BIO_get_host_ip(const char *str, unsigned char *ip);
75066bae5e7SchristosOSSL_DEPRECATEDIN_1_1_0 int BIO_get_accept_socket(char *host_port, int mode);
75166bae5e7SchristosOSSL_DEPRECATEDIN_1_1_0 int BIO_accept(int sock, char **ip_port);
75266bae5e7Schristos# endif
75366bae5e7Schristos
75466bae5e7Schristosunion BIO_sock_info_u {
75566bae5e7Schristos    BIO_ADDR *addr;
75666bae5e7Schristos};
75766bae5e7Schristosenum BIO_sock_info_type {
75866bae5e7Schristos    BIO_SOCK_INFO_ADDRESS
75966bae5e7Schristos};
76066bae5e7Schristosint BIO_sock_info(int sock,
76166bae5e7Schristos                  enum BIO_sock_info_type type, union BIO_sock_info_u *info);
76266bae5e7Schristos
76366bae5e7Schristos#  define BIO_SOCK_REUSEADDR    0x01
76466bae5e7Schristos#  define BIO_SOCK_V6_ONLY      0x02
76566bae5e7Schristos#  define BIO_SOCK_KEEPALIVE    0x04
76666bae5e7Schristos#  define BIO_SOCK_NONBLOCK     0x08
76766bae5e7Schristos#  define BIO_SOCK_NODELAY      0x10
76866bae5e7Schristos
76966bae5e7Schristosint BIO_socket(int domain, int socktype, int protocol, int options);
77066bae5e7Schristosint BIO_connect(int sock, const BIO_ADDR *addr, int options);
77166bae5e7Schristosint BIO_bind(int sock, const BIO_ADDR *addr, int options);
77266bae5e7Schristosint BIO_listen(int sock, const BIO_ADDR *addr, int options);
77366bae5e7Schristosint BIO_accept_ex(int accept_sock, BIO_ADDR *addr, int options);
77466bae5e7Schristosint BIO_closesocket(int sock);
77566bae5e7Schristos
77666bae5e7SchristosBIO *BIO_new_socket(int sock, int close_flag);
77766bae5e7SchristosBIO *BIO_new_connect(const char *host_port);
77866bae5e7SchristosBIO *BIO_new_accept(const char *host_port);
77966bae5e7Schristos# endif /* OPENSSL_NO_SOCK*/
78066bae5e7Schristos
78166bae5e7SchristosBIO *BIO_new_fd(int fd, int close_flag);
78266bae5e7Schristos
78366bae5e7Schristosint BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
78466bae5e7Schristos                     BIO **bio2, size_t writebuf2);
78566bae5e7Schristos/*
78666bae5e7Schristos * If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
78766bae5e7Schristos * Otherwise returns 0 and sets *bio1 and *bio2 to NULL. Size 0 uses default
78866bae5e7Schristos * value.
78966bae5e7Schristos */
79066bae5e7Schristos
79166bae5e7Schristosvoid BIO_copy_next_retry(BIO *b);
79266bae5e7Schristos
79366bae5e7Schristos/*
79466bae5e7Schristos * long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);
79566bae5e7Schristos */
79666bae5e7Schristos
79766bae5e7Schristos# define ossl_bio__attr__(x)
79866bae5e7Schristos# if defined(__GNUC__) && defined(__STDC_VERSION__) \
79966bae5e7Schristos    && !defined(__MINGW32__) && !defined(__MINGW64__) \
80066bae5e7Schristos    && !defined(__APPLE__)
80166bae5e7Schristos    /*
80266bae5e7Schristos     * Because we support the 'z' modifier, which made its appearance in C99,
80366bae5e7Schristos     * we can't use __attribute__ with pre C99 dialects.
80466bae5e7Schristos     */
80566bae5e7Schristos#  if __STDC_VERSION__ >= 199901L
80666bae5e7Schristos#   undef ossl_bio__attr__
80766bae5e7Schristos#   define ossl_bio__attr__ __attribute__
80866bae5e7Schristos#   if __GNUC__*10 + __GNUC_MINOR__ >= 44
80966bae5e7Schristos#    define ossl_bio__printf__ __gnu_printf__
81066bae5e7Schristos#   else
81166bae5e7Schristos#    define ossl_bio__printf__ __printf__
81266bae5e7Schristos#   endif
81366bae5e7Schristos#  endif
81466bae5e7Schristos# endif
81566bae5e7Schristosint BIO_printf(BIO *bio, const char *format, ...)
81666bae5e7Schristosossl_bio__attr__((__format__(ossl_bio__printf__, 2, 3)));
81766bae5e7Schristosint BIO_vprintf(BIO *bio, const char *format, va_list args)
81866bae5e7Schristosossl_bio__attr__((__format__(ossl_bio__printf__, 2, 0)));
81966bae5e7Schristosint BIO_snprintf(char *buf, size_t n, const char *format, ...)
82066bae5e7Schristosossl_bio__attr__((__format__(ossl_bio__printf__, 3, 4)));
82166bae5e7Schristosint BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
82266bae5e7Schristosossl_bio__attr__((__format__(ossl_bio__printf__, 3, 0)));
82366bae5e7Schristos# undef ossl_bio__attr__
82466bae5e7Schristos# undef ossl_bio__printf__
82566bae5e7Schristos
82666bae5e7Schristos
82766bae5e7SchristosBIO_METHOD *BIO_meth_new(int type, const char *name);
82866bae5e7Schristosvoid BIO_meth_free(BIO_METHOD *biom);
82966bae5e7Schristosint (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, int);
83066bae5e7Schristosint (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, size_t,
83166bae5e7Schristos                                                size_t *);
83266bae5e7Schristosint BIO_meth_set_write(BIO_METHOD *biom,
83366bae5e7Schristos                       int (*write) (BIO *, const char *, int));
83466bae5e7Schristosint BIO_meth_set_write_ex(BIO_METHOD *biom,
83566bae5e7Schristos                       int (*bwrite) (BIO *, const char *, size_t, size_t *));
83666bae5e7Schristosint (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int);
83766bae5e7Schristosint (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *);
83866bae5e7Schristosint BIO_meth_set_read(BIO_METHOD *biom,
83966bae5e7Schristos                      int (*read) (BIO *, char *, int));
84066bae5e7Schristosint BIO_meth_set_read_ex(BIO_METHOD *biom,
84166bae5e7Schristos                         int (*bread) (BIO *, char *, size_t, size_t *));
84266bae5e7Schristosint (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *);
84366bae5e7Schristosint BIO_meth_set_puts(BIO_METHOD *biom,
84466bae5e7Schristos                      int (*puts) (BIO *, const char *));
84566bae5e7Schristosint (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int);
84666bae5e7Schristosint BIO_meth_set_gets(BIO_METHOD *biom,
84766bae5e7Schristos                      int (*gets) (BIO *, char *, int));
84866bae5e7Schristoslong (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, long, void *);
84966bae5e7Schristosint BIO_meth_set_ctrl(BIO_METHOD *biom,
85066bae5e7Schristos                      long (*ctrl) (BIO *, int, long, void *));
85166bae5e7Schristosint (*BIO_meth_get_create(const BIO_METHOD *bion)) (BIO *);
85266bae5e7Schristosint BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *));
85366bae5e7Schristosint (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *);
85466bae5e7Schristosint BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *));
85566bae5e7Schristoslong (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))
85666bae5e7Schristos                                 (BIO *, int, BIO_info_cb *);
85766bae5e7Schristosint BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
85866bae5e7Schristos                               long (*callback_ctrl) (BIO *, int,
85966bae5e7Schristos                                                      BIO_info_cb *));
86066bae5e7Schristos
86166bae5e7Schristos# ifdef  __cplusplus
86266bae5e7Schristos}
86366bae5e7Schristos# endif
86466bae5e7Schristos#endif
865