diff --git a/.travis.yml b/.travis.yml index 9864ce9ab..6616d4f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,7 @@ matrix: - os: osx rust: stable + osx_image: xcode10.2 addons: apt: @@ -63,7 +64,7 @@ addons: before_script: - scripts/reset-submodule.cmd - - export GRPC_VERSION=1.17.2 + - export GRPC_VERSION=1.26.0 - export PATH="$PATH:$HOME/.cache/bin:$HOME/.cargo/bin" - GRPC_HEADER="$HOME/.cache/include/grpc/grpc.h" - if [[ $TRAVIS_OS_NAME == "osx" ]] && [[ ! -f $GRPC_HEADER ]]; then @@ -84,6 +85,7 @@ before_script: env prefix=$HOME/.cache make install_c ); fi + - eval "$(gimme stable)" - export CPLUS_INCLUDE_PATH="$HOME/.cache/include" - export LD_LIBRARY_PATH="$HOME/.cache/lib" - export DYLD_LIBRARY_PATH="$HOME/.cache/lib" @@ -91,6 +93,7 @@ before_script: - export PKG_CONFIG_PATH="$HOME/.cache/lib/pkgconfig" script: + - which go && go version - if [[ $TRAVIS_OS_NAME == "linux" ]] && [[ $TRAVIS_RUST_VERSION == "stable" ]]; then rustup component add rustfmt && cargo fmt --all -- --check; scripts/generate-bindings.sh && git diff --exit-code HEAD; diff --git a/grpc-sys/bindings/x86_64-unknown-linux-gnu-bindings.rs b/grpc-sys/bindings/x86_64-unknown-linux-gnu-bindings.rs index 4987ef506..9a248bfeb 100644 --- a/grpc-sys/bindings/x86_64-unknown-linux-gnu-bindings.rs +++ b/grpc-sys/bindings/x86_64-unknown-linux-gnu-bindings.rs @@ -1,6 +1,8 @@ /* automatically generated by rust-bindgen */ +pub const GRPC_USE_ABSL: u32 = 0; pub const GRPC_ARES: u32 = 1; +pub const GRPC_IF_NAMETOINDEX: u32 = 1; pub const GRPC_ALLOW_EXCEPTIONS: u32 = 1; pub const GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY: &'static [u8; 31usize] = b"grpc-internal-encoding-request\0"; @@ -28,6 +30,8 @@ pub const GRPC_ARG_MAX_CONNECTION_IDLE_MS: &'static [u8; 28usize] = pub const GRPC_ARG_MAX_CONNECTION_AGE_MS: &'static [u8; 27usize] = b"grpc.max_connection_age_ms\0"; pub const GRPC_ARG_MAX_CONNECTION_AGE_GRACE_MS: &'static [u8; 33usize] = b"grpc.max_connection_age_grace_ms\0"; +pub const GRPC_ARG_CLIENT_IDLE_TIMEOUT_MS: &'static [u8; 28usize] = + b"grpc.client_idle_timeout_ms\0"; pub const GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION: &'static [u8; 29usize] = b"grpc.per_message_compression\0"; pub const GRPC_ARG_ENABLE_DEADLINE_CHECKS: &'static [u8; 30usize] = @@ -75,6 +79,7 @@ pub const GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS: &'static [u8; 33usize] = pub const GRPC_SSL_TARGET_NAME_OVERRIDE_ARG: &'static [u8; 30usize] = b"grpc.ssl_target_name_override\0"; pub const GRPC_SSL_SESSION_CACHE_ARG: &'static [u8; 23usize] = b"grpc.ssl_session_cache\0"; +pub const GRPC_ARG_TSI_MAX_FRAME_SIZE: &'static [u8; 24usize] = b"grpc.tsi.max_frame_size\0"; pub const GRPC_ARG_MAX_METADATA_SIZE: &'static [u8; 23usize] = b"grpc.max_metadata_size\0"; pub const GRPC_ARG_ALLOW_REUSEPORT: &'static [u8; 18usize] = b"grpc.so_reuseport\0"; pub const GRPC_ARG_RESOURCE_QUOTA: &'static [u8; 20usize] = b"grpc.resource_quota\0"; @@ -101,6 +106,12 @@ pub const GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS: &'static [u8; 28usize] = b"grpc.grpclb_call_timeout_ms\0"; pub const GRPC_ARG_GRPCLB_FALLBACK_TIMEOUT_MS: &'static [u8; 32usize] = b"grpc.grpclb_fallback_timeout_ms\0"; +pub const GRPC_ARG_XDS_FALLBACK_TIMEOUT_MS: &'static [u8; 29usize] = + b"grpc.xds_fallback_timeout_ms\0"; +pub const GRPC_ARG_LOCALITY_RETENTION_INTERVAL_MS: &'static [u8; 40usize] = + b"grpc.xds_locality_retention_interval_ms\0"; +pub const GRPC_ARG_XDS_FAILOVER_TIMEOUT_MS: &'static [u8; 29usize] = + b"grpc.xds_failover_timeout_ms\0"; pub const GRPC_ARG_WORKAROUND_CRONET_COMPRESSION: &'static [u8; 35usize] = b"grpc.workaround.cronet_compression\0"; pub const GRPC_ARG_OPTIMIZATION_TARGET: &'static [u8; 25usize] = b"grpc.optimization_target\0"; @@ -114,8 +125,14 @@ pub const GRPC_ARG_ENABLE_HTTP_PROXY: &'static [u8; 23usize] = b"grpc.enable_htt pub const GRPC_ARG_SURFACE_USER_AGENT: &'static [u8; 24usize] = b"grpc.surface_user_agent\0"; pub const GRPC_ARG_INHIBIT_HEALTH_CHECKING: &'static [u8; 29usize] = b"grpc.inhibit_health_checking\0"; +pub const GRPC_ARG_DNS_ENABLE_SRV_QUERIES: &'static [u8; 28usize] = + b"grpc.dns_enable_srv_queries\0"; pub const GRPC_ARG_DNS_ARES_QUERY_TIMEOUT_MS: &'static [u8; 28usize] = b"grpc.dns_ares_query_timeout\0"; +pub const GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL: &'static [u8; 31usize] = + b"grpc.use_local_subchannel_pool\0"; +pub const GRPC_ARG_CHANNEL_POOL_DOMAIN: &'static [u8; 28usize] = b"grpc.channel_pooling_domain\0"; +pub const GRPC_ARG_CHANNEL_ID: &'static [u8; 16usize] = b"grpc.channel_id\0"; pub const GRPC_DEFAULT_MAX_SEND_MESSAGE_LENGTH: i32 = -1; pub const GRPC_DEFAULT_MAX_RECV_MESSAGE_LENGTH: u32 = 4194304; pub const GRPC_WRITE_BUFFER_HINT: u32 = 1; @@ -144,7 +161,8 @@ pub const GRPC_GOOGLE_CREDENTIALS_ENV_VAR: &'static [u8; 31usize] = b"GOOGLE_APPLICATION_CREDENTIALS\0"; pub const GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX: u32 = 4; #[repr(u32)] -#[doc = " The various compression algorithms supported by gRPC"] +#[doc = " The various compression algorithms supported by gRPC (not sorted by"] +#[doc = " compression level)"] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum grpc_compression_algorithm { GRPC_COMPRESS_NONE = 0, @@ -344,132 +362,10 @@ fn bindgen_test_layout_grpc_compression_options() { ) ); } -#[doc = " Slice API"] -#[doc = ""] -#[doc = "A slice represents a contiguous reference counted array of bytes."] -#[doc = "It is cheap to take references to a slice, and it is cheap to create a"] -#[doc = "slice pointing to a subset of another slice."] -#[doc = ""] -#[doc = "The data-structure for slices is exposed here to allow non-gpr code to"] -#[doc = "build slices from whatever data they have available."] -#[doc = ""] -#[doc = "When defining interfaces that handle slices, care should be taken to define"] -#[doc = "reference ownership semantics (who should call unref?) and mutability"] -#[doc = "constraints (is the callee allowed to modify the slice?)"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct grpc_slice_refcount_vtable { - pub ref_: ::std::option::Option, - pub unref: ::std::option::Option, - pub eq: ::std::option::Option< - unsafe extern "C" fn(a: grpc_slice, b: grpc_slice) -> ::std::os::raw::c_int, - >, - pub hash: ::std::option::Option u32>, -} -#[test] -fn bindgen_test_layout_grpc_slice_refcount_vtable() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(grpc_slice_refcount_vtable)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(grpc_slice_refcount_vtable)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).ref_ as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount_vtable), - "::", - stringify!(ref_) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).unref as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount_vtable), - "::", - stringify!(unref) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).eq as *const _ as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount_vtable), - "::", - stringify!(eq) - ) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).hash as *const _ as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount_vtable), - "::", - stringify!(hash) - ) - ); -} -#[doc = " Reference count container for grpc_slice. Contains function pointers to"] -#[doc = "increment and decrement reference counts. Implementations should cleanup"] -#[doc = "when the reference count drops to zero."] -#[doc = "Typically client code should not touch this, and use grpc_slice_malloc,"] -#[doc = "grpc_slice_new, or grpc_slice_new_with_len instead."] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct grpc_slice_refcount { - pub vtable: *const grpc_slice_refcount_vtable, - #[doc = " If a subset of this slice is taken, use this pointer for the refcount."] - #[doc = "Typically points back to the refcount itself, however iterning"] - #[doc = "implementations can use this to avoid a verification step on each hash"] - #[doc = "or equality check"] - pub sub_refcount: *mut grpc_slice_refcount, -} -#[test] -fn bindgen_test_layout_grpc_slice_refcount() { - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(grpc_slice_refcount)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(grpc_slice_refcount)) - ); - assert_eq!( - unsafe { &(*(::std::ptr::null::())).vtable as *const _ as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount), - "::", - stringify!(vtable) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).sub_refcount as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(grpc_slice_refcount), - "::", - stringify!(sub_refcount) - ) - ); + _unused: [u8; 0], } #[doc = " A grpc_slice s, if initialized, represents the byte range"] #[doc = "s.bytes[0..s.length-1]."] @@ -496,8 +392,8 @@ pub union grpc_slice_grpc_slice_data { #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct grpc_slice_grpc_slice_data_grpc_slice_refcounted { - pub bytes: *mut u8, pub length: usize, + pub bytes: *mut u8, } #[test] fn bindgen_test_layout_grpc_slice_grpc_slice_data_grpc_slice_refcounted() { @@ -519,7 +415,7 @@ fn bindgen_test_layout_grpc_slice_grpc_slice_data_grpc_slice_refcounted() { ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).bytes + &(*(::std::ptr::null::())).length as *const _ as usize }, 0usize, @@ -527,12 +423,12 @@ fn bindgen_test_layout_grpc_slice_grpc_slice_data_grpc_slice_refcounted() { "Offset of field: ", stringify!(grpc_slice_grpc_slice_data_grpc_slice_refcounted), "::", - stringify!(bytes) + stringify!(length) ) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).length + &(*(::std::ptr::null::())).bytes as *const _ as usize }, 8usize, @@ -540,7 +436,7 @@ fn bindgen_test_layout_grpc_slice_grpc_slice_data_grpc_slice_refcounted() { "Offset of field: ", stringify!(grpc_slice_grpc_slice_data_grpc_slice_refcounted), "::", - stringify!(length) + stringify!(bytes) ) ); } @@ -801,7 +697,7 @@ pub struct gpr_timespec { pub tv_sec: i64, pub tv_nsec: i32, #[doc = " Against which clock was this time measured? (or GPR_TIMESPAN if"] - #[doc = "this is a relative time meaure)"] + #[doc = "this is a relative time measure)"] pub clock_type: gpr_clock_type, } #[test] @@ -1122,7 +1018,7 @@ extern "C" { extern "C" { #[doc = " Splits s into two: modifies s to be s[0:split], and returns a new slice,"] #[doc = "sharing a refcount with s, that contains s[split:s.length]."] - #[doc = "Requires s intialized, split <= s.length"] + #[doc = "Requires s initialized, split <= s.length"] pub fn grpc_slice_split_tail(s: *mut grpc_slice, split: usize) -> grpc_slice; } #[repr(u32)] @@ -1145,7 +1041,7 @@ extern "C" { extern "C" { #[doc = " Splits s into two: modifies s to be s[split:s.length], and returns a new"] #[doc = "slice, sharing a refcount with s, that contains s[0:split]."] - #[doc = "Requires s intialized, split <= s.length"] + #[doc = "Requires s initialized, split <= s.length"] pub fn grpc_slice_split_head(s: *mut grpc_slice, split: usize) -> grpc_slice; } extern "C" { @@ -1188,7 +1084,7 @@ extern "C" { pub fn grpc_slice_chr(s: grpc_slice, c: ::std::os::raw::c_char) -> ::std::os::raw::c_int; } extern "C" { - #[doc = " return the index of the first occurance of \\a needle in \\a haystack, or -1"] + #[doc = " return the index of the first occurrence of \\a needle in \\a haystack, or -1"] #[doc = "if it's not found"] pub fn grpc_slice_slice(haystack: grpc_slice, needle: grpc_slice) -> ::std::os::raw::c_int; } @@ -1362,7 +1258,8 @@ pub mod grpc_status_code { pub const GRPC_STATUS_INTERNAL: Type = 13; #[doc = " The service is currently unavailable. This is a most likely a"] #[doc = "transient condition and may be corrected by retrying with"] - #[doc = "a backoff."] + #[doc = "a backoff. Note that it is not always safe to retry non-idempotent"] + #[doc = "operations."] #[doc = ""] #[doc = "WARNING: Although data MIGHT not have been transmitted when this"] #[doc = "status occurs, there is NOT A GUARANTEE that the server has not seen"] @@ -2100,7 +1997,8 @@ pub struct grpc_event { #[doc = "field is guaranteed to be 0"] pub success: ::std::os::raw::c_int, #[doc = " The tag passed to grpc_call_start_batch etc to start this operation."] - #[doc = "Only GRPC_OP_COMPLETE has a tag."] + #[doc = "Only* GRPC_OP_COMPLETE has a tag. For all other grpc_completion_type"] + #[doc = "values, tag is uninitialized."] pub tag: *mut ::std::os::raw::c_void, } #[test] @@ -3073,12 +2971,18 @@ pub struct grpc_experimental_completion_queue_functor { arg2: ::std::os::raw::c_int, ), >, + #[doc = " The inlineable member specifies whether this functor can be run inline."] + #[doc = "This should only be used for trivial internally-defined functors."] + pub inlineable: ::std::os::raw::c_int, + #[doc = " The following fields are not API. They are meant for internal use."] + pub internal_success: ::std::os::raw::c_int, + pub internal_next: *mut grpc_experimental_completion_queue_functor, } #[test] fn bindgen_test_layout_grpc_experimental_completion_queue_functor() { assert_eq!( ::std::mem::size_of::(), - 8usize, + 24usize, concat!( "Size of: ", stringify!(grpc_experimental_completion_queue_functor) @@ -3105,6 +3009,45 @@ fn bindgen_test_layout_grpc_experimental_completion_queue_functor() { stringify!(functor_run) ) ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).inlineable + as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(grpc_experimental_completion_queue_functor), + "::", + stringify!(inlineable) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).internal_success + as *const _ as usize + }, + 12usize, + concat!( + "Offset of field: ", + stringify!(grpc_experimental_completion_queue_functor), + "::", + stringify!(internal_success) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).internal_next + as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(grpc_experimental_completion_queue_functor), + "::", + stringify!(internal_next) + ) + ); } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -3251,6 +3194,22 @@ extern "C" { slice: *mut grpc_slice, ) -> ::std::os::raw::c_int; } +extern "C" { + #[doc = " EXPERIMENTAL API - This function may be removed and changed, in the future."] + #[doc = ""] + #[doc = " Updates \\a slice with the next piece of data from from \\a reader and returns"] + #[doc = " 1. Returns 0 at the end of the stream. Caller is responsible for making sure"] + #[doc = " the slice pointer remains valid when accessed."] + #[doc = ""] + #[doc = " NOTE: Do not use this function unless the caller can guarantee that the"] + #[doc = " underlying grpc_byte_buffer outlasts the use of the slice. This is only"] + #[doc = " safe when the underlying grpc_byte_buffer remains immutable while slice"] + #[doc = " is being accessed."] + pub fn grpc_byte_buffer_reader_peek( + reader: *mut grpc_byte_buffer_reader, + slice: *mut *mut grpc_slice, + ) -> ::std::os::raw::c_int; +} extern "C" { #[doc = " Merge all data from \\a reader into single slice"] pub fn grpc_byte_buffer_reader_readall(reader: *mut grpc_byte_buffer_reader) -> grpc_slice; @@ -3493,10 +3452,11 @@ extern "C" { #[doc = "Before it's called, there should haven been a matching invocation to"] #[doc = "grpc_init()."] #[doc = ""] - #[doc = "No memory is used by grpc after this call returns, nor are any instructions"] - #[doc = "executing within the grpc library."] - #[doc = "Prior to calling, all application owned grpc objects must have been"] - #[doc = "destroyed."] + #[doc = "The last call to grpc_shutdown will initiate cleaning up of grpc library"] + #[doc = "internals, which can happen in another thread. Once the clean-up is done,"] + #[doc = "no memory is used by grpc, nor are any instructions executing within the"] + #[doc = "grpc library. Prior to calling, all application owned grpc objects must"] + #[doc = "have been destroyed."] pub fn grpc_shutdown(); } extern "C" { @@ -3506,6 +3466,11 @@ extern "C" { #[doc = "https://github.com/grpc/grpc/issues/15334"] pub fn grpc_is_initialized() -> ::std::os::raw::c_int; } +extern "C" { + #[doc = " EXPERIMENTAL. Blocking shut down grpc library."] + #[doc = "This is only for wrapped language to use now."] + pub fn grpc_shutdown_blocking(); +} extern "C" { #[doc = " Return a string representing the current version of grpc"] pub fn grpc_version_string() -> *const ::std::os::raw::c_char; @@ -3684,6 +3649,8 @@ extern "C" { } extern "C" { #[doc = " Pre-register a method/host pair on a channel."] + #[doc = "method and host are not owned and must remain alive while the server is"] + #[doc = "running."] pub fn grpc_channel_register_call( channel: *mut grpc_channel, method: *const ::std::os::raw::c_char, @@ -3811,7 +3778,7 @@ extern "C" { pub fn grpc_channel_destroy(channel: *mut grpc_channel); } extern "C" { - #[doc = " Called by clients to cancel an RPC on the server."] + #[doc = " Cancel an RPC."] #[doc = "Can be called multiple times, from any thread."] #[doc = "THREAD-SAFETY grpc_call_cancel and grpc_call_cancel_with_status"] #[doc = "are thread-safe, and can be called at any point before grpc_call_unref"] @@ -3822,7 +3789,7 @@ extern "C" { ) -> grpc_call_error; } extern "C" { - #[doc = " Called by clients to cancel an RPC on the server."] + #[doc = " Cancel an RPC."] #[doc = "Can be called multiple times, from any thread."] #[doc = "If a status has not been received for the call, set it to the status code"] #[doc = "and description passed in."] @@ -4056,6 +4023,7 @@ extern "C" { pub fn grpc_channelz_get_server_sockets( server_id: isize, start_socket_id: isize, + max_results: isize, ) -> *mut ::std::os::raw::c_char; } extern "C" { @@ -4158,7 +4126,7 @@ pub enum grpc_ssl_client_certificate_request_type { #[doc = " Server requests client certificate and enforces that the client presents a"] #[doc = "certificate."] #[doc = ""] - #[doc = "The cerificate presented by the client is verified by the gRPC framework."] + #[doc = "The certificate presented by the client is verified by the gRPC framework."] #[doc = "(For a successful connection the client needs to present a certificate that"] #[doc = "can be verified against the root certificate configured by the server)"] #[doc = ""] @@ -4167,11 +4135,12 @@ pub enum grpc_ssl_client_certificate_request_type { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY = 4, } #[repr(u32)] -#[doc = " Type of local connection for which local channel/server credentials will be"] -#[doc = " applied. It only supports UDS for now."] +#[doc = " Type of local connections for which local channel/server credentials will be"] +#[doc = " applied. It supports UDS and local TCP connections."] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum grpc_local_connect_type { UDS = 0, + LOCAL_TCP = 1, } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -4460,7 +4429,9 @@ fn bindgen_test_layout_grpc_ssl_pem_key_cert_pair() { ) ); } -#[doc = " Object that holds additional peer-verification options on a secure"] +#[doc = " Deprecated in favor of grpc_ssl_verify_peer_options. It will be removed"] +#[doc = "after all of its call sites are migrated to grpc_ssl_verify_peer_options."] +#[doc = "Object that holds additional peer-verification options on a secure"] #[doc = "channel."] #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -4538,8 +4509,88 @@ fn bindgen_test_layout_verify_peer_options() { ) ); } +#[doc = " Object that holds additional peer-verification options on a secure"] +#[doc = "channel."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_ssl_verify_peer_options { + #[doc = " If non-NULL this callback will be invoked with the expected"] + #[doc = "target_name, the peer's certificate (in PEM format), and whatever"] + #[doc = "userdata pointer is set below. If a non-zero value is returned by this"] + #[doc = "callback then it is treated as a verification failure. Invocation of"] + #[doc = "the callback is blocking, so any implementation should be light-weight."] + pub verify_peer_callback: ::std::option::Option< + unsafe extern "C" fn( + target_name: *const ::std::os::raw::c_char, + peer_pem: *const ::std::os::raw::c_char, + userdata: *mut ::std::os::raw::c_void, + ) -> ::std::os::raw::c_int, + >, + #[doc = " Arbitrary userdata that will be passed as the last argument to"] + #[doc = "verify_peer_callback."] + pub verify_peer_callback_userdata: *mut ::std::os::raw::c_void, + #[doc = " A destruct callback that will be invoked when the channel is being"] + #[doc = "cleaned up. The userdata argument will be passed to it. The intent is"] + #[doc = "to perform any cleanup associated with that userdata."] + pub verify_peer_destruct: + ::std::option::Option, +} +#[test] +fn bindgen_test_layout_grpc_ssl_verify_peer_options() { + assert_eq!( + ::std::mem::size_of::(), + 24usize, + concat!("Size of: ", stringify!(grpc_ssl_verify_peer_options)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(grpc_ssl_verify_peer_options)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).verify_peer_callback + as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(grpc_ssl_verify_peer_options), + "::", + stringify!(verify_peer_callback) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).verify_peer_callback_userdata + as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(grpc_ssl_verify_peer_options), + "::", + stringify!(verify_peer_callback_userdata) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).verify_peer_destruct + as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(grpc_ssl_verify_peer_options), + "::", + stringify!(verify_peer_destruct) + ) + ); +} extern "C" { - #[doc = " Creates an SSL credentials object."] + #[doc = " Deprecated in favor of grpc_ssl_server_credentials_create_ex. It will be"] + #[doc = "removed after all of its call sites are migrated to"] + #[doc = "grpc_ssl_server_credentials_create_ex. Creates an SSL credentials object."] #[doc = "- pem_root_certs is the NULL-terminated string containing the PEM encoding"] #[doc = "of the server root certificates. If this parameter is NULL, the"] #[doc = "implementation will first try to dereference the file pointed by the"] @@ -4547,6 +4598,15 @@ extern "C" { #[doc = "try to get the roots set by grpc_override_ssl_default_roots. Eventually,"] #[doc = "if all these fail, it will try to get the roots from a well-known place on"] #[doc = "disk (in the grpc install directory)."] + #[doc = ""] + #[doc = "gRPC has implemented root cache if the underlying OpenSSL library supports"] + #[doc = "it. The gRPC root certificates cache is only applicable on the default"] + #[doc = "root certificates, which is used when this parameter is nullptr. If user"] + #[doc = "provides their own pem_root_certs, when creating an SSL credential object,"] + #[doc = "gRPC would not be able to cache it, and each subchannel will generate a"] + #[doc = "copy of the root store. So it is recommended to avoid providing large room"] + #[doc = "pem with pem_root_certs parameter to avoid excessive memory consumption,"] + #[doc = "particularly on mobile platforms such as iOS."] #[doc = "- pem_key_cert_pair is a pointer on the object containing client's private"] #[doc = "key and certificate chain. This parameter can be NULL if the client does"] #[doc = "not have such a key/cert pair."] @@ -4564,6 +4624,14 @@ extern "C" { reserved: *mut ::std::os::raw::c_void, ) -> *mut grpc_channel_credentials; } +extern "C" { + pub fn grpc_ssl_credentials_create_ex( + pem_root_certs: *const ::std::os::raw::c_char, + pem_key_cert_pair: *mut grpc_ssl_pem_key_cert_pair, + verify_options: *const grpc_ssl_verify_peer_options, + reserved: *mut ::std::os::raw::c_void, + ) -> *mut grpc_channel_credentials; +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct grpc_call_credentials { @@ -4627,7 +4695,7 @@ extern "C" { } extern "C" { #[doc = " Creates an Oauth2 Access Token credentials with an access token that was"] - #[doc = "aquired by an out of band mechanism."] + #[doc = "acquired by an out of band mechanism."] pub fn grpc_access_token_credentials_create( access_token: *const ::std::os::raw::c_char, reserved: *mut ::std::os::raw::c_void, @@ -4641,106 +4709,262 @@ extern "C" { reserved: *mut ::std::os::raw::c_void, ) -> *mut grpc_call_credentials; } -#[doc = " Callback function to be called by the metadata credentials plugin"] -#[doc = "implementation when the metadata is ready."] -#[doc = "- user_data is the opaque pointer that was passed in the get_metadata method"] -#[doc = "of the grpc_metadata_credentials_plugin (see below)."] -#[doc = "- creds_md is an array of credentials metadata produced by the plugin. It"] -#[doc = "may be set to NULL in case of an error."] -#[doc = "- num_creds_md is the number of items in the creds_md array."] -#[doc = "- status must be GRPC_STATUS_OK in case of success or another specific error"] -#[doc = "code otherwise."] -#[doc = "- error_details contains details about the error if any. In case of success"] -#[doc = "it should be NULL and will be otherwise ignored."] -pub type grpc_credentials_plugin_metadata_cb = ::std::option::Option< - unsafe extern "C" fn( - user_data: *mut ::std::os::raw::c_void, - creds_md: *const grpc_metadata, - num_creds_md: usize, - status: grpc_status_code::Type, - error_details: *const ::std::os::raw::c_char, - ), ->; -#[doc = " Context that can be used by metadata credentials plugin in order to create"] -#[doc = "auth related metadata."] +#[doc = " Options for creating STS Oauth Token Exchange credentials following the IETF"] +#[doc = "draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16."] +#[doc = "Optional fields may be set to NULL or empty string. It is the responsibility"] +#[doc = "of the caller to ensure that the subject and actor tokens are refreshed on"] +#[doc = "disk at the specified paths. This API is used for experimental purposes for"] +#[doc = "now and may change in the future."] #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct grpc_auth_metadata_context { - #[doc = " The fully qualifed service url."] - pub service_url: *const ::std::os::raw::c_char, - #[doc = " The method name of the RPC being called (not fully qualified)."] - #[doc = "The fully qualified method name can be built from the service_url:"] - #[doc = "full_qualified_method_name = ctx->service_url + '/' + ctx->method_name."] - pub method_name: *const ::std::os::raw::c_char, - #[doc = " The auth_context of the channel which gives the server's identity."] - pub channel_auth_context: *const grpc_auth_context, - #[doc = " Reserved for future use."] - pub reserved: *mut ::std::os::raw::c_void, +pub struct grpc_sts_credentials_options { + pub token_exchange_service_uri: *const ::std::os::raw::c_char, + pub resource: *const ::std::os::raw::c_char, + pub audience: *const ::std::os::raw::c_char, + pub scope: *const ::std::os::raw::c_char, + pub requested_token_type: *const ::std::os::raw::c_char, + pub subject_token_path: *const ::std::os::raw::c_char, + pub subject_token_type: *const ::std::os::raw::c_char, + pub actor_token_path: *const ::std::os::raw::c_char, + pub actor_token_type: *const ::std::os::raw::c_char, } #[test] -fn bindgen_test_layout_grpc_auth_metadata_context() { +fn bindgen_test_layout_grpc_sts_credentials_options() { assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(grpc_auth_metadata_context)) + ::std::mem::size_of::(), + 72usize, + concat!("Size of: ", stringify!(grpc_sts_credentials_options)) ); assert_eq!( - ::std::mem::align_of::(), + ::std::mem::align_of::(), 8usize, - concat!("Alignment of ", stringify!(grpc_auth_metadata_context)) + concat!("Alignment of ", stringify!(grpc_sts_credentials_options)) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).service_url as *const _ as usize + &(*(::std::ptr::null::())).token_exchange_service_uri + as *const _ as usize }, 0usize, concat!( "Offset of field: ", - stringify!(grpc_auth_metadata_context), + stringify!(grpc_sts_credentials_options), "::", - stringify!(service_url) + stringify!(token_exchange_service_uri) ) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).method_name as *const _ as usize + &(*(::std::ptr::null::())).resource as *const _ as usize }, 8usize, concat!( "Offset of field: ", - stringify!(grpc_auth_metadata_context), + stringify!(grpc_sts_credentials_options), "::", - stringify!(method_name) + stringify!(resource) ) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).channel_auth_context as *const _ - as usize + &(*(::std::ptr::null::())).audience as *const _ as usize }, 16usize, concat!( "Offset of field: ", - stringify!(grpc_auth_metadata_context), + stringify!(grpc_sts_credentials_options), "::", - stringify!(channel_auth_context) + stringify!(audience) ) ); assert_eq!( unsafe { - &(*(::std::ptr::null::())).reserved as *const _ as usize + &(*(::std::ptr::null::())).scope as *const _ as usize }, 24usize, concat!( "Offset of field: ", - stringify!(grpc_auth_metadata_context), + stringify!(grpc_sts_credentials_options), "::", - stringify!(reserved) + stringify!(scope) ) ); -} -#[doc = " grpc_metadata_credentials plugin is an API user provided structure used to"] -#[doc = "create grpc_credentials objects that can be set on a channel (composed) or"] + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).requested_token_type + as *const _ as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(grpc_sts_credentials_options), + "::", + stringify!(requested_token_type) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).subject_token_path as *const _ + as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(grpc_sts_credentials_options), + "::", + stringify!(subject_token_path) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).subject_token_type as *const _ + as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(grpc_sts_credentials_options), + "::", + stringify!(subject_token_type) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).actor_token_path as *const _ + as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(grpc_sts_credentials_options), + "::", + stringify!(actor_token_path) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).actor_token_type as *const _ + as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(grpc_sts_credentials_options), + "::", + stringify!(actor_token_type) + ) + ); +} +extern "C" { + #[doc = " Creates an STS credentials following the STS Token Exchanged specifed in the"] + #[doc = "IETF draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16."] + #[doc = "This API is used for experimental purposes for now and may change in the"] + #[doc = "future."] + pub fn grpc_sts_credentials_create( + options: *const grpc_sts_credentials_options, + reserved: *mut ::std::os::raw::c_void, + ) -> *mut grpc_call_credentials; +} +#[doc = " Callback function to be called by the metadata credentials plugin"] +#[doc = "implementation when the metadata is ready."] +#[doc = "- user_data is the opaque pointer that was passed in the get_metadata method"] +#[doc = "of the grpc_metadata_credentials_plugin (see below)."] +#[doc = "- creds_md is an array of credentials metadata produced by the plugin. It"] +#[doc = "may be set to NULL in case of an error."] +#[doc = "- num_creds_md is the number of items in the creds_md array."] +#[doc = "- status must be GRPC_STATUS_OK in case of success or another specific error"] +#[doc = "code otherwise."] +#[doc = "- error_details contains details about the error if any. In case of success"] +#[doc = "it should be NULL and will be otherwise ignored."] +pub type grpc_credentials_plugin_metadata_cb = ::std::option::Option< + unsafe extern "C" fn( + user_data: *mut ::std::os::raw::c_void, + creds_md: *const grpc_metadata, + num_creds_md: usize, + status: grpc_status_code::Type, + error_details: *const ::std::os::raw::c_char, + ), +>; +#[doc = " Context that can be used by metadata credentials plugin in order to create"] +#[doc = "auth related metadata."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_auth_metadata_context { + #[doc = " The fully qualifed service url."] + pub service_url: *const ::std::os::raw::c_char, + #[doc = " The method name of the RPC being called (not fully qualified)."] + #[doc = "The fully qualified method name can be built from the service_url:"] + #[doc = "full_qualified_method_name = ctx->service_url + '/' + ctx->method_name."] + pub method_name: *const ::std::os::raw::c_char, + #[doc = " The auth_context of the channel which gives the server's identity."] + pub channel_auth_context: *const grpc_auth_context, + #[doc = " Reserved for future use."] + pub reserved: *mut ::std::os::raw::c_void, +} +#[test] +fn bindgen_test_layout_grpc_auth_metadata_context() { + assert_eq!( + ::std::mem::size_of::(), + 32usize, + concat!("Size of: ", stringify!(grpc_auth_metadata_context)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(grpc_auth_metadata_context)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).service_url as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(grpc_auth_metadata_context), + "::", + stringify!(service_url) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).method_name as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(grpc_auth_metadata_context), + "::", + stringify!(method_name) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).channel_auth_context as *const _ + as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(grpc_auth_metadata_context), + "::", + stringify!(channel_auth_context) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).reserved as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(grpc_auth_metadata_context), + "::", + stringify!(reserved) + ) + ); +} +#[doc = " grpc_metadata_credentials plugin is an API user provided structure used to"] +#[doc = "create grpc_credentials objects that can be set on a channel (composed) or"] #[doc = "a call. See grpc_credentials_metadata_create_from_plugin below."] #[doc = "The grpc client stack will call the get_metadata method of the plugin for"] #[doc = "every call in scope for the credentials created from it."] @@ -4947,7 +5171,7 @@ extern "C" { #[doc = " Deprecated in favor of grpc_ssl_server_credentials_create_with_options."] #[doc = "Same as grpc_ssl_server_credentials_create method except uses"] #[doc = "grpc_ssl_client_certificate_request_type enum to support more ways to"] - #[doc = "authenticate client cerificates."] + #[doc = "authenticate client certificates."] pub fn grpc_ssl_server_credentials_create_ex( pem_root_certs: *const ::std::os::raw::c_char, pem_key_cert_pairs: *mut grpc_ssl_pem_key_cert_pair, @@ -5192,6 +5416,556 @@ extern "C" { type_: grpc_local_connect_type, ) -> *mut grpc_server_credentials; } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_key_materials_config { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_credential_reload_config { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_server_authorization_check_config { + _unused: [u8; 0], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_credentials_options { + _unused: [u8; 0], +} +extern "C" { + #[doc = " Create an empty TLS credentials options. It is used for"] + #[doc = " experimental purpose for now and subject to change."] + pub fn grpc_tls_credentials_options_create() -> *mut grpc_tls_credentials_options; +} +extern "C" { + #[doc = " Set grpc_ssl_client_certificate_request_type field in credentials options"] + #[doc = "with the provided type. options should not be NULL."] + #[doc = "It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_credentials_options_set_cert_request_type( + options: *mut grpc_tls_credentials_options, + type_: grpc_ssl_client_certificate_request_type, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Set grpc_tls_key_materials_config field in credentials options"] + #[doc = "with the provided config struct whose ownership is transferred."] + #[doc = "Both parameters should not be NULL."] + #[doc = "It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_credentials_options_set_key_materials_config( + options: *mut grpc_tls_credentials_options, + config: *mut grpc_tls_key_materials_config, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Set grpc_tls_credential_reload_config field in credentials options"] + #[doc = "with the provided config struct whose ownership is transferred."] + #[doc = "Both parameters should not be NULL."] + #[doc = "It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_credentials_options_set_credential_reload_config( + options: *mut grpc_tls_credentials_options, + config: *mut grpc_tls_credential_reload_config, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Set grpc_tls_server_authorization_check_config field in credentials options"] + #[doc = "with the provided config struct whose ownership is transferred."] + #[doc = "Both parameters should not be NULL."] + #[doc = "It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_credentials_options_set_server_authorization_check_config( + options: *mut grpc_tls_credentials_options, + config: *mut grpc_tls_server_authorization_check_config, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Create an empty grpc_tls_key_materials_config instance."] + #[doc = " It is used for experimental purpose for now and subject to change."] + pub fn grpc_tls_key_materials_config_create() -> *mut grpc_tls_key_materials_config; +} +extern "C" { + #[doc = " Set grpc_tls_key_materials_config instance with provided a TLS certificate."] + #[doc = "config will take the ownership of pem_root_certs and pem_key_cert_pairs."] + #[doc = "It's valid for the caller to provide nullptr pem_root_certs, in which case"] + #[doc = "the gRPC-provided root cert will be used. pem_key_cert_pairs should not be"] + #[doc = "NULL. It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_key_materials_config_set_key_materials( + config: *mut grpc_tls_key_materials_config, + pem_root_certs: *const ::std::os::raw::c_char, + pem_key_cert_pairs: *mut *const grpc_ssl_pem_key_cert_pair, + num_key_cert_pairs: usize, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Set grpc_tls_key_materials_config instance with a provided version number,"] + #[doc = "which is used to keep track of the version of key materials."] + #[doc = "It returns 1 on success and 0 on failure. It is used for"] + #[doc = "experimental purpose for now and subject to change."] + pub fn grpc_tls_key_materials_config_set_version( + config: *mut grpc_tls_key_materials_config, + version: ::std::os::raw::c_int, + ) -> ::std::os::raw::c_int; +} +extern "C" { + #[doc = " Get the version number of a grpc_tls_key_materials_config instance."] + #[doc = "It returns the version number on success and -1 on failure."] + #[doc = "It is used for experimental purpose for now and subject to change."] + pub fn grpc_tls_key_materials_config_get_version( + config: *mut grpc_tls_key_materials_config, + ) -> ::std::os::raw::c_int; +} +#[doc = " A callback function provided by gRPC to handle the result of credential"] +#[doc = "reload. It is used when schedule API is implemented asynchronously and"] +#[doc = "serves to bring the control back to grpc C core. It is used for"] +#[doc = "experimental purpose for now and subject to change."] +pub type grpc_tls_on_credential_reload_done_cb = + ::std::option::Option; +#[doc = " A struct containing all information necessary to schedule/cancel a"] +#[doc = "credential reload request."] +#[doc = "- cb and cb_user_data represent a gRPC-provided"] +#[doc = "callback and an argument passed to it."] +#[doc = "- key_materials_config is an in/output parameter containing currently"] +#[doc = "used/newly reloaded credentials. If credential reload does not result"] +#[doc = "in a new credential, key_materials_config should not be modified."] +#[doc = "- status and error_details are used to hold information about"] +#[doc = "errors occurred when a credential reload request is scheduled/cancelled."] +#[doc = "- config is a pointer to the unique grpc_tls_credential_reload_config"] +#[doc = "instance that this argument corresponds to."] +#[doc = "- context is a pointer to a wrapped language implementation of this"] +#[doc = "grpc_tls_credential_reload_arg instance."] +#[doc = "- destroy_context is a pointer to a caller-provided method that cleans"] +#[doc = "up any data associated with the context pointer."] +#[doc = "It is used for experimental purposes for now and subject to change."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_credential_reload_arg { + pub cb: grpc_tls_on_credential_reload_done_cb, + pub cb_user_data: *mut ::std::os::raw::c_void, + pub key_materials_config: *mut grpc_tls_key_materials_config, + pub status: grpc_ssl_certificate_config_reload_status, + pub error_details: *const ::std::os::raw::c_char, + pub config: *mut grpc_tls_credential_reload_config, + pub context: *mut ::std::os::raw::c_void, + pub destroy_context: + ::std::option::Option, +} +#[test] +fn bindgen_test_layout_grpc_tls_credential_reload_arg() { + assert_eq!( + ::std::mem::size_of::(), + 64usize, + concat!("Size of: ", stringify!(grpc_tls_credential_reload_arg)) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!("Alignment of ", stringify!(grpc_tls_credential_reload_arg)) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cb as *const _ as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(cb) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cb_user_data as *const _ + as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(cb_user_data) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).key_materials_config + as *const _ as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(key_materials_config) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).status as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(status) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).error_details as *const _ + as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(error_details) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).config as *const _ as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(config) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).context as *const _ as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(context) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).destroy_context as *const _ + as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_credential_reload_arg), + "::", + stringify!(destroy_context) + ) + ); +} +extern "C" { + #[doc = " Create a grpc_tls_credential_reload_config instance."] + #[doc = "- config_user_data is config-specific, read-only user data"] + #[doc = "that works for all channels created with a credential using the config."] + #[doc = "- schedule is a pointer to an application-provided callback used to invoke"] + #[doc = "credential reload API. The implementation of this method has to be"] + #[doc = "non-blocking, but can be performed synchronously or asynchronously."] + #[doc = "1) If processing occurs synchronously, it populates arg->key_materials,"] + #[doc = "arg->status, and arg->error_details and returns zero."] + #[doc = "2) If processing occurs asynchronously, it returns a non-zero value."] + #[doc = "The application then invokes arg->cb when processing is completed. Note"] + #[doc = "that arg->cb cannot be invoked before schedule API returns."] + #[doc = "- cancel is a pointer to an application-provided callback used to cancel"] + #[doc = "a credential reload request scheduled via an asynchronous schedule API."] + #[doc = "arg is used to pinpoint an exact reloading request to be cancelled."] + #[doc = "The operation may not have any effect if the request has already been"] + #[doc = "processed."] + #[doc = "- destruct is a pointer to an application-provided callback used to clean up"] + #[doc = "any data associated with the config."] + #[doc = "It is used for experimental purpose for now and subject to change."] + pub fn grpc_tls_credential_reload_config_create( + config_user_data: *const ::std::os::raw::c_void, + schedule: ::std::option::Option< + unsafe extern "C" fn( + config_user_data: *mut ::std::os::raw::c_void, + arg: *mut grpc_tls_credential_reload_arg, + ) -> ::std::os::raw::c_int, + >, + cancel: ::std::option::Option< + unsafe extern "C" fn( + config_user_data: *mut ::std::os::raw::c_void, + arg: *mut grpc_tls_credential_reload_arg, + ), + >, + destruct: ::std::option::Option< + unsafe extern "C" fn(config_user_data: *mut ::std::os::raw::c_void), + >, + ) -> *mut grpc_tls_credential_reload_config; +} +#[doc = " callback function provided by gRPC used to handle the result of server"] +#[doc = "authorization check. It is used when schedule API is implemented"] +#[doc = "asynchronously, and serves to bring the control back to gRPC C core. It is"] +#[doc = "used for experimental purpose for now and subject to change."] +pub type grpc_tls_on_server_authorization_check_done_cb = + ::std::option::Option; +#[doc = " A struct containing all information necessary to schedule/cancel a server"] +#[doc = "authorization check request."] +#[doc = "- cb and cb_user_data represent a gRPC-provided callback and an argument"] +#[doc = "passed to it."] +#[doc = "- success will store the result of server authorization check. That is,"] +#[doc = "if success returns a non-zero value, it means the authorization check"] +#[doc = "passes and if returning zero, it means the check fails."] +#[doc = "- target_name is the name of an endpoint the channel is connecting to."] +#[doc = "- peer_cert represents a complete certificate chain including both"] +#[doc = "signing and leaf certificates."] +#[doc = "- status and error_details contain information"] +#[doc = "about errors occurred when a server authorization check request is"] +#[doc = "scheduled/cancelled."] +#[doc = "- config is a pointer to the unique"] +#[doc = "grpc_tls_server_authorization_check_config instance that this argument"] +#[doc = "corresponds to."] +#[doc = "- context is a pointer to a wrapped language implementation of this"] +#[doc = "grpc_tls_server_authorization_check_arg instance."] +#[doc = "- destroy_context is a pointer to a caller-provided method that cleans"] +#[doc = "up any data associated with the context pointer."] +#[doc = "It is used for experimental purpose for now and subject to change."] +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct grpc_tls_server_authorization_check_arg { + pub cb: grpc_tls_on_server_authorization_check_done_cb, + pub cb_user_data: *mut ::std::os::raw::c_void, + pub success: ::std::os::raw::c_int, + pub target_name: *const ::std::os::raw::c_char, + pub peer_cert: *const ::std::os::raw::c_char, + pub status: grpc_status_code::Type, + pub error_details: *const ::std::os::raw::c_char, + pub config: *mut grpc_tls_server_authorization_check_config, + pub context: *mut ::std::os::raw::c_void, + pub destroy_context: + ::std::option::Option, +} +#[test] +fn bindgen_test_layout_grpc_tls_server_authorization_check_arg() { + assert_eq!( + ::std::mem::size_of::(), + 80usize, + concat!( + "Size of: ", + stringify!(grpc_tls_server_authorization_check_arg) + ) + ); + assert_eq!( + ::std::mem::align_of::(), + 8usize, + concat!( + "Alignment of ", + stringify!(grpc_tls_server_authorization_check_arg) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cb as *const _ + as usize + }, + 0usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(cb) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).cb_user_data + as *const _ as usize + }, + 8usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(cb_user_data) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).success as *const _ + as usize + }, + 16usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(success) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).target_name + as *const _ as usize + }, + 24usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(target_name) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).peer_cert + as *const _ as usize + }, + 32usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(peer_cert) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).status as *const _ + as usize + }, + 40usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(status) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).error_details + as *const _ as usize + }, + 48usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(error_details) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).config as *const _ + as usize + }, + 56usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(config) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).context as *const _ + as usize + }, + 64usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(context) + ) + ); + assert_eq!( + unsafe { + &(*(::std::ptr::null::())).destroy_context + as *const _ as usize + }, + 72usize, + concat!( + "Offset of field: ", + stringify!(grpc_tls_server_authorization_check_arg), + "::", + stringify!(destroy_context) + ) + ); +} +extern "C" { + #[doc = " Create a grpc_tls_server_authorization_check_config instance."] + #[doc = "- config_user_data is config-specific, read-only user data"] + #[doc = "that works for all channels created with a credential using the config."] + #[doc = "- schedule is a pointer to an application-provided callback used to invoke"] + #[doc = "server authorization check API. The implementation of this method has to"] + #[doc = "be non-blocking, but can be performed synchronously or asynchronously."] + #[doc = "1)If processing occurs synchronously, it populates arg->result,"] + #[doc = "arg->status, and arg->error_details and returns zero."] + #[doc = "2) If processing occurs asynchronously, it returns a non-zero value. The"] + #[doc = "application then invokes arg->cb when processing is completed. Note that"] + #[doc = "arg->cb cannot be invoked before schedule API returns."] + #[doc = "- cancel is a pointer to an application-provided callback used to cancel a"] + #[doc = "server authorization check request scheduled via an asynchronous schedule"] + #[doc = "API. arg is used to pinpoint an exact check request to be cancelled. The"] + #[doc = "operation may not have any effect if the request has already been"] + #[doc = "processed."] + #[doc = "- destruct is a pointer to an application-provided callback used to clean up"] + #[doc = "any data associated with the config."] + #[doc = "It is used for experimental purpose for now and subject to change."] + pub fn grpc_tls_server_authorization_check_config_create( + config_user_data: *const ::std::os::raw::c_void, + schedule: ::std::option::Option< + unsafe extern "C" fn( + config_user_data: *mut ::std::os::raw::c_void, + arg: *mut grpc_tls_server_authorization_check_arg, + ) -> ::std::os::raw::c_int, + >, + cancel: ::std::option::Option< + unsafe extern "C" fn( + config_user_data: *mut ::std::os::raw::c_void, + arg: *mut grpc_tls_server_authorization_check_arg, + ), + >, + destruct: ::std::option::Option< + unsafe extern "C" fn(config_user_data: *mut ::std::os::raw::c_void), + >, + ) -> *mut grpc_tls_server_authorization_check_config; +} +extern "C" { + #[doc = " This method creates a TLS SPIFFE channel credential object."] + #[doc = " It takes ownership of the options parameter."] + #[doc = ""] + #[doc = " - options: grpc TLS credentials options instance."] + #[doc = ""] + #[doc = " It returns the created credential object."] + #[doc = ""] + #[doc = " It is used for experimental purpose for now and subject"] + #[doc = " to change."] + pub fn grpc_tls_spiffe_credentials_create( + options: *mut grpc_tls_credentials_options, + ) -> *mut grpc_channel_credentials; +} +extern "C" { + #[doc = " This method creates a TLS server credential object."] + #[doc = " It takes ownership of the options parameter."] + #[doc = ""] + #[doc = " - options: grpc TLS credentials options instance."] + #[doc = ""] + #[doc = " It returns the created credential object."] + #[doc = ""] + #[doc = " It is used for experimental purpose for now and subject"] + #[doc = " to change."] + pub fn grpc_tls_spiffe_server_credentials_create( + options: *mut grpc_tls_credentials_options, + ) -> *mut grpc_server_credentials; +} #[repr(u32)] #[doc = " The severity of a log message - use the #defines below when calling into"] #[doc = "gpr_log to additionally supply file and line data"] @@ -5301,83 +6075,6 @@ pub type gpr_log_func = ::std::option::Option *mut ::std::os::raw::c_void>, - pub zalloc_fn: - ::std::option::Option *mut ::std::os::raw::c_void>, - #[doc = " if NULL, uses malloc_fn then memset"] - pub realloc_fn: ::std::option::Option< - unsafe extern "C" fn( - ptr: *mut ::std::os::raw::c_void, - size: usize, - ) -> *mut ::std::os::raw::c_void, - >, - pub free_fn: ::std::option::Option, -} -#[test] -fn bindgen_test_layout_gpr_allocation_functions() { - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(gpr_allocation_functions)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(gpr_allocation_functions)) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).malloc_fn as *const _ as usize - }, - 0usize, - concat!( - "Offset of field: ", - stringify!(gpr_allocation_functions), - "::", - stringify!(malloc_fn) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).zalloc_fn as *const _ as usize - }, - 8usize, - concat!( - "Offset of field: ", - stringify!(gpr_allocation_functions), - "::", - stringify!(zalloc_fn) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).realloc_fn as *const _ as usize - }, - 16usize, - concat!( - "Offset of field: ", - stringify!(gpr_allocation_functions), - "::", - stringify!(realloc_fn) - ) - ); - assert_eq!( - unsafe { - &(*(::std::ptr::null::())).free_fn as *const _ as usize - }, - 24usize, - concat!( - "Offset of field: ", - stringify!(gpr_allocation_functions), - "::", - stringify!(free_fn) - ) - ); -} extern "C" { #[doc = " malloc."] #[doc = " If size==0, always returns NULL. Otherwise this function never returns NULL."] @@ -5406,17 +6103,6 @@ extern "C" { #[doc = " free memory allocated by gpr_malloc_aligned"] pub fn gpr_free_aligned(ptr: *mut ::std::os::raw::c_void); } -extern "C" { - #[doc = " Request the family of allocation functions in \\a functions be used. NOTE"] - #[doc = " that this request will be honored in a *best effort* basis and that no"] - #[doc = " guarantees are made about the default functions (eg, malloc) being called."] - #[doc = " The functions.free_fn implementation must be a no-op for NULL input."] - pub fn gpr_set_allocation_functions(functions: gpr_allocation_functions); -} -extern "C" { - #[doc = " Return the family of allocation functions currently in effect."] - pub fn gpr_get_allocation_functions() -> gpr_allocation_functions; -} extern "C" { #[doc = " Return the number of CPU cores on the current system. Will return 0 if"] #[doc = "the information is not available."] diff --git a/grpc-sys/build.rs b/grpc-sys/build.rs index 5901cc850..cf7274927 100644 --- a/grpc-sys/build.rs +++ b/grpc-sys/build.rs @@ -15,7 +15,7 @@ use cmake::Config; use pkg_config::{Config as PkgConfig, Library}; use walkdir::WalkDir; -const GRPC_VERSION: &'static str = "1.17.2"; +const GRPC_VERSION: &'static str = "1.26.0"; fn probe_library(library: &str, cargo_metadata: bool) -> Library { match PkgConfig::new() @@ -178,6 +178,7 @@ fn build_grpc(cc: &mut Build, library: &str) { println!("cargo:rustc-link-lib=static=cares"); println!("cargo:rustc-link-lib=static=gpr"); println!("cargo:rustc-link-lib=static=address_sorting"); + println!("cargo:rustc-link-lib=static=upb"); println!("cargo:rustc-link-lib=static={}", library); if cfg!(feature = "secure") { diff --git a/grpc-sys/grpc b/grpc-sys/grpc index 57a3c97b3..d6347b839 160000 --- a/grpc-sys/grpc +++ b/grpc-sys/grpc @@ -1 +1 @@ -Subproject commit 57a3c97b3e03c68e0c74a7955a6ff8da73d5a674 +Subproject commit d6347b8398be8c1607427b0924f26fae53a5ba3a diff --git a/src/buf.rs b/src/buf.rs index 52395d9af..7731fd598 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -6,8 +6,6 @@ use std::ffi::{c_void, CStr, CString}; use std::fmt::{self, Debug, Formatter}; use std::io::{self, BufRead, Read}; use std::mem::{self, ManuallyDrop, MaybeUninit}; -use std::ptr; -use std::sync::atomic::{self, AtomicUsize, Ordering}; /// A convenient rust wrapper for the type `grpc_slice`. /// @@ -107,84 +105,33 @@ impl PartialEq for GrpcSlice { } } -/// `grpc_slice` use `grpc_slice_refcount` to trace the lifetime of inner data. -/// -/// When ref count decreases to 0, there will be no access to the data. -/// To utilize the mechanism, we need to define a struct which has -/// `grpc_slice_refcount` type as the first field, so that it's safe to cast -/// a pointer to the struct to `grpc_slice_refcount` and all ref/unref operations -/// will be forwarded to our own implement. -/// -/// Vec will be stored inside the struct so that it will be dropped automatically -/// once the struct is dropped. -/// -/// Note that the struct should not be moved if `sub_refcount` at `grpc_slice_refcount` -/// points back to the `VecRefCount` itself. -#[repr(C)] -struct VecRefCount { - rc: grpc_slice_refcount, - refs: AtomicUsize, - v: Vec, -} - -unsafe extern "C" fn vec_ref(rc_ptr: *mut c_void) { - let rc_ptr = rc_ptr as *mut VecRefCount; - (*rc_ptr).refs.fetch_add(1, Ordering::Relaxed); -} - -unsafe extern "C" fn vec_unref(rc_ptr: *mut c_void) { - let rc_ptr = rc_ptr as *mut VecRefCount; - if (*rc_ptr).refs.fetch_sub(1, Ordering::Release) != 1 { - return; - } - - atomic::fence(Ordering::Acquire); - Box::from_raw(rc_ptr); +unsafe extern "C" fn drop_vec(ptr: *mut c_void, len: usize) { + Vec::from_raw_parts(ptr as *mut u8, len, len); } -/// The global vtable for vec. -const VEC_REF_COUNT_VTABLE: grpc_slice_refcount_vtable = grpc_slice_refcount_vtable { - ref_: Some(vec_ref), - unref: Some(vec_unref), - eq: Some(grpc_slice_default_eq_impl), - hash: Some(grpc_slice_default_hash_impl), -}; - impl From> for GrpcSlice { /// Converts a `Vec` into `GrpcSlice`. /// /// If v can't fit inline, there will be allocations. #[inline] fn from(mut v: Vec) -> GrpcSlice { - let mut slice = GrpcSlice::default(); if v.is_empty() { - return slice; - } else if v.len() <= mem::size_of_val(unsafe { &slice.0.data.inlined.bytes }) { - unsafe { - slice.0.data.inlined.length = v.len() as u8; - slice.0.data.inlined.bytes[..v.len()].copy_from_slice(&v); - } - return slice; + return GrpcSlice::default(); } - unsafe { - slice.0.data = grpc_slice_grpc_slice_data { - refcounted: grpc_slice_grpc_slice_data_grpc_slice_refcounted { - bytes: v.as_mut_ptr(), - length: v.len(), - }, + + if v.len() == v.capacity() { + let slice = unsafe { + grpcio_sys::grpc_slice_new_with_len(v.as_mut_ptr() as _, v.len(), Some(drop_vec)) }; + mem::forget(v); + return GrpcSlice(slice); + } - let mut ref_count = Box::new(VecRefCount { - rc: grpc_slice_refcount { - vtable: &VEC_REF_COUNT_VTABLE, - sub_refcount: ptr::null_mut(), - }, - refs: AtomicUsize::new(1), - v, - }); - ref_count.rc.sub_refcount = &mut ref_count.rc; - slice.0.refcount = Box::into_raw(mem::transmute(ref_count)); - slice + unsafe { + GrpcSlice(grpcio_sys::grpc_slice_from_copied_buffer( + v.as_mut_ptr() as _, + v.len(), + )) } } }