diff --git a/src/bindings_go.rs b/src/bindings_go.rs index 37c4874..1acb34c 100644 --- a/src/bindings_go.rs +++ b/src/bindings_go.rs @@ -8,7 +8,7 @@ use std::ffi::CString; use super::CwtchLib; use crate::cwtchlib_go::bindings; -use crate::{ConversationID, CwtchError, ProfileIdentity, ServerIdentity, structs::*}; +use crate::{ConversationID, CwtchError, FileKey, ProfileIdentity, ServerIdentity, structs::*}; use crate::event::Event; struct c_str_wrap { @@ -123,48 +123,48 @@ impl CwtchLib for CwtchLibGo { c_bind!(started(;;) c_Started -> i32); c_bind!(send_app_event(event_json: &str;;) c_SendAppEvent); fn send_profile_event(&self, profile: ProfileIdentity, event_jason: &str) { - self._send_profile_event(profile.into(), event_jason) + self._send_profile_event(String::from(profile).as_str(), event_jason) } c_bind!(create_profile(nick: &str, pass: &str;;) c_CreateProfile); c_bind!(load_profiles(pass: &str;;) c_LoadProfiles); fn accept_conversation(&self, profile: ProfileIdentity, conversation_id: ConversationID) { - self._accept_conversation(profile.into(), conversation_id.into()) + self._accept_conversation(String::from(profile).as_str(), conversation_id.into()) } fn block_contact(&self, profile: ProfileIdentity, conversation_id: ConversationID) { - self._block_contact(profile.into(), conversation_id.into()) + self._block_contact(String::from(profile).as_str(), conversation_id.into()) } fn unblock_contact(&self, profile: ProfileIdentity, conversation_id: ConversationID) { - self._unblock_contact(profile.into(), conversation_id.into()) + self._unblock_contact(String::from(profile).as_str(), conversation_id.into()) } fn get_message(&self, profile: ProfileIdentity, conversation_id: ConversationID, message_index: i32) -> String { - self._get_message(profile.into(), conversation_id.into(), message_index) + self._get_message(String::from(profile).as_str(), conversation_id.into(), message_index) } fn get_message_by_id(&self, profile: ProfileIdentity, conversation_id: ConversationID, message_id: i32) -> String { - self._get_message_by_id(profile.into(), conversation_id.into(), message_id) + self._get_message_by_id(String::from(profile).as_str(), conversation_id.into(), message_id) } fn get_message_by_content_hash(&self, profile: ProfileIdentity, conversation_id: ConversationID, hash: &str) -> String { - self._get_message_by_content_hash(profile.into(), conversation_id.into(), hash) + self._get_message_by_content_hash(String::from(profile).as_str(), conversation_id.into(), hash) } fn get_messages(&self, profile: ProfileIdentity, conversation_id: ConversationID, message_index: i32, count: i32) -> String { - self.get_messages(profile.into(), conversation_id, message_index, count) + self._get_messages(String::from(profile).as_str(), conversation_id.into(), message_index, count) } fn send_message(&self, profile: ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String { - self._send_message(profile.into(), conversation_id.into(), msg) + self._send_message(String::from(profile).as_str(), conversation_id.into(), msg) } fn send_invitation(&self, profile: ProfileIdentity, conversation_id: ConversationID, target_id: i32) -> String { - self._send_invitation(profile.into(), conversation_id.into(), target_id) + self._send_invitation(String::from(profile).as_str(), conversation_id.into(), target_id) } fn share_file(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_path: &str) -> String { - self.share_file(profile.into(), conversation_id, file_path) + self._share_file(String::from(profile).as_str(), conversation_id.into(), file_path) } - fn download_file(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_path: &str, manifest_path: &str, file_key: &str) { - self._download_file(profile.into(), conversation_id.into(), file_path, manifest_path, file_key) + fn download_file(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_path: &str, manifest_path: &str, file_key: FileKey) { + self._download_file(String::from(profile).as_str(), conversation_id.into(), file_path, manifest_path, String::from(file_key).as_str()) } - fn check_download_status(&self, profile: ProfileIdentity, file_key: &str) { - self._check_download_status(profile.into(), file_key) + fn check_download_status(&self, profile: ProfileIdentity, file_key: FileKey) { + self._check_download_status(String::from(profile).as_str(), String::from(file_key).as_str()) } - fn verify_or_resume_download(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_key: &str) { - self._verify_or_resume_download(profile.into(), conversation_id.into(), file_key) + fn verify_or_resume_download(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_key: FileKey) { + self._verify_or_resume_download(String::from(profile).as_str(), conversation_id.into(), String::from(file_key).as_str()) } fn reset_tor(&self) { @@ -173,26 +173,26 @@ impl CwtchLib for CwtchLibGo { } } fn create_group(&self, profile: ProfileIdentity, server: &str, name: &str) { - self._create_group(profile.into(), server, name) + self._create_group(String::from(profile).as_str(), server, name) } fn delete_profile(&self, profile: ProfileIdentity, pass: &str) { - self._delete_profile(profile.into(), pass) + self._delete_profile(String::from(profile).as_str(), pass) } fn archive_conversation(&self, profile: ProfileIdentity, conversation_id: ConversationID) { - self._archive_conversation(profile.into(), conversation_id.into()) + self._archive_conversation(String::from(profile).as_str(), conversation_id.into()) } fn delete_contact(&self, profile: ProfileIdentity, conversation_id: ConversationID) { - self._delete_contact(profile.into(), conversation_id.into()) + self._delete_contact(String::from(profile).as_str(), conversation_id.into()) } fn import_bundle(&self, profile: ProfileIdentity, bundle: &str) { - self._import_bundle(profile.into(), bundle) + self._import_bundle(String::from(profile).as_str(), bundle) } fn set_profile_attribute(&self, profile: ProfileIdentity, key: &str, val: &str) { - self._set_profile_attribute(profile.into(), key, val) + self._set_profile_attribute(String::from(profile).as_str(), key, val) } fn get_profile_attribute(&self, profile: ProfileIdentity, key: &str) -> Result, CwtchError> { - let resp = self._get_profile_attribute(profile.into(), key); + let resp = self._get_profile_attribute(String::from(profile).as_str(), key); let attr: Attribute = match serde_json::from_str(&resp) { Ok(attr) => attr, Err(e) => return Err(e.to_string()), @@ -203,10 +203,10 @@ impl CwtchLib for CwtchLibGo { } } fn set_conversation_attribute(&self, profile: ProfileIdentity, conversation_id: ConversationID, key: &str, val: &str) { - self._set_conversation_attribute(profile.into(), conversation_id.into(), key, val) + self._set_conversation_attribute(String::from(profile).as_str(), conversation_id.into(), key, val) } fn get_conversation_attribute(&self, profile: ProfileIdentity, conversation_id: ConversationID, key: &str) -> Result, CwtchError> { - let resp = self._get_conversation_attribute(profile.into(), conversation_id.into(), key); + let resp = self._get_conversation_attribute(String::from(profile).as_str(), conversation_id.into(), key); let attr: Attribute = match serde_json::from_str(&resp) { Ok(attr) => attr, Err(e) => return Err(e.to_string()), @@ -217,13 +217,13 @@ impl CwtchLib for CwtchLibGo { } } fn set_message_attribute(&self, profile: ProfileIdentity, conversation_id: ConversationID, channel_id: i32, message_id: i32, key: &str, val: &str) { - self._set_message_attribute(profile.into(), conversation_id.into(), channel_id, message_id, key, val) + self._set_message_attribute(String::from(profile).as_str(), conversation_id.into(), channel_id, message_id, key, val) } fn change_password(&self, profile: ProfileIdentity, old_pass: &str, new_pass: &str, new_pass_again: &str) { - self._change_password(profile.into(), old_pass, new_pass, new_pass_again) + self._change_password(String::from(profile).as_str(), old_pass, new_pass, new_pass_again) } fn export_profile(&self, profile: ProfileIdentity, filename: &str) { - self._export_profile(profile.into(), filename) + self._export_profile(String::from(profile).as_str(), filename) } c_bind!(import_profile(filename: &str, password: &str;;) c_ImportProfile -> String); @@ -238,19 +238,19 @@ 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 delete_server(&self, server: ServerIdentity, current_password: &str) { - self._delete_server(server.into(), current_password) + self._delete_server(String::from(server).as_str(), current_password) } c_bind!(launch_servers(;;) c_LaunchServers); fn launch_server(&self, server: ServerIdentity) { - self._launch_server(server.into()) + self._launch_server(String::from(server).as_str()) } fn stop_server(&self, server: ServerIdentity) { - self._stop_server(server.into()) + self._stop_server(String::from(server).as_str()) } c_bind!(stop_servers(;;) c_StopServers); c_bind!(destroy_servers(;;) c_DestroyServers); fn set_server_attribute(&self, server: ServerIdentity, key: &str, val: &str) { - self._set_server_attribute(server.into(), key, val) + self._set_server_attribute(String::from(server).as_str(), key, val) } c_bind!(get_debug_info(;;) c_GetDebugInfo -> String); diff --git a/src/event.rs b/src/event.rs index 1e4ba96..3aaa5a7 100644 --- a/src/event.rs +++ b/src/event.rs @@ -31,14 +31,6 @@ impl From<&str> for ProfileIdentity { } } -impl From for &str { - fn from(x: ProfileIdentity) -> Self { - //x.0.to_string().as_str() - let s: String = x.0.to_string(); - s.as_str() - } -} - #[derive(Debug)] /// Contact ID used to refer to contacts in Cwtch pub struct ContactIdentity(String); @@ -91,11 +83,9 @@ impl From<&str> for ServerIdentity { } } -impl From for &str { +impl From for String { fn from(x: ServerIdentity) -> Self { - //x.0.to_string().borrow() - let s: String = x.0.to_string(); - s.as_str() + x.into() } } @@ -109,6 +99,12 @@ impl From for FileKey { } } +impl From for String { + fn from(x: FileKey) -> Self { + x.into() + } +} + #[derive(Debug)] /// Enum for type of notification a UI/client should emit for a new message pub enum MessageNotification { diff --git a/src/lib.rs b/src/lib.rs index c2a225c..52dd6f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ #![doc(html_root_url = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs")] #![deny(missing_docs)] -use crate::event::{ConversationID, Event, ProfileIdentity, ServerIdentity}; +use crate::event::{ConversationID, Event, FileKey, ProfileIdentity, ServerIdentity}; mod bindings_go; mod cwtchlib_go; @@ -81,14 +81,14 @@ pub trait CwtchLib { conversation_id: ConversationID, file_path: &str, manifest_path: &str, - file_key: &str, + file_key: FileKey, ); /// Query the status of a download - fn check_download_status(&self, profile: ProfileIdentity, file_key: &str); + fn check_download_status(&self, profile: ProfileIdentity, file_key: FileKey); /// Verufy a download is done, and if not, resume it - fn verify_or_resume_download(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_key: &str); + fn verify_or_resume_download(&self, profile: ProfileIdentity, conversation_id: ConversationID, file_key: FileKey); /// Ask the ACN inside the Cwtch app to restart the tor connection fn reset_tor(&self);