mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
Merge branch 'master' into flub-nowarn
This commit is contained in:
179
src/dc_imex.rs
179
src/dc_imex.rs
@@ -34,9 +34,9 @@ pub unsafe fn dc_imex(
|
||||
param2: *const libc::c_char,
|
||||
) {
|
||||
let param: *mut dc_param_t = dc_param_new();
|
||||
dc_param_set_int(param, 'S' as i32, what);
|
||||
dc_param_set(param, 'E' as i32, param1);
|
||||
dc_param_set(param, 'F' as i32, param2);
|
||||
dc_param_set_int(param, DC_PARAM_CMD as i32, what);
|
||||
dc_param_set(param, DC_PARAM_CMD_ARG as i32, param1);
|
||||
dc_param_set(param, DC_PARAM_CMD_ARG2 as i32, param2);
|
||||
dc_job_kill_action(context, 910i32);
|
||||
dc_job_add(context, 910i32, 0i32, (*param).packed, 0i32);
|
||||
dc_param_unref(param);
|
||||
@@ -143,15 +143,15 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
||||
if !(chat_id == 0i32 as libc::c_uint) {
|
||||
msg = dc_msg_new_untyped(context);
|
||||
(*msg).type_0 = 60i32;
|
||||
dc_param_set((*msg).param, 'f' as i32, setup_file_name);
|
||||
dc_param_set((*msg).param, DC_PARAM_FILE as i32, setup_file_name);
|
||||
dc_param_set(
|
||||
(*msg).param,
|
||||
'm' as i32,
|
||||
DC_PARAM_MIMETYPE as i32,
|
||||
b"application/autocrypt-setup\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
dc_param_set_int((*msg).param, 'S' as i32, 6i32);
|
||||
dc_param_set_int((*msg).param, 'u' as i32, 2i32);
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 6);
|
||||
dc_param_set_int((*msg).param, DC_PARAM_FORCE_PLAINTEXT as i32, 2);
|
||||
if !context
|
||||
.running_state
|
||||
.clone()
|
||||
@@ -309,7 +309,7 @@ pub unsafe fn dc_create_setup_code(_context: &Context) -> *mut libc::c_char {
|
||||
);
|
||||
}
|
||||
|
||||
strdup(to_cstring(ret).as_ptr())
|
||||
to_cstring(ret)
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
@@ -539,7 +539,7 @@ pub unsafe fn dc_normalize_setup_code(
|
||||
p1 = p1.offset(1);
|
||||
}
|
||||
|
||||
strdup(to_cstring(out).as_ptr())
|
||||
to_cstring(out)
|
||||
}
|
||||
|
||||
pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) {
|
||||
@@ -551,9 +551,17 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
let mut param2: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
if !(0 == dc_alloc_ongoing(context)) {
|
||||
ongoing_allocated_here = 1i32;
|
||||
what = dc_param_get_int((*job).param, 'S' as i32, 0i32);
|
||||
param1 = dc_param_get((*job).param, 'E' as i32, 0 as *const libc::c_char);
|
||||
param2 = dc_param_get((*job).param, 'F' as i32, 0 as *const libc::c_char);
|
||||
what = dc_param_get_int((*job).param, DC_PARAM_CMD as i32, 0);
|
||||
param1 = dc_param_get(
|
||||
(*job).param,
|
||||
DC_PARAM_CMD_ARG as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
param2 = dc_param_get(
|
||||
(*job).param,
|
||||
DC_PARAM_CMD_ARG2 as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if param1.is_null() {
|
||||
error!(context, 0, "No Import/export dir/file given.",);
|
||||
} else {
|
||||
@@ -806,77 +814,75 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
||||
0, "***IMPORT-in-progress: total_files_cnt={:?}", total_files_cnt,
|
||||
);
|
||||
|
||||
context
|
||||
.sql
|
||||
.query_map(
|
||||
"SELECT file_name, file_content FROM backup_blobs ORDER BY id;",
|
||||
params![],
|
||||
|row| {
|
||||
let name: String = row.get(0)?;
|
||||
let blob: Vec<u8> = row.get(1)?;
|
||||
let res = context.sql.query_map(
|
||||
"SELECT file_name, file_content FROM backup_blobs ORDER BY id;",
|
||||
params![],
|
||||
|row| {
|
||||
let name: String = row.get(0)?;
|
||||
let blob: Vec<u8> = row.get(1)?;
|
||||
|
||||
Ok((name, blob))
|
||||
},
|
||||
|files| {
|
||||
let mut loop_success = true;
|
||||
let mut processed_files_cnt = 0;
|
||||
Ok((name, blob))
|
||||
},
|
||||
|files| {
|
||||
let mut loop_success = true;
|
||||
let mut processed_files_cnt = 0;
|
||||
|
||||
for file in files {
|
||||
if file.is_err() {
|
||||
loop_success = false;
|
||||
break;
|
||||
}
|
||||
let (file_name, file_blob) = file.unwrap();
|
||||
for file in files {
|
||||
let (file_name, file_blob) = file?;
|
||||
|
||||
if context
|
||||
.running_state
|
||||
.clone()
|
||||
.read()
|
||||
.unwrap()
|
||||
.shall_stop_ongoing
|
||||
{
|
||||
loop_success = false;
|
||||
break;
|
||||
}
|
||||
processed_files_cnt += 1;
|
||||
let mut permille = processed_files_cnt * 1000 / total_files_cnt;
|
||||
if permille < 10 {
|
||||
permille = 10
|
||||
}
|
||||
if permille > 990 {
|
||||
permille = 990
|
||||
}
|
||||
context.call_cb(Event::IMEX_PROGRESS, permille as uintptr_t, 0);
|
||||
if file_blob.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let pathNfilename = format!("{}/{}", as_str(context.get_blobdir()), file_name);
|
||||
if dc_write_file_safe(context, &pathNfilename, &file_blob) {
|
||||
continue;
|
||||
}
|
||||
|
||||
error!(
|
||||
context,
|
||||
0,
|
||||
"Storage full? Cannot write file {} with {} bytes.",
|
||||
&pathNfilename,
|
||||
file_blob.len(),
|
||||
);
|
||||
// otherwise the user may believe the stuff is imported correctly, but there are files missing ...
|
||||
if context
|
||||
.running_state
|
||||
.clone()
|
||||
.read()
|
||||
.unwrap()
|
||||
.shall_stop_ongoing
|
||||
{
|
||||
loop_success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if !loop_success {
|
||||
return Err(format_err!("fail").into());
|
||||
processed_files_cnt += 1;
|
||||
let mut permille = processed_files_cnt * 1000 / total_files_cnt;
|
||||
if permille < 10 {
|
||||
permille = 10
|
||||
}
|
||||
sql::execute(context, &context.sql, "DROP TABLE backup_blobs;", params![])?;
|
||||
sql::try_execute(context, &context.sql, "VACUUM;").ok();
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.is_ok() as libc::c_int
|
||||
if permille > 990 {
|
||||
permille = 990
|
||||
}
|
||||
context.call_cb(Event::IMEX_PROGRESS, permille as uintptr_t, 0);
|
||||
if file_blob.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let pathNfilename = format!("{}/{}", as_str(context.get_blobdir()), file_name);
|
||||
if dc_write_file_safe(context, &pathNfilename, &file_blob) {
|
||||
continue;
|
||||
}
|
||||
error!(
|
||||
context,
|
||||
0,
|
||||
"Storage full? Cannot write file {} with {} bytes.",
|
||||
&pathNfilename,
|
||||
file_blob.len(),
|
||||
);
|
||||
// otherwise the user may believe the stuff is imported correctly, but there are files missing ...
|
||||
loop_success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if !loop_success {
|
||||
return Err(format_err!("fail").into());
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
|
||||
res.and_then(|_| {
|
||||
/// only delete backup_blobs if all files were successfully extracted
|
||||
sql::execute(context, &context.sql, "DROP TABLE backup_blobs;", params![])?;
|
||||
sql::try_execute(context, &context.sql, "VACUUM;").ok();
|
||||
Ok(())
|
||||
})
|
||||
.is_ok() as libc::c_int
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -897,7 +903,8 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
.format("delta-chat-%Y-%m-%d.bak")
|
||||
.to_string();
|
||||
let buffer = to_cstring(res);
|
||||
let dest_pathNfilename = dc_get_fine_pathNfilename(context, dir, buffer.as_ptr());
|
||||
let dest_pathNfilename = dc_get_fine_pathNfilename(context, dir, buffer);
|
||||
free(buffer as *mut _);
|
||||
if dest_pathNfilename.is_null() {
|
||||
error!(context, 0, "Cannot get backup file name.",);
|
||||
|
||||
@@ -973,7 +980,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
|
||||
sql.prepare(
|
||||
"INSERT INTO backup_blobs (file_name, file_content) VALUES (?, ?);",
|
||||
move |mut stmt| {
|
||||
move |mut stmt, _| {
|
||||
let mut processed_files_cnt = 0;
|
||||
for entry in dir_handle {
|
||||
if entry.is_err() {
|
||||
@@ -1096,6 +1103,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
let mut imported_cnt: libc::c_int = 0;
|
||||
let mut suffix: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut path_plus_name: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut name_c: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut set_default: libc::c_int;
|
||||
let mut buf: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut buf_bytes: size_t = 0 as size_t;
|
||||
@@ -1123,8 +1131,9 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
let entry = entry.unwrap();
|
||||
free(suffix as *mut libc::c_void);
|
||||
let name_f = entry.file_name();
|
||||
let name_c = to_cstring(name_f.to_string_lossy());
|
||||
suffix = dc_get_filesuffix_lc(name_c.as_ptr());
|
||||
free(name_c as *mut libc::c_void);
|
||||
name_c = to_cstring(name_f.to_string_lossy());
|
||||
suffix = dc_get_filesuffix_lc(name_c);
|
||||
if suffix.is_null()
|
||||
|| strcmp(suffix, b"asc\x00" as *const u8 as *const libc::c_char) != 0
|
||||
{
|
||||
@@ -1134,7 +1143,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
path_plus_name = dc_mprintf(
|
||||
b"%s/%s\x00" as *const u8 as *const libc::c_char,
|
||||
dir_name,
|
||||
name_c.as_ptr(),
|
||||
name_c,
|
||||
);
|
||||
info!(context, 0, "Checking: {}", as_str(path_plus_name));
|
||||
free(buf as *mut libc::c_void);
|
||||
@@ -1172,12 +1181,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
}
|
||||
}
|
||||
set_default = 1;
|
||||
if !strstr(
|
||||
name_c.as_ptr(),
|
||||
b"legacy\x00" as *const u8 as *const libc::c_char,
|
||||
)
|
||||
.is_null()
|
||||
{
|
||||
if !strstr(name_c, b"legacy\x00" as *const u8 as *const libc::c_char).is_null() {
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
@@ -1202,6 +1206,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
}
|
||||
}
|
||||
|
||||
free(name_c as *mut libc::c_void);
|
||||
free(suffix as *mut libc::c_void);
|
||||
free(path_plus_name as *mut libc::c_void);
|
||||
free(buf as *mut libc::c_void);
|
||||
|
||||
Reference in New Issue
Block a user