mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
Remove to_cstring() naming convention ambiguity
Add a trait for str.strdup() to replace to_cstring() which avoid the signature ambiguity with .to_string(). Also instruduce CString::yolo() as a shortcut to CString::new().unwrap() and use it whenever the variable does can be deallocated by going out of scope. This is less error prone. Use some Path.to_c_string() functions where possible.
This commit is contained in:
committed by
Floris Bruynooghe
parent
e7428887d0
commit
b6b0849bce
@@ -515,7 +515,7 @@ pub unsafe fn dc_normalize_setup_code(
|
||||
p1 = p1.offset(1);
|
||||
}
|
||||
|
||||
to_cstring(out)
|
||||
out.strdup()
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
@@ -524,16 +524,14 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
let mut success: libc::c_int = 0;
|
||||
let mut ongoing_allocated_here: libc::c_int = 0;
|
||||
let what: libc::c_int;
|
||||
let mut param1 = 0 as *mut libc::c_char;
|
||||
let mut param2 = 0 as *mut libc::c_char;
|
||||
|
||||
if !(0 == dc_alloc_ongoing(context)) {
|
||||
ongoing_allocated_here = 1;
|
||||
what = (*job).param.get_int(Param::Cmd).unwrap_or_default();
|
||||
param1 = to_cstring((*job).param.get(Param::Arg).unwrap_or_default());
|
||||
param2 = to_cstring((*job).param.get(Param::Arg2).unwrap_or_default());
|
||||
let param1 = CString::yolo((*job).param.get(Param::Arg).unwrap_or_default());
|
||||
let _param2 = CString::yolo((*job).param.get(Param::Arg2).unwrap_or_default());
|
||||
|
||||
if strlen(param1) == 0 {
|
||||
if strlen(param1.as_ptr()) == 0 {
|
||||
error!(context, 0, "No Import/export dir/file given.",);
|
||||
} else {
|
||||
info!(context, 0, "Import/export process started.",);
|
||||
@@ -551,7 +549,7 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
);
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
dc_create_folder(context, param1);
|
||||
dc_create_folder(context, param1.as_ptr());
|
||||
current_block = 4495394744059808450;
|
||||
}
|
||||
} else {
|
||||
@@ -564,28 +562,28 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
current_block = 10991094515395304355;
|
||||
match current_block {
|
||||
2973387206439775448 => {
|
||||
if 0 == import_backup(context, param1) {
|
||||
if 0 == import_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
11250025114629486028 => {
|
||||
if 0 == import_self_keys(context, param1) {
|
||||
if 0 == import_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
12669919903773909120 => {
|
||||
if 0 == export_backup(context, param1) {
|
||||
if 0 == export_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if 0 == export_self_keys(context, param1) {
|
||||
if 0 == export_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
@@ -604,28 +602,28 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
current_block = 11250025114629486028;
|
||||
match current_block {
|
||||
2973387206439775448 => {
|
||||
if 0 == import_backup(context, param1) {
|
||||
if 0 == import_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
11250025114629486028 => {
|
||||
if 0 == import_self_keys(context, param1) {
|
||||
if 0 == import_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
12669919903773909120 => {
|
||||
if 0 == export_backup(context, param1) {
|
||||
if 0 == export_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if 0 == export_self_keys(context, param1) {
|
||||
if 0 == export_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
@@ -644,28 +642,28 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
current_block = 12669919903773909120;
|
||||
match current_block {
|
||||
2973387206439775448 => {
|
||||
if 0 == import_backup(context, param1) {
|
||||
if 0 == import_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
11250025114629486028 => {
|
||||
if 0 == import_self_keys(context, param1) {
|
||||
if 0 == import_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
12669919903773909120 => {
|
||||
if 0 == export_backup(context, param1) {
|
||||
if 0 == export_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if 0 == export_self_keys(context, param1) {
|
||||
if 0 == export_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
@@ -684,28 +682,28 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
current_block = 2973387206439775448;
|
||||
match current_block {
|
||||
2973387206439775448 => {
|
||||
if 0 == import_backup(context, param1) {
|
||||
if 0 == import_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
11250025114629486028 => {
|
||||
if 0 == import_self_keys(context, param1) {
|
||||
if 0 == import_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
12669919903773909120 => {
|
||||
if 0 == export_backup(context, param1) {
|
||||
if 0 == export_backup(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if 0 == export_self_keys(context, param1) {
|
||||
if 0 == export_self_keys(context, param1.as_ptr()) {
|
||||
current_block = 3568988166330621280;
|
||||
} else {
|
||||
current_block = 1118134448028020070;
|
||||
@@ -727,8 +725,6 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
}
|
||||
}
|
||||
|
||||
free(param1 as *mut libc::c_void);
|
||||
free(param2 as *mut libc::c_void);
|
||||
if 0 != ongoing_allocated_here {
|
||||
dc_free_ongoing(context);
|
||||
}
|
||||
@@ -875,9 +871,8 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
let res = chrono::NaiveDateTime::from_timestamp(now as i64, 0)
|
||||
.format("delta-chat-%Y-%m-%d.bak")
|
||||
.to_string();
|
||||
let buffer = to_cstring(res);
|
||||
let dest_pathNfilename = dc_get_fine_pathNfilename(context, dir, buffer);
|
||||
free(buffer as *mut _);
|
||||
let buffer = CString::yolo(res);
|
||||
let dest_pathNfilename = dc_get_fine_pathNfilename(context, dir, buffer.as_ptr());
|
||||
if dest_pathNfilename.is_null() {
|
||||
error!(context, 0, "Cannot get backup file name.",);
|
||||
|
||||
@@ -1076,7 +1071,6 @@ 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;
|
||||
@@ -1104,9 +1098,8 @@ 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();
|
||||
free(name_c as *mut libc::c_void);
|
||||
name_c = to_cstring(name_f.to_string_lossy());
|
||||
suffix = dc_get_filesuffix_lc(name_c);
|
||||
let name_c = name_f.to_c_string().unwrap();
|
||||
suffix = dc_get_filesuffix_lc(name_c.as_ptr());
|
||||
if suffix.is_null()
|
||||
|| strcmp(suffix, b"asc\x00" as *const u8 as *const libc::c_char) != 0
|
||||
{
|
||||
@@ -1116,7 +1109,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,
|
||||
name_c.as_ptr(),
|
||||
);
|
||||
info!(context, 0, "Checking: {}", as_str(path_plus_name));
|
||||
free(buf as *mut libc::c_void);
|
||||
@@ -1154,7 +1147,12 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
|
||||
}
|
||||
}
|
||||
set_default = 1;
|
||||
if !strstr(name_c, b"legacy\x00" as *const u8 as *const libc::c_char).is_null() {
|
||||
if !strstr(
|
||||
name_c.as_ptr(),
|
||||
b"legacy\x00" as *const u8 as *const libc::c_char,
|
||||
)
|
||||
.is_null()
|
||||
{
|
||||
info!(
|
||||
context,
|
||||
0,
|
||||
@@ -1179,7 +1177,6 @@ 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