Skip to main content

variant_ssl_sys/
bio.rs

1use libc::*;
2
3use super::*;
4
5pub const BIO_TYPE_NONE: c_int = 0;
6
7pub const BIO_CTRL_EOF: c_int = 2;
8pub const BIO_CTRL_INFO: c_int = 3;
9pub const BIO_CTRL_FLUSH: c_int = 11;
10pub const BIO_CTRL_DGRAM_QUERY_MTU: c_int = 40;
11pub const BIO_C_SET_BUF_MEM_EOF_RETURN: c_int = 130;
12
13pub unsafe fn BIO_set_retry_read(b: *mut BIO) {
14    BIO_set_flags(b, BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY)
15}
16
17pub unsafe fn BIO_set_retry_write(b: *mut BIO) {
18    BIO_set_flags(b, BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY)
19}
20
21pub unsafe fn BIO_clear_retry_flags(b: *mut BIO) {
22    BIO_clear_flags(b, BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY)
23}
24
25pub const BIO_FLAGS_READ: c_int = 0x01;
26pub const BIO_FLAGS_WRITE: c_int = 0x02;
27pub const BIO_FLAGS_IO_SPECIAL: c_int = 0x04;
28pub const BIO_FLAGS_RWS: c_int = BIO_FLAGS_READ | BIO_FLAGS_WRITE | BIO_FLAGS_IO_SPECIAL;
29pub const BIO_FLAGS_SHOULD_RETRY: c_int = 0x08;
30
31pub unsafe fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long {
32    BIO_ctrl(b, BIO_CTRL_INFO, 0, pp as *mut c_void)
33}
34
35cfg_if! {
36    if #[cfg(ossl320)] {
37        use std::ptr;
38
39        pub const BIO_CTRL_DGRAM_GET_MTU: c_int = 41;
40        pub const BIO_CTRL_DGRAM_SET_MTU: c_int = 42;
41        pub const BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP: c_int = 82;
42        pub const BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE: c_int = 83;
43        pub const BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE: c_int = 84;
44        pub const BIO_CTRL_DGRAM_GET_CAPS: c_int = 86;
45        pub const BIO_CTRL_DGRAM_SET_CAPS: c_int = 87;
46        pub const BIO_CTRL_DGRAM_GET_NO_TRUNC: c_int = 88;
47        pub const BIO_CTRL_DGRAM_SET_NO_TRUNC: c_int = 89;
48
49        pub unsafe fn BIO_dgram_get_no_trunc(bio: *mut BIO) -> c_int {
50            BIO_ctrl(bio, BIO_CTRL_DGRAM_GET_NO_TRUNC, 0, ptr::null_mut()) as c_int
51        }
52        pub unsafe fn BIO_dgram_set_no_trunc(bio: *mut BIO, enable: c_int) -> c_int {
53            BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_NO_TRUNC, enable as c_long, ptr::null_mut()) as c_int
54        }
55        pub unsafe fn BIO_dgram_get_cap(bio: *mut BIO) -> u32 {
56            BIO_ctrl(bio, BIO_CTRL_DGRAM_GET_CAPS, 0, ptr::null_mut()) as u32
57        }
58        pub unsafe fn BIO_dgram_set_cap(bio: *mut BIO, cap: u32) -> c_int {
59            BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CAPS, cap as c_long, ptr::null_mut()) as c_int
60        }
61        pub unsafe fn BIO_dgram_get_local_addr_cap(bio: *mut BIO) -> c_int {
62            BIO_ctrl(bio, BIO_CTRL_DGRAM_GET_LOCAL_ADDR_CAP, 0, ptr::null_mut()) as c_int
63        }
64        pub unsafe fn BIO_dgram_get_local_addr_enable(bio: *mut BIO, enable: *mut c_int) -> c_int {
65            BIO_ctrl(bio, BIO_CTRL_DGRAM_GET_LOCAL_ADDR_ENABLE, 0, enable as *mut c_void) as c_int
66        }
67        pub unsafe fn BIO_dgram_set_local_addr_enable(bio: *mut BIO, enable: c_int) -> c_int {
68            BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_LOCAL_ADDR_ENABLE, enable as c_long, ptr::null_mut()) as c_int
69        }
70        pub unsafe fn BIO_dgram_get_mtu(bio: *mut BIO) -> c_uint {
71            BIO_ctrl(bio, BIO_CTRL_DGRAM_GET_MTU, 0, ptr::null_mut()) as c_uint
72        }
73        pub unsafe fn BIO_dgram_set_mtu(bio: *mut BIO, mtu: c_uint) -> c_int {
74            BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_MTU, mtu as c_long, ptr::null_mut()) as c_int
75        }
76    }
77}