mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
Return Result from dc_initiate_key_transfer
This commit is contained in:
committed by
holger krekel
parent
6c9c21c135
commit
f346a052c1
@@ -1563,7 +1563,13 @@ pub unsafe extern "C" fn dc_initiate_key_transfer(context: *mut dc_context_t) ->
|
|||||||
}
|
}
|
||||||
let ffi_context = &*context;
|
let ffi_context = &*context;
|
||||||
ffi_context
|
ffi_context
|
||||||
.with_inner(|ctx| dc_imex::dc_initiate_key_transfer(ctx))
|
.with_inner(|ctx| match dc_imex::dc_initiate_key_transfer(ctx) {
|
||||||
|
Ok(res) => res.strdup(),
|
||||||
|
Err(err) => {
|
||||||
|
error!(ctx, "dc_initiate_key_transfer(): {}", err);
|
||||||
|
ptr::null_mut()
|
||||||
|
}
|
||||||
|
})
|
||||||
.unwrap_or_else(|_| ptr::null_mut())
|
.unwrap_or_else(|_| ptr::null_mut())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -414,18 +414,13 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
============================================="
|
============================================="
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
"initiate-key-transfer" => {
|
"initiate-key-transfer" => match dc_initiate_key_transfer(context) {
|
||||||
let setup_code = dc_initiate_key_transfer(context);
|
Ok(setup_code) => println!(
|
||||||
if !setup_code.is_null() {
|
"Setup code for the transferred setup message: {}",
|
||||||
println!(
|
setup_code,
|
||||||
"Setup code for the transferred setup message: {}",
|
),
|
||||||
as_str(setup_code),
|
Err(err) => bail!("Failed to generate setup code: {}", err),
|
||||||
);
|
},
|
||||||
free(setup_code as *mut libc::c_void);
|
|
||||||
} else {
|
|
||||||
bail!("Failed to generate setup code");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
"get-setupcodebegin" => {
|
"get-setupcodebegin" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
||||||
let msg_id: u32 = arg1.parse()?;
|
let msg_id: u32 = arg1.parse()?;
|
||||||
|
|||||||
@@ -75,11 +75,9 @@ pub fn dc_imex_has_backup(context: &Context, dir_name: impl AsRef<Path>) -> Resu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
pub fn dc_initiate_key_transfer(context: &Context) -> Result<String> {
|
||||||
let mut msg: Message;
|
let mut msg: Message;
|
||||||
if !dc_alloc_ongoing(context) {
|
ensure!(dc_alloc_ongoing(context), "could not allocate ongoing");
|
||||||
return std::ptr::null_mut();
|
|
||||||
}
|
|
||||||
let setup_code = dc_create_setup_code(context);
|
let setup_code = dc_create_setup_code(context);
|
||||||
/* this may require a keypair to be created. this may take a second ... */
|
/* this may require a keypair to be created. this may take a second ... */
|
||||||
if !context
|
if !context
|
||||||
@@ -149,7 +147,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
}
|
}
|
||||||
dc_free_ongoing(context);
|
dc_free_ongoing(context);
|
||||||
|
|
||||||
setup_code.strdup()
|
Ok(setup_code)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Renders HTML body of a setup file message.
|
/// Renders HTML body of a setup file message.
|
||||||
|
|||||||
Reference in New Issue
Block a user