@@ -2,9 +2,15 @@ use crate::client::{FluvioClient, fluvio_connect};
22use crate :: producer:: { FluvioProducer , create_producer, producer_send, producer_flush} ;
33use crate :: consumer:: { FluvioConsumer , FluvioStream , FluvioRecord , partition_consumer, consumer_stream, stream_next} ;
44use crate :: produce_output:: { FluvioProduceOutput , produce_output_wait} ;
5+ use crate :: config:: { FluvioConfigWrapper , fluvio_config_load} ;
56use std:: os:: raw:: c_char;
67use std:: ffi:: CStr ;
78
9+ #[ repr( C ) ]
10+ pub struct fluvio_config_t {
11+ _private : [ u8 ; 0 ] ,
12+ }
13+
814#[ unsafe( no_mangle) ]
915pub extern "C" fn fluvio_c_connect ( out_client : * mut * mut FluvioClient ) -> i32 {
1016 match fluvio_connect ( ) {
@@ -16,6 +22,19 @@ pub extern "C" fn fluvio_c_connect(out_client: *mut *mut FluvioClient) -> i32 {
1622 }
1723}
1824
25+ #[ unsafe( no_mangle) ]
26+ pub unsafe extern "C" fn fluvio_c_connect_with_config ( config : * mut fluvio_config_t , out_client : * mut * mut FluvioClient ) -> i32 {
27+ if config. is_null ( ) || out_client. is_null ( ) { return -1 ; }
28+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
29+ match crate :: client:: fluvio_connect_with_config ( config_wrapper) {
30+ Ok ( client) => {
31+ unsafe { * out_client = Box :: into_raw ( client) ; }
32+ 0
33+ }
34+ Err ( _) => -1 ,
35+ }
36+ }
37+
1938#[ unsafe( no_mangle) ]
2039pub extern "C" fn fluvio_c_client_free ( client : * mut FluvioClient ) {
2140 if !client. is_null ( ) { unsafe { let _ = Box :: from_raw ( client) ; } }
@@ -64,6 +83,69 @@ pub extern "C" fn fluvio_c_produce_output_free(out: *mut FluvioProduceOutput) {
6483 if !out. is_null ( ) { unsafe { let _ = Box :: from_raw ( out) ; } }
6584}
6685
86+ #[ unsafe( no_mangle) ]
87+ pub extern "C" fn fluvio_c_config_load ( out_config : * mut * mut fluvio_config_t ) -> i32 {
88+ if out_config. is_null ( ) { return -1 ; }
89+ match fluvio_config_load ( ) {
90+ Ok ( config) => { unsafe { * out_config = Box :: into_raw ( config) as * mut fluvio_config_t ; } 0 }
91+ Err ( _) => -1 ,
92+ }
93+ }
94+
95+ #[ unsafe( no_mangle) ]
96+ pub unsafe extern "C" fn fluvio_c_config_set_endpoint ( config : * mut fluvio_config_t , endpoint : * const std:: ffi:: c_char ) {
97+ if config. is_null ( ) || endpoint. is_null ( ) { return ; }
98+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
99+ let ep_str = std:: ffi:: CStr :: from_ptr ( endpoint) . to_string_lossy ( ) ;
100+ crate :: config:: fluvio_config_set_endpoint ( config_wrapper, & ep_str) ;
101+ }
102+
103+ #[ unsafe( no_mangle) ]
104+ pub unsafe extern "C" fn fluvio_c_config_set_client_id ( config : * mut fluvio_config_t , client_id : * const std:: ffi:: c_char ) {
105+ if config. is_null ( ) || client_id. is_null ( ) { return ; }
106+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
107+ let client_id_str = std:: ffi:: CStr :: from_ptr ( client_id) . to_string_lossy ( ) ;
108+ crate :: config:: fluvio_config_set_client_id ( config_wrapper, & client_id_str) ;
109+ }
110+
111+ #[ unsafe( no_mangle) ]
112+ pub unsafe extern "C" fn fluvio_c_config_disable_tls ( config : * mut fluvio_config_t ) {
113+ if config. is_null ( ) { return ; }
114+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
115+ crate :: config:: fluvio_config_disable_tls ( config_wrapper) ;
116+ }
117+
118+ #[ unsafe( no_mangle) ]
119+ pub unsafe extern "C" fn fluvio_c_config_set_anonymous_tls ( config : * mut fluvio_config_t ) {
120+ if config. is_null ( ) { return ; }
121+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
122+ crate :: config:: fluvio_config_set_anonymous_tls ( config_wrapper) ;
123+ }
124+
125+ #[ unsafe( no_mangle) ]
126+ pub unsafe extern "C" fn fluvio_c_config_set_inline_tls ( config : * mut fluvio_config_t , domain : * const std:: ffi:: c_char , key : * const std:: ffi:: c_char , cert : * const std:: ffi:: c_char , ca_cert : * const std:: ffi:: c_char ) {
127+ if config. is_null ( ) || domain. is_null ( ) || key. is_null ( ) || cert. is_null ( ) || ca_cert. is_null ( ) { return ; }
128+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
129+ crate :: config:: fluvio_config_set_inline_tls ( config_wrapper,
130+ & std:: ffi:: CStr :: from_ptr ( domain) . to_string_lossy ( ) ,
131+ & std:: ffi:: CStr :: from_ptr ( key) . to_string_lossy ( ) ,
132+ & std:: ffi:: CStr :: from_ptr ( cert) . to_string_lossy ( ) ,
133+ & std:: ffi:: CStr :: from_ptr ( ca_cert) . to_string_lossy ( ) ,
134+ ) ;
135+ }
136+
137+ #[ unsafe( no_mangle) ]
138+ pub unsafe extern "C" fn fluvio_c_config_set_tls_file_paths ( config : * mut fluvio_config_t , domain : * const std:: ffi:: c_char , key_path : * const std:: ffi:: c_char , cert_path : * const std:: ffi:: c_char , ca_cert_path : * const std:: ffi:: c_char ) {
139+ if config. is_null ( ) || domain. is_null ( ) || key_path. is_null ( ) || cert_path. is_null ( ) || ca_cert_path. is_null ( ) { return ; }
140+ let config_wrapper = & mut * ( config as * mut FluvioConfigWrapper ) ;
141+ crate :: config:: fluvio_config_set_tls_file_paths ( config_wrapper,
142+ & std:: ffi:: CStr :: from_ptr ( domain) . to_string_lossy ( ) ,
143+ & std:: ffi:: CStr :: from_ptr ( key_path) . to_string_lossy ( ) ,
144+ & std:: ffi:: CStr :: from_ptr ( cert_path) . to_string_lossy ( ) ,
145+ & std:: ffi:: CStr :: from_ptr ( ca_cert_path) . to_string_lossy ( ) ,
146+ ) ;
147+ }
148+
67149#[ unsafe( no_mangle) ]
68150pub extern "C" fn fluvio_c_partition_consumer ( client : * mut FluvioClient , topic : * const c_char , partition : u32 , out_consumer : * mut * mut FluvioConsumer ) -> i32 {
69151 if client. is_null ( ) || topic. is_null ( ) || out_consumer. is_null ( ) { return -1 ; }
0 commit comments