mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
Simplify dc_initiate_key_transfer()
This commit is contained in:
committed by
Friedel Ziegelmayer
parent
39e9cfd908
commit
9e50e77031
165
src/dc_imex.rs
165
src/dc_imex.rs
@@ -98,101 +98,86 @@ pub unsafe fn dc_imex_has_backup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
||||||
let current_block: u64;
|
|
||||||
let mut success: libc::c_int = 0i32;
|
|
||||||
let mut setup_code: *mut libc::c_char;
|
|
||||||
let mut setup_file_content: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut setup_file_content: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
let mut setup_file_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut setup_file_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
let chat_id: uint32_t;
|
|
||||||
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
||||||
let msg_id: uint32_t;
|
if dc_alloc_ongoing(context) == 0 {
|
||||||
if 0 == dc_alloc_ongoing(context) {
|
return std::ptr::null_mut();
|
||||||
return 0 as *mut libc::c_char;
|
|
||||||
}
|
}
|
||||||
setup_code = to_cstring(dc_create_setup_code(context));
|
let setup_code = CString::new(dc_create_setup_code(context)).unwrap();
|
||||||
if !setup_code.is_null() {
|
/* 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
|
.running_state
|
||||||
.running_state
|
.clone()
|
||||||
.clone()
|
.read()
|
||||||
.read()
|
.unwrap()
|
||||||
.unwrap()
|
.shall_stop_ongoing
|
||||||
.shall_stop_ongoing
|
{
|
||||||
{
|
setup_file_content = dc_render_setup_file(context, setup_code.as_ptr());
|
||||||
setup_file_content = dc_render_setup_file(context, setup_code);
|
if !setup_file_content.is_null() {
|
||||||
if !setup_file_content.is_null() {
|
/* encrypting may also take a while ... */
|
||||||
/* encrypting may also take a while ... */
|
if !context
|
||||||
if !context
|
.running_state
|
||||||
.running_state
|
.clone()
|
||||||
.clone()
|
.read()
|
||||||
.read()
|
.unwrap()
|
||||||
.unwrap()
|
.shall_stop_ongoing
|
||||||
.shall_stop_ongoing
|
{
|
||||||
{
|
setup_file_name = dc_get_fine_pathNfilename(
|
||||||
setup_file_name = dc_get_fine_pathNfilename(
|
context,
|
||||||
|
b"$BLOBDIR\x00" as *const u8 as *const libc::c_char,
|
||||||
|
b"autocrypt-setup-message.html\x00" as *const u8 as *const libc::c_char,
|
||||||
|
);
|
||||||
|
if !(setup_file_name.is_null()
|
||||||
|
|| 0 == dc_write_file(
|
||||||
context,
|
context,
|
||||||
b"$BLOBDIR\x00" as *const u8 as *const libc::c_char,
|
setup_file_name,
|
||||||
b"autocrypt-setup-message.html\x00" as *const u8 as *const libc::c_char,
|
setup_file_content as *const libc::c_void,
|
||||||
);
|
strlen(setup_file_content),
|
||||||
if !(setup_file_name.is_null()
|
))
|
||||||
|| 0 == dc_write_file(
|
{
|
||||||
context,
|
let chat_id = dc_create_chat_by_contact_id(context, 1i32 as uint32_t);
|
||||||
setup_file_name,
|
if !(chat_id == 0i32 as libc::c_uint) {
|
||||||
setup_file_content as *const libc::c_void,
|
msg = dc_msg_new_untyped(context);
|
||||||
strlen(setup_file_content),
|
(*msg).type_0 = DC_MSG_FILE;
|
||||||
))
|
(*msg).param.set(Param::File, as_str(setup_file_name));
|
||||||
{
|
|
||||||
chat_id = dc_create_chat_by_contact_id(context, 1i32 as uint32_t);
|
|
||||||
if !(chat_id == 0i32 as libc::c_uint) {
|
|
||||||
msg = dc_msg_new_untyped(context);
|
|
||||||
(*msg).type_0 = DC_MSG_FILE;
|
|
||||||
(*msg).param.set(Param::File, as_str(setup_file_name));
|
|
||||||
|
|
||||||
(*msg)
|
(*msg)
|
||||||
.param
|
.param
|
||||||
.set(Param::MimeType, "application/autocrypt-setup");
|
.set(Param::MimeType, "application/autocrypt-setup");
|
||||||
(*msg).param.set_int(Param::Cmd, 6);
|
(*msg).param.set_int(Param::Cmd, 6);
|
||||||
(*msg).param.set_int(Param::ForcePlaintext, 2);
|
(*msg).param.set_int(Param::ForcePlaintext, 2);
|
||||||
|
|
||||||
if !context
|
if !context
|
||||||
.running_state
|
.running_state
|
||||||
.clone()
|
.clone()
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.shall_stop_ongoing
|
.shall_stop_ongoing
|
||||||
{
|
{
|
||||||
msg_id = dc_send_msg(context, chat_id, msg);
|
let msg_id = dc_send_msg(context, chat_id, msg);
|
||||||
if !(msg_id == 0i32 as libc::c_uint) {
|
if msg_id != 0 {
|
||||||
|
dc_msg_unref(msg);
|
||||||
|
msg = 0 as *mut dc_msg_t;
|
||||||
|
info!(context, 0, "Wait for setup message being sent ...",);
|
||||||
|
loop {
|
||||||
|
if context
|
||||||
|
.running_state
|
||||||
|
.clone()
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.shall_stop_ongoing
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
|
msg = dc_get_msg(context, msg_id);
|
||||||
|
if 0 != dc_msg_is_sent(msg) {
|
||||||
|
info!(context, 0, "... setup message sent.",);
|
||||||
|
break;
|
||||||
|
}
|
||||||
dc_msg_unref(msg);
|
dc_msg_unref(msg);
|
||||||
msg = 0 as *mut dc_msg_t;
|
msg = 0 as *mut dc_msg_t
|
||||||
info!(context, 0, "Wait for setup message being sent ...",);
|
|
||||||
loop {
|
|
||||||
if context
|
|
||||||
.running_state
|
|
||||||
.clone()
|
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.shall_stop_ongoing
|
|
||||||
{
|
|
||||||
current_block = 6116957410927263949;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
||||||
msg = dc_get_msg(context, msg_id);
|
|
||||||
if 0 != dc_msg_is_sent(msg) {
|
|
||||||
current_block = 6450636197030046351;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
msg = 0 as *mut dc_msg_t
|
|
||||||
}
|
|
||||||
match current_block {
|
|
||||||
6116957410927263949 => {}
|
|
||||||
_ => {
|
|
||||||
info!(context, 0, "... setup message sent.",);
|
|
||||||
success = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,16 +186,12 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 == success {
|
|
||||||
free(setup_code as *mut libc::c_void);
|
|
||||||
setup_code = 0 as *mut libc::c_char
|
|
||||||
}
|
|
||||||
free(setup_file_name as *mut libc::c_void);
|
free(setup_file_name as *mut libc::c_void);
|
||||||
free(setup_file_content as *mut libc::c_void);
|
free(setup_file_content as *mut libc::c_void);
|
||||||
dc_msg_unref(msg);
|
dc_msg_unref(msg);
|
||||||
dc_free_ongoing(context);
|
dc_free_ongoing(context);
|
||||||
|
|
||||||
setup_code
|
dc_strdup(setup_code.as_ptr())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe extern "C" fn dc_render_setup_file(
|
pub unsafe extern "C" fn dc_render_setup_file(
|
||||||
|
|||||||
Reference in New Issue
Block a user