diff --git a/src/bindings_go.rs b/src/bindings_go.rs index dec15de..d2d9921 100644 --- a/src/bindings_go.rs +++ b/src/bindings_go.rs @@ -11,8 +11,18 @@ use crate::cwtchlib_go::bindings; use crate::{ConversationID, CwtchError, FileKey, ProfileIdentity, ServerIdentity, structs::*}; use crate::event::Event; +type c_bool = core::ffi::c_char; + +fn from_c_bool(b: c_bool) -> bool { + b == 1 +} + +fn to_c_bool(b: bool) -> c_bool { + if b { 1 } else { 0 } +} + struct c_str_wrap { - raw: *mut i8, + raw: *mut core::ffi::c_char, len: i32, } @@ -90,7 +100,7 @@ impl CwtchLibGo { c_bind!(_get_profile_attribute(profile: &str, key: &str;;) c_GetProfileAttribute -> String); c_bind!(_get_conversation_attribute(profile: &str; conversation_id: i32; key: &str) c_GetConversationAttribute -> String); c_bind!(_get_appbus_event(;;) c_GetAppBusEvent -> String); - c_bind!(_create_profile(nick: &str, pass: &str; autostart: i8;) c_CreateProfile); + c_bind!(_create_profile(nick: &str, pass: &str; autostart: c_bool;) c_CreateProfile); c_bind!(_activate_peer_engine(profile: &str;;) c_ActivatePeerEngine); c_bind!(_deactivate_peer_engine(profile: &str;;) c_DeactivatePeerEngine); c_bind!(_accept_conversation(profile: &str ; conversation_id: i32; ) c_AcceptConversation); @@ -118,6 +128,7 @@ impl CwtchLibGo { c_bind!(_update_message_attribute(profile: &str; conversation_id: i32, channel_id: i32, message_id: i32; key: &str, val: &str) c_UpdateMessageAttribute); c_bind!(_change_password(profile: &str, old_pass: &str, new_pass: &str, new_pass_again: &str;;) c_ChangePassword); c_bind!(_export_profile(profile: &str, filename: &str;;) c_ExportProfile); + c_bind!(_create_server(password: &str, description: &str; autostart: c_bool;) c_CreateServer); c_bind!(_delete_server(server: &str, current_password: &str;;) c_DeleteServer); c_bind!(_launch_server(server: &str;;) c_LaunchServer); c_bind!(_stop_server(server: &str;;) c_StopServer); @@ -136,8 +147,9 @@ impl CwtchLib for CwtchLibGo { } c_bind!(reconnect_cwtch_foreground(;;) c_ReconnectCwtchForeground); fn create_profile(&self, nick: &str, pass: &str, autostart: bool) { - self._create_profile(nick, pass, if autostart { 1 } else { 0 }) + self._create_profile(nick, pass, to_c_bool(autostart)) } + fn activate_peer_engine(&self, profile: &ProfileIdentity) { self._activate_peer_engine(profile.as_str()) } @@ -277,7 +289,9 @@ impl CwtchLib for CwtchLibGo { } c_bind!(load_servers(password: &str;;) c_LoadServers); - c_bind!(create_server(password: &str, description: &str; autostart: i8;) c_CreateServer); + fn create_server(&self, password: &str, description: &str , autostart: bool) { + self._create_server(password, description, to_c_bool(autostart)) + } fn delete_server(&self, server: ServerIdentity, current_password: &str) { self._delete_server(String::from(server).as_str(), current_password) } diff --git a/src/lib.rs b/src/lib.rs index c88ce41..8a96365 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -168,8 +168,8 @@ pub trait CwtchLib { /// Load all servers encrypted by password fn load_servers(&self, password: &str); - /// Create a new server, encrypted with password, autostart i8 used as bool - fn create_server(&self, password: &str, description: &str, autostart: i8); + /// Create a new server, encrypted with password + fn create_server(&self, password: &str, description: &str, autostart: bool); /// Delete the specified server (if password is correct) fn delete_server(&self, server: ServerIdentity, current_password: &str);