1#![doc = include_str!( "../README.md" )]
2#![doc(html_logo_url = "https://git.openprivacy.ca/cwtch.im/cwtch-ui/media/branch/trunk/cwtch.png")]
3#![doc(html_root_url = "https://git.openprivacy.ca/cwtch.im/libcwtch-rs")]
4#![deny(missing_docs)]
5
6use crate::event::{ConversationID, Event, FileKey, ProfileIdentity, ServerIdentity};
7use crate::structs::{ACL, MessageWrapper, Settings, SharedFile};
8
9mod bindings_go;
10mod cwtchlib_go;
11
12pub mod structs;
14pub mod event;
16
17pub type CwtchError = String;
19
20pub trait CwtchLib {
22 fn start_cwtch(&self, app_dir: &str, tor_path: &str) -> i32;
24
25 fn started(&self) -> i32;
27
28 fn reconnect_cwtch_foreground(&self);
31
32 fn update_settings(&self, settings: &Settings);
34
35 fn activate_peer_engine(&self, profile: &ProfileIdentity);
37
38 fn deactivate_peer_engine(&self, profile: &ProfileIdentity);
40
41 fn get_appbus_event(&self) -> Event;
43
44 fn configure_connections(&self, profile: &ProfileIdentity, listen: bool, peers: bool, servers: bool);
46
47 fn create_profile(&self, nick: &str, pass: &str, autostart: bool);
49
50 fn load_profiles(&self, pass: &str);
52
53 fn accept_conversation(&self, profile: &ProfileIdentity, conversation_id: ConversationID);
55
56 fn block_conversation(&self, profile: &ProfileIdentity, conversation_id: ConversationID);
58
59 fn unblock_conversation(&self, profile: &ProfileIdentity, conversation_id: ConversationID);
61
62 fn peer_with(&self, profile: &ProfileIdentity, new_peer_address: &str);
64
65 fn disconnect_from_peer(&self, profile: &ProfileIdentity, peer_id: &str);
67
68 fn search_conversations(&self, profile: &ProfileIdentity, pattern: &str) -> String;
70
71 fn get_conversation_access_control_list(&self, profile: &ProfileIdentity, conversation_id: ConversationID) -> Result<ACL, CwtchError>;
73
74 fn update_conversation_access_control_list(&self, profile: &ProfileIdentity, conversation_id: ConversationID, acl: ACL);
76
77 fn get_message_by_id(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message_id: i32) -> String;
79
80 fn get_message_by_content_hash(
82 &self,
83 profile: &ProfileIdentity,
84 conversation_id: ConversationID,
85 hash: &str,
86 ) -> String;
87
88 fn get_messages(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message_index: i32, count: u32) -> String;
90
91 fn send_message_raw(&self, profile: &ProfileIdentity, conversation_id: ConversationID, msg: &str) -> String;
93
94 fn send_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, message: &MessageWrapper) -> Result<String, CwtchError>;
96
97 fn send_invite_message(&self, profile: &ProfileIdentity, conversation_id: ConversationID, target_id: i32) -> String;
99
100 fn share_file(&self, profile: &ProfileIdentity, conversation_id: ConversationID, file_path: &str) -> String;
102
103 fn get_shared_files(&self, profile: &ProfileIdentity, conversaion_id: ConversationID) -> Vec<SharedFile>;
105
106 fn download_file_default_limit(
108 &self,
109 profile: &ProfileIdentity,
110 conversation_id: ConversationID,
111 file_path: &str,
112 manifest_path: &str,
113 file_key: &FileKey,
114 );
115
116 fn restart_fileshare(&self, profile: &ProfileIdentity, file_key: &FileKey);
118
119 fn stop_fileshare(&self, profile: &ProfileIdentity, file_key: &FileKey);
121
122 fn check_download_status(&self, profile: &ProfileIdentity, file_key: &FileKey);
124
125 fn verify_or_resume_download(&self, profile: &ProfileIdentity, conversation_id: ConversationID, file_key: &FileKey);
127
128 fn reset_tor(&self);
130
131 fn start_group(&self, profile: &ProfileIdentity, name: &str, server: &str);
133
134 fn queue_join_server(&self, profile: &ProfileIdentity, server: &ServerIdentity);
136
137 fn disconnect_from_server(&self, profile: &ProfileIdentity, server: &ServerIdentity);
139
140 fn publish_server_update(&self, profile: &ProfileIdentity);
142
143 fn get_server_info_list(&self, profile: &ProfileIdentity);
145
146 fn delete_server_info(&self, profile: &ProfileIdentity, server: &ServerIdentity);
148
149 fn delete_profile(&self, profile: &ProfileIdentity, pass: &str);
151
152 fn archive_conversation(&self, profile: &ProfileIdentity, conversation_id: ConversationID);
154
155 fn delete_conversation(&self, profile: &ProfileIdentity, conversation_id: ConversationID);
157
158 fn import_bundle(&self, profile: &ProfileIdentity, bundle: &str);
160
161 fn set_profile_attribute(&self, profile: &ProfileIdentity, key: &str, val: &str);
163
164 fn get_profile_attribute(&self, profile: &ProfileIdentity, key: &str) -> Result<Option<String>, CwtchError>;
166
167 fn set_conversation_attribute(&self, profile: &ProfileIdentity, conversation_id: ConversationID, key: &str, val: &str);
169
170 fn update_message_attribute(
172 &self,
173 profile: &ProfileIdentity,
174 conversation_id: ConversationID,
175 channel_id: i32,
176 message_id: i32,
177 attribute_key: &str,
178 attribute_value: &str,
179 );
180
181 fn get_conversation_attribute(&self, profile: &ProfileIdentity, conversation_id: ConversationID, key: &str) -> Result<Option<String>, CwtchError>;
183
184 fn change_password(&self, profile: &ProfileIdentity, old_pass: &str, new_pass: &str, new_pass_again: &str);
186
187 fn export_profile(&self, profile: &ProfileIdentity, filename: &str);
189
190 fn import_profile(&self, filename: &str, password: &str) -> String;
192
193 fn shutdown_cwtch(&self);
195
196 fn load_servers(&self, password: &str);
200
201 fn create_server(&self, password: &str, description: &str, autostart: bool);
203
204 fn delete_server(&self, server: ServerIdentity, current_password: &str);
206
207 fn launch_servers(&self);
209
210 fn launch_server(&self, server: ServerIdentity);
212
213 fn stop_server(&self, server: ServerIdentity);
215
216 fn stop_servers(&self);
218
219 fn destroy_servers(&self);
221
222 fn set_server_attribute(&self, server: ServerIdentity, key: &str, val: &str);
224
225 fn get_debug_info(&self) -> String;
227}
228
229pub fn new_cwtchlib_go() -> impl CwtchLib {
231 bindings_go::CwtchLibGo {}
232}