mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 13:36:30 +03:00
add dc_receive_backup ffi (#3504)
* add dc_receive_backup ffi * fix compile issues * make clippy happy Co-authored-by: dignifiedquire <me@dignifiedquire.com>
This commit is contained in:
@@ -27,6 +27,7 @@ thiserror = "1"
|
||||
rand = "0.7"
|
||||
once_cell = "1.16.0"
|
||||
iroh-share = { git = "https://github.com/n0-computer/iroh", branch = "iroh-share" }
|
||||
multibase = "0.9"
|
||||
|
||||
[features]
|
||||
default = ["vendored"]
|
||||
|
||||
@@ -2223,7 +2223,10 @@ pub unsafe extern "C" fn dc_send_backup(
|
||||
imex::send_backup(ctx, folder.as_ref(), passphrase)
|
||||
.await
|
||||
.map(|(sender, transfer)| {
|
||||
Box::into_raw(Box::new(dc_backup_sender { sender, transfer }))
|
||||
Box::into_raw(Box::new(dc_backup_sender {
|
||||
_sender: sender,
|
||||
transfer,
|
||||
}))
|
||||
})
|
||||
.log_err(ctx, "send_backup failed")
|
||||
.unwrap_or_else(|_| ptr::null_mut())
|
||||
@@ -2235,7 +2238,7 @@ pub unsafe extern "C" fn dc_send_backup(
|
||||
}
|
||||
|
||||
pub struct dc_backup_sender {
|
||||
sender: iroh_share::Sender,
|
||||
_sender: iroh_share::Sender,
|
||||
transfer: iroh_share::SenderTransfer,
|
||||
}
|
||||
|
||||
@@ -2265,6 +2268,30 @@ pub unsafe extern "C" fn dc_backup_sender_unref(bs: *mut dc_backup_sender) {
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_receive_backup(
|
||||
ctx: *mut dc_context_t,
|
||||
ticket: *const libc::c_char,
|
||||
passphrase: *const libc::c_char,
|
||||
) {
|
||||
if ctx.is_null() || ticket.is_null() {
|
||||
eprintln!("ignoring careless call to dc_receive_backup");
|
||||
return;
|
||||
}
|
||||
let ctx = &*ctx;
|
||||
let ticket = multibase::decode(to_string_lossy(ticket))
|
||||
.map(|(_, ticket)| ticket)
|
||||
.unwrap_or_default();
|
||||
|
||||
let passphrase = to_opt_string_lossy(passphrase);
|
||||
|
||||
spawn(async move {
|
||||
imex::receive_backup(ctx, ticket, passphrase)
|
||||
.await
|
||||
.log_err(ctx, "IMEX failed")
|
||||
});
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_imex_has_backup(
|
||||
context: *mut dc_context_t,
|
||||
|
||||
Reference in New Issue
Block a user