11use crate :: client:: { FluvioClient , fluvio_connect} ;
22use crate :: producer:: { FluvioProducer , create_producer, producer_send, producer_flush} ;
3- use crate :: consumer:: { FluvioConsumer , FluvioStream , FluvioRecord , partition_consumer , consumer_stream, stream_next} ;
3+ use crate :: consumer:: { FluvioStream , FluvioRecord , 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) ; } }
@@ -65,19 +84,73 @@ pub extern "C" fn fluvio_c_produce_output_free(out: *mut FluvioProduceOutput) {
6584}
6685
6786#[ unsafe( no_mangle) ]
68- pub extern "C" fn fluvio_c_partition_consumer ( client : * mut FluvioClient , topic : * const c_char , partition : u32 , out_consumer : * mut * mut FluvioConsumer ) -> i32 {
69- if client. is_null ( ) || topic. is_null ( ) || out_consumer. is_null ( ) { return -1 ; }
70- let topic_str = unsafe { CStr :: from_ptr ( topic) . to_str ( ) } . unwrap_or ( "" ) ;
71- match partition_consumer ( unsafe { & * client } , topic_str, partition) {
72- Ok ( consumer) => { unsafe { * out_consumer = Box :: into_raw ( consumer) ; } 0 }
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 }
7391 Err ( _) => -1 ,
7492 }
7593}
7694
7795#[ unsafe( no_mangle) ]
78- pub extern "C" fn fluvio_c_consumer_stream ( consumer : * mut FluvioConsumer , offset_index : i64 , out_stream : * mut * mut FluvioStream ) -> i32 {
79- if consumer. is_null ( ) || out_stream. is_null ( ) { return -1 ; }
80- match consumer_stream ( unsafe { & * consumer } , offset_index) {
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+
149+ #[ unsafe( no_mangle) ]
150+ pub extern "C" fn fluvio_c_consumer_stream ( client : * mut FluvioClient , topic : * const c_char , partition : u32 , offset_index : i64 , out_stream : * mut * mut FluvioStream ) -> i32 {
151+ if client. is_null ( ) || topic. is_null ( ) || out_stream. is_null ( ) { return -1 ; }
152+ let topic_str = unsafe { CStr :: from_ptr ( topic) . to_str ( ) } . unwrap_or ( "" ) ;
153+ match consumer_stream ( unsafe { & * client } , topic_str, partition, offset_index) {
81154 Ok ( stream) => { unsafe { * out_stream = Box :: into_raw ( stream) ; } 0 }
82155 Err ( _) => -1 ,
83156 }
@@ -110,7 +183,3 @@ pub extern "C" fn fluvio_c_stream_free(stream: *mut FluvioStream) {
110183 if !stream. is_null ( ) { unsafe { let _ = Box :: from_raw ( stream) ; } }
111184}
112185
113- #[ unsafe( no_mangle) ]
114- pub extern "C" fn fluvio_c_consumer_free ( consumer : * mut FluvioConsumer ) {
115- if !consumer. is_null ( ) { unsafe { let _ = Box :: from_raw ( consumer) ; } }
116- }
0 commit comments