diff --git a/build.rs b/build.rs
index 0267d14..6e52ea4 100644
--- a/build.rs
+++ b/build.rs
@@ -15,9 +15,9 @@ fn main() {
println!("cargo:rerun-if-changed=libCwtch.h");
let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so");
- // https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.5.4
+ // https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.7.0
Command::new("wget")
- .arg("https://git.openprivacy.ca/attachments/dd3c6b41-98e4-4e7b-81af-d21893bfe389")
+ .arg("https://git.openprivacy.ca/attachments/390d383b-ab02-489b-b5c9-e62267d8b3fd")
.arg("-O")
.arg(lib_cwtch_path)
.output()
@@ -29,5 +29,5 @@ fn main() {
io::copy(&mut file, &mut hasher).expect("failed to copy file into hasher");
let hash_bytes = hasher.finalize();
- assert_eq!(hash_bytes[..], hex!("776a26076dfad3370d1b2edec9ad954187584f54483ec201163be0dc356c10b0fe74168e8e95f2116f458e5676e1fb07fbd0357cab1e4389ac762fe03bd5ef67")[..]);
+ assert_eq!(hash_bytes[..], hex!("271c281bad59696fc4ea5e559b5d3fe5c1949384c26dd891dde91b0af0a012e30bdbc3b16781ec5de795d2945e2f42415a8985451b49394b3c85c412ab4769d3")[..]);
}
diff --git a/libCwtch.h b/libCwtch.h
index de34689..0730fb6 100644
--- a/libCwtch.h
+++ b/libCwtch.h
@@ -61,6 +61,7 @@ extern "C" {
#endif
extern int c_StartCwtch(char* dir_c, int len, char* tor_c, int torLen);
+extern int c_Started();
extern void c_ReconnectCwtchForeground();
// A generic method for Rebroadcasting App Events from a UI
@@ -86,11 +87,14 @@ extern char* c_GetMessageByID(char* profile_ptr, int profile_len, int conversati
// the pointer returned from this function **must** be freed by calling c_Free
extern char* c_GetMessagesByContentHash(char* profile_ptr, int profile_len, int conversation_id, char* contenthash_ptr, int contenthash_len);
+// the pointer returned from this function **must** be Freed by c_Free
+extern char* c_GetMessages(char* profile_ptr, int profile_len, int conversation_id, int message_index, int count);
+
// Dangerous function. Should only be used as documented in `MEMORY.md`
extern void c_FreePointer(char* ptr);
-extern void c_SendMessage(char* profile_ptr, int profile_len, int conversation_id, char* msg_ptr, int msg_len);
-extern void c_SendInvitation(char* profile_ptr, int profile_len, int conversation_id, int target_id);
-extern void c_ShareFile(char* profile_ptr, int profile_len, int conversation_id, char* filepath_ptr, int filepath_len);
+extern char* c_SendMessage(char* profile_ptr, int profile_len, int conversation_id, char* msg_ptr, int msg_len);
+extern char* c_SendInvitation(char* profile_ptr, int profile_len, int conversation_id, int target_id);
+extern char* c_ShareFile(char* profile_ptr, int profile_len, int conversation_id, char* filepath_ptr, int filepath_len);
extern void c_DownloadFile(char* profile_ptr, int profile_len, int conversation_id, char* filepath_ptr, int filepath_len, char* manifestpath_ptr, int manifestpath_len, char* filekey_ptr, int filekey_len);
extern void c_CheckDownloadStatus(char* profilePtr, int profileLen, char* fileKeyPtr, int fileKeyLen);
extern void c_VerifyOrResumeDownload(char* profile_ptr, int profile_len, int conversation_id, char* filekey_ptr, int filekey_len);
@@ -101,9 +105,13 @@ extern void c_ArchiveConversation(char* profile_ptr, int profile_len, int conver
extern void c_DeleteContact(char* profile_ptr, int profile_len, int conversation_id);
extern void c_ImportBundle(char* profile_ptr, int profile_len, char* bundle_ptr, int bundle_len);
extern void c_SetProfileAttribute(char* profile_ptr, int profile_len, char* key_ptr, int key_len, char* val_ptr, int val_len);
+extern char* c_GetProfileAttribute(char* profile_ptr, int profile_len, char* key_ptr, int key_len);
extern void c_SetConversationAttribute(char* profile_ptr, int profile_len, int conversation_id, char* key_ptr, int key_len, char* val_ptr, int val_len);
+extern char* c_GetConversationAttribute(char* profile_ptr, int profile_len, int conversation_id, char* key_ptr, int key_len);
extern void c_SetMessageAttribute(char* profile_ptr, int profile_len, int conversation_id, int channel_id, int message_id, char* key_ptr, int key_len, char* val_ptr, int val_len);
extern void c_ChangePassword(char* profile_ptr, int profile_len, char* oldpassword_ptr, int oldpassword_len, char* newpassword_ptr, int newpassword_len, char* newpassword_again_ptr, int newpassword_again_len);
+extern void c_ExportProfile(char* profile_ptr, int profile_len, char* file_ptr, int file_len);
+extern char* c_ImportProfile(char* file_ptr, int file_len, char* passwordPtr, int passwordLen);
extern void c_ShutdownCwtch();
extern void c_LoadServers(char* passwordPtr, int passwordLen);
extern void c_CreateServer(char* passwordPtr, int passwordLen, char* descPtr, int descLen, char autostart);
diff --git a/src/bindings_go.rs b/src/bindings_go.rs
index ed1610d..2a36a1d 100644
--- a/src/bindings_go.rs
+++ b/src/bindings_go.rs
@@ -8,6 +8,7 @@ use std::ffi::CString;
use super::CwtchLib;
use crate::cwtchlib_go::bindings;
+use crate::{CwtchError, structs::*};
struct c_str_wrap {
raw: *mut i8,
@@ -80,8 +81,16 @@ macro_rules! c_bind {
pub struct CwtchLibGo {}
+// Some bindings are going to be wrapped so we can handle their returns and give most rust idiomatic returns (esp for json returning apis)
+// so we pre define the real binding here as a _helper function and in the impl for CwtchLib define the wrapper
+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);
+}
+
impl CwtchLib for CwtchLibGo {
c_bind!(start_cwtch(app_dir: &str, tor_path: &str;;) c_StartCwtch -> i32);
+ c_bind!(started(;;) c_Started -> i32);
c_bind!(send_app_event(event_json: &str;;) c_SendAppEvent);
c_bind!(send_profile_event(profile: &str, event_jason: &str;;) c_SendProfileEvent);
c_bind!(get_appbus_event(;;) c_GetAppBusEvent -> String);
@@ -90,12 +99,13 @@ impl CwtchLib for CwtchLibGo {
c_bind!(accept_conversation(profile: &str ; conversation_id: i32 ;) c_AcceptConversation);
c_bind!(block_contact(profile: &str ; conversation_id: i32; ) c_BlockContact);
c_bind!(unblock_contact(profile: &str ; conversation_id: i32; ) c_UnblockContact);
- c_bind!(get_message(profile: &str; conversation_id: i32, message_index: i32 ;) c_GetMessage -> String);
+ c_bind!(get_message(profile: &str; conversation_id: i32, message_index: i32 ;) c_GetMessage -> String);
c_bind!(get_message_by_id(profile: &str ; conversation_id: i32, message_id: i32 ;) c_GetMessageByID -> String);
c_bind!(get_message_by_content_hash(profile: &str ; conversation_id: i32 ; hash: &str) c_GetMessagesByContentHash -> String);
- c_bind!(send_message(profile: &str; conversation_id: i32; msg: &str) c_SendMessage);
- c_bind!(send_invitation(profile: &str; conversation_id: i32, target_id: i32;) c_SendInvitation);
- c_bind!(share_file(profile: &str; conversation_id: i32; file_path: &str) c_ShareFile);
+ c_bind!(get_messages(profile: &str; conversation_id: i32, message_index: i32, count: i32 ;) c_GetMessages -> String);
+ c_bind!(send_message(profile: &str; conversation_id: i32; msg: &str) c_SendMessage -> String);
+ c_bind!(send_invitation(profile: &str; conversation_id: i32, target_id: i32;) c_SendInvitation -> String);
+ c_bind!(share_file(profile: &str; conversation_id: i32; file_path: &str) c_ShareFile -> String);
c_bind!(download_file(profile: &str; conversation_id: i32; file_path: &str, manifest_path: &str, file_key: &str) c_DownloadFile);
c_bind!(check_download_status(profile: &str, file_key: &str;;) c_CheckDownloadStatus);
c_bind!(verify_or_resume_download(profile: &str; conversation_id: i32; file_key: &str) c_VerifyOrResumeDownload);
@@ -110,9 +120,33 @@ impl CwtchLib for CwtchLibGo {
c_bind!(delete_contact(profile: &str; conversation_id: i32;) c_DeleteContact);
c_bind!(import_bundle(profile: &str, bundle: &str;;) c_ImportBundle);
c_bind!(set_profile_attribute(profile: &str, key: &str, val: &str;;) c_SetProfileAttribute);
+ fn get_profile_attribute(&self, profile: &str, key: &str) -> Result