diff --git a/deltachat-ffi/Cargo.toml b/deltachat-ffi/Cargo.toml index 5ecee8872..e5ba6f341 100644 --- a/deltachat-ffi/Cargo.toml +++ b/deltachat-ffi/Cargo.toml @@ -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"] diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index f78db33c8..eb0ba1ff7 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -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,