mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
- remove current_block logic from dc_chat.rs with the "OK_TO_CONTINUE"
pattern -- re-indentation will come after this commit with a pure application of "cargo fmt" - bring back comment from C code - make some path helpers return bool
This commit is contained in:
@@ -59,10 +59,10 @@ pub const DC_CHAT_ID_ALLDONE_HINT: usize = 7;
|
|||||||
/// larger chat IDs are "real" chats, their messages are "real" messages.
|
/// larger chat IDs are "real" chats, their messages are "real" messages.
|
||||||
pub const DC_CHAT_ID_LAST_SPECIAL: usize = 9;
|
pub const DC_CHAT_ID_LAST_SPECIAL: usize = 9;
|
||||||
|
|
||||||
pub const DC_CHAT_TYPE_UNDEFINED: usize = 0;
|
pub const DC_CHAT_TYPE_UNDEFINED: i32 = 0;
|
||||||
pub const DC_CHAT_TYPE_SINGLE: usize = 100;
|
pub const DC_CHAT_TYPE_SINGLE: i32 = 100;
|
||||||
pub const DC_CHAT_TYPE_GROUP: usize = 120;
|
pub const DC_CHAT_TYPE_GROUP: i32 = 120;
|
||||||
pub const DC_CHAT_TYPE_VERIFIED_GROUP: usize = 130;
|
pub const DC_CHAT_TYPE_VERIFIED_GROUP: i32 = 130;
|
||||||
|
|
||||||
pub const DC_MSG_ID_MARKER1: usize = 1;
|
pub const DC_MSG_ID_MARKER1: usize = 1;
|
||||||
pub const DC_MSG_ID_DAYMARKER: usize = 9;
|
pub const DC_MSG_ID_DAYMARKER: usize = 9;
|
||||||
|
|||||||
118
src/dc_chat.rs
118
src/dc_chat.rs
@@ -386,14 +386,12 @@ unsafe fn prepare_msg_common<'a>(
|
|||||||
chat_id: uint32_t,
|
chat_id: uint32_t,
|
||||||
mut msg: *mut dc_msg_t<'a>,
|
mut msg: *mut dc_msg_t<'a>,
|
||||||
) -> uint32_t {
|
) -> uint32_t {
|
||||||
let current_block: u64;
|
let mut OK_TO_CONTINUE = true;
|
||||||
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
let mut chat: *mut Chat = 0 as *mut Chat;
|
|
||||||
(*msg).id = 0i32 as uint32_t;
|
(*msg).id = 0i32 as uint32_t;
|
||||||
(*msg).context = context;
|
(*msg).context = context;
|
||||||
if (*msg).type_0 == DC_MSG_TEXT {
|
if (*msg).type_0 == DC_MSG_TEXT {
|
||||||
; /* the caller should check if the message text is empty */
|
/* the caller should check if the message text is empty */
|
||||||
current_block = 17281240262373992796;
|
|
||||||
} else if msgtype_has_file((*msg).type_0) {
|
} else if msgtype_has_file((*msg).type_0) {
|
||||||
pathNfilename = dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
pathNfilename = dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
||||||
if pathNfilename.is_null() {
|
if pathNfilename.is_null() {
|
||||||
@@ -403,17 +401,21 @@ unsafe fn prepare_msg_common<'a>(
|
|||||||
"Attachment missing for message of type #{}.",
|
"Attachment missing for message of type #{}.",
|
||||||
(*msg).type_0,
|
(*msg).type_0,
|
||||||
);
|
);
|
||||||
current_block = 2171833246886114521;
|
OK_TO_CONTINUE = false;
|
||||||
} else if (*msg).state == DC_STATE_OUT_PREPARING
|
} else if (*msg).state == DC_STATE_OUT_PREPARING
|
||||||
&& 0 == dc_is_blobdir_path(context, pathNfilename)
|
&& !dc_is_blobdir_path(context, pathNfilename)
|
||||||
{
|
{
|
||||||
error!(context, 0, "Files must be created in the blob-directory.",);
|
error!(context, 0, "Files must be created in the blob-directory.",);
|
||||||
current_block = 2171833246886114521;
|
OK_TO_CONTINUE = false;
|
||||||
} else if 0 == dc_make_rel_and_copy(context, &mut pathNfilename) {
|
} else if !dc_make_rel_and_copy(context, &mut pathNfilename) {
|
||||||
current_block = 2171833246886114521;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
} else {
|
||||||
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
||||||
if (*msg).type_0 == DC_MSG_FILE || (*msg).type_0 == DC_MSG_IMAGE {
|
if (*msg).type_0 == DC_MSG_FILE || (*msg).type_0 == DC_MSG_IMAGE {
|
||||||
|
/* Correct the type, take care not to correct already very special formats as GIF or VOICE.
|
||||||
|
Typical conversions:
|
||||||
|
- from FILE to AUDIO/VIDEO/IMAGE
|
||||||
|
- from FILE/IMAGE to GIF */
|
||||||
let mut better_type: libc::c_int = 0i32;
|
let mut better_type: libc::c_int = 0i32;
|
||||||
let mut better_mime: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut better_mime: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
dc_msg_guess_msgtype_from_suffix(pathNfilename, &mut better_type, &mut better_mime);
|
dc_msg_guess_msgtype_from_suffix(pathNfilename, &mut better_type, &mut better_mime);
|
||||||
@@ -439,7 +441,6 @@ unsafe fn prepare_msg_common<'a>(
|
|||||||
as_str(pathNfilename),
|
as_str(pathNfilename),
|
||||||
(*msg).type_0
|
(*msg).type_0
|
||||||
);
|
);
|
||||||
current_block = 17281240262373992796;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
@@ -448,25 +449,21 @@ unsafe fn prepare_msg_common<'a>(
|
|||||||
"Cannot send messages of type #{}.",
|
"Cannot send messages of type #{}.",
|
||||||
(*msg).type_0
|
(*msg).type_0
|
||||||
);
|
);
|
||||||
current_block = 2171833246886114521;
|
OK_TO_CONTINUE = false;
|
||||||
}
|
}
|
||||||
match current_block {
|
if OK_TO_CONTINUE {
|
||||||
17281240262373992796 => {
|
|
||||||
dc_unarchive_chat(context, chat_id);
|
dc_unarchive_chat(context, chat_id);
|
||||||
chat = dc_chat_new(context);
|
let chat = dc_chat_new(context);
|
||||||
if dc_chat_load_from_db(chat, chat_id) {
|
if dc_chat_load_from_db(chat, chat_id) {
|
||||||
if (*msg).state != DC_STATE_OUT_PREPARING {
|
if (*msg).state != DC_STATE_OUT_PREPARING {
|
||||||
(*msg).state = DC_STATE_OUT_PENDING
|
(*msg).state = DC_STATE_OUT_PENDING
|
||||||
}
|
}
|
||||||
(*msg).id =
|
(*msg).id = prepare_msg_raw(context, chat, msg, dc_create_smeared_timestamp(context));
|
||||||
prepare_msg_raw(context, chat, msg, dc_create_smeared_timestamp(context));
|
|
||||||
(*msg).chat_id = chat_id
|
(*msg).chat_id = chat_id
|
||||||
}
|
}
|
||||||
}
|
dc_chat_unref(chat);
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
/* potential error already logged */
|
/* potential error already logged */
|
||||||
dc_chat_unref(chat);
|
|
||||||
free(pathNfilename as *mut libc::c_void);
|
free(pathNfilename as *mut libc::c_void);
|
||||||
|
|
||||||
(*msg).id
|
(*msg).id
|
||||||
@@ -480,7 +477,7 @@ unsafe fn prepare_msg_raw(
|
|||||||
) -> uint32_t {
|
) -> uint32_t {
|
||||||
let mut do_guarantee_e2ee: libc::c_int;
|
let mut do_guarantee_e2ee: libc::c_int;
|
||||||
let e2ee_enabled: libc::c_int;
|
let e2ee_enabled: libc::c_int;
|
||||||
let current_block: u64;
|
let mut OK_TO_CONTINUE = true;
|
||||||
let mut parent_rfc724_mid = 0 as *mut libc::c_char;
|
let mut parent_rfc724_mid = 0 as *mut libc::c_char;
|
||||||
let mut parent_references = 0 as *mut libc::c_char;
|
let mut parent_references = 0 as *mut libc::c_char;
|
||||||
let mut parent_in_reply_to = 0 as *mut libc::c_char;
|
let mut parent_in_reply_to = 0 as *mut libc::c_char;
|
||||||
@@ -518,7 +515,7 @@ unsafe fn prepare_msg_raw(
|
|||||||
);
|
);
|
||||||
free(from_c as *mut _);
|
free(from_c as *mut _);
|
||||||
|
|
||||||
if (*chat).type_0 == 100 {
|
if (*chat).type_0 == DC_CHAT_TYPE_SINGLE {
|
||||||
if let Some(id) = context.sql.query_row_col(
|
if let Some(id) = context.sql.query_row_col(
|
||||||
context,
|
context,
|
||||||
"SELECT contact_id FROM chats_contacts WHERE chat_id=?;",
|
"SELECT contact_id FROM chats_contacts WHERE chat_id=?;",
|
||||||
@@ -526,7 +523,6 @@ unsafe fn prepare_msg_raw(
|
|||||||
0,
|
0,
|
||||||
) {
|
) {
|
||||||
to_id = id;
|
to_id = id;
|
||||||
current_block = 5689316957504528238;
|
|
||||||
} else {
|
} else {
|
||||||
error!(
|
error!(
|
||||||
context,
|
context,
|
||||||
@@ -534,10 +530,10 @@ unsafe fn prepare_msg_raw(
|
|||||||
"Cannot send message, contact for chat #{} not found.",
|
"Cannot send message, contact for chat #{} not found.",
|
||||||
(*chat).id,
|
(*chat).id,
|
||||||
);
|
);
|
||||||
current_block = 10477488590406205504;
|
OK_TO_CONTINUE = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (*chat).type_0 == 120 || (*chat).type_0 == 130 {
|
if (*chat).type_0 == DC_CHAT_TYPE_GROUP || (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP {
|
||||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1 {
|
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1 {
|
||||||
dc_param_set(
|
dc_param_set(
|
||||||
(*chat).param,
|
(*chat).param,
|
||||||
@@ -547,11 +543,8 @@ unsafe fn prepare_msg_raw(
|
|||||||
dc_chat_update_param(chat);
|
dc_chat_update_param(chat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
current_block = 5689316957504528238;
|
|
||||||
}
|
}
|
||||||
match current_block {
|
if OK_TO_CONTINUE {
|
||||||
10477488590406205504 => {}
|
|
||||||
_ => {
|
|
||||||
/* check if we can guarantee E2EE for this message.
|
/* check if we can guarantee E2EE for this message.
|
||||||
if we guarantee E2EE, and circumstances change
|
if we guarantee E2EE, and circumstances change
|
||||||
so that E2EE is no longer available at a later point (reset, changed settings),
|
so that E2EE is no longer available at a later point (reset, changed settings),
|
||||||
@@ -752,7 +745,7 @@ unsafe fn prepare_msg_raw(
|
|||||||
(*chat).id,
|
(*chat).id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1001,7 +994,7 @@ pub unsafe fn dc_set_draft(context: &Context, chat_id: uint32_t, msg: *mut dc_ms
|
|||||||
|
|
||||||
// TODO should return bool /rtn
|
// TODO should return bool /rtn
|
||||||
unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t) -> libc::c_int {
|
unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
let current_block: u64;
|
let mut OK_TO_CONTINUE = true;
|
||||||
// similar to as dc_set_draft() but does not emit an event
|
// similar to as dc_set_draft() but does not emit an event
|
||||||
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
let prev_draft_msg_id: uint32_t;
|
let prev_draft_msg_id: uint32_t;
|
||||||
@@ -1015,31 +1008,25 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
|||||||
if !msg.is_null() {
|
if !msg.is_null() {
|
||||||
if (*msg).type_0 == DC_MSG_TEXT {
|
if (*msg).type_0 == DC_MSG_TEXT {
|
||||||
if (*msg).text.is_null() || *(*msg).text.offset(0isize) as libc::c_int == 0i32 {
|
if (*msg).text.is_null() || *(*msg).text.offset(0isize) as libc::c_int == 0i32 {
|
||||||
current_block = 14513523936503887211;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
|
||||||
current_block = 4495394744059808450;
|
|
||||||
}
|
}
|
||||||
} else if msgtype_has_file((*msg).type_0) {
|
} else if msgtype_has_file((*msg).type_0) {
|
||||||
pathNfilename =
|
pathNfilename =
|
||||||
dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
||||||
if pathNfilename.is_null() {
|
if pathNfilename.is_null() {
|
||||||
current_block = 14513523936503887211;
|
OK_TO_CONTINUE = false;
|
||||||
} else if 0 != dc_msg_is_increation(msg)
|
} else if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, pathNfilename)
|
||||||
&& 0 == dc_is_blobdir_path(context, pathNfilename)
|
|
||||||
{
|
{
|
||||||
current_block = 14513523936503887211;
|
OK_TO_CONTINUE = false;
|
||||||
} else if 0 == dc_make_rel_and_copy(context, &mut pathNfilename) {
|
} else if !dc_make_rel_and_copy(context, &mut pathNfilename) {
|
||||||
current_block = 14513523936503887211;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
} else {
|
||||||
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
||||||
current_block = 4495394744059808450;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
current_block = 14513523936503887211;
|
OK_TO_CONTINUE = false;
|
||||||
}
|
}
|
||||||
match current_block {
|
if OK_TO_CONTINUE {
|
||||||
14513523936503887211 => {}
|
|
||||||
_ => {
|
|
||||||
if sql::execute(
|
if sql::execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
@@ -1058,7 +1045,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
|||||||
).is_ok() {
|
).is_ok() {
|
||||||
sth_changed = 1;
|
sth_changed = 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(pathNfilename as *mut libc::c_void);
|
free(pathNfilename as *mut libc::c_void);
|
||||||
@@ -1571,7 +1558,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
|||||||
contact_id: u32,
|
contact_id: u32,
|
||||||
flags: libc::c_int,
|
flags: libc::c_int,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let mut current_block: u64;
|
let mut OK_TO_CONTINUE = true;
|
||||||
let mut success: libc::c_int = 0;
|
let mut success: libc::c_int = 0;
|
||||||
let contact: *mut dc_contact_t = dc_get_contact(context, contact_id);
|
let contact: *mut dc_contact_t = dc_get_contact(context, contact_id);
|
||||||
let chat: *mut Chat = dc_chat_new(context);
|
let chat: *mut Chat = dc_chat_new(context);
|
||||||
@@ -1614,9 +1601,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
|||||||
if 0 != dc_is_contact_in_chat(context, chat_id, contact_id) {
|
if 0 != dc_is_contact_in_chat(context, chat_id, contact_id) {
|
||||||
if 0 == flags & 0x1 {
|
if 0 == flags & 0x1 {
|
||||||
success = 1;
|
success = 1;
|
||||||
current_block = 12326129973959287090;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
|
||||||
current_block = 15125582407903384992;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// else continue and send status mail
|
// else continue and send status mail
|
||||||
@@ -1626,28 +1611,17 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
|||||||
context, 0,
|
context, 0,
|
||||||
"Only bidirectional verified contacts can be added to verified groups."
|
"Only bidirectional verified contacts can be added to verified groups."
|
||||||
);
|
);
|
||||||
current_block = 12326129973959287090;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
|
||||||
current_block = 13472856163611868459;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
current_block = 13472856163611868459;
|
|
||||||
}
|
}
|
||||||
match current_block {
|
if OK_TO_CONTINUE {
|
||||||
12326129973959287090 => {}
|
|
||||||
_ => {
|
|
||||||
if 0 == dc_add_to_chat_contacts_table(context, chat_id, contact_id)
|
if 0 == dc_add_to_chat_contacts_table(context, chat_id, contact_id)
|
||||||
{
|
{
|
||||||
current_block = 12326129973959287090;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
|
||||||
current_block = 15125582407903384992;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if OK_TO_CONTINUE {
|
||||||
match current_block {
|
|
||||||
12326129973959287090 => {}
|
|
||||||
_ => {
|
|
||||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
|
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
|
||||||
(*msg).type_0 = DC_MSG_TEXT;
|
(*msg).type_0 = DC_MSG_TEXT;
|
||||||
(*msg).text = dc_stock_system_msg(
|
(*msg).text = dc_stock_system_msg(
|
||||||
@@ -1682,7 +1656,6 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
dc_chat_unref(chat);
|
dc_chat_unref(chat);
|
||||||
dc_contact_unref(contact);
|
dc_contact_unref(contact);
|
||||||
dc_msg_unref(msg);
|
dc_msg_unref(msg);
|
||||||
@@ -1923,7 +1896,7 @@ pub unsafe fn dc_set_chat_profile_image(
|
|||||||
chat_id: uint32_t,
|
chat_id: uint32_t,
|
||||||
new_image: *const libc::c_char,
|
new_image: *const libc::c_char,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let current_block: u64;
|
let mut OK_TO_CONTINUE = true;
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success: libc::c_int = 0i32;
|
||||||
let chat: *mut Chat = dc_chat_new(context);
|
let chat: *mut Chat = dc_chat_new(context);
|
||||||
let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
||||||
@@ -1941,17 +1914,11 @@ pub unsafe fn dc_set_chat_profile_image(
|
|||||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||||
if !new_image.is_null() {
|
if !new_image.is_null() {
|
||||||
new_image_rel = dc_strdup(new_image);
|
new_image_rel = dc_strdup(new_image);
|
||||||
if 0 == dc_make_rel_and_copy(context, &mut new_image_rel) {
|
if !dc_make_rel_and_copy(context, &mut new_image_rel) {
|
||||||
current_block = 14766584022300871387;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
|
||||||
current_block = 1856101646708284338;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
current_block = 1856101646708284338;
|
|
||||||
}
|
}
|
||||||
match current_block {
|
if OK_TO_CONTINUE {
|
||||||
14766584022300871387 => {}
|
|
||||||
_ => {
|
|
||||||
dc_param_set((*chat).param, DC_PARAM_PROFILE_IMAGE as i32, new_image_rel);
|
dc_param_set((*chat).param, DC_PARAM_PROFILE_IMAGE as i32, new_image_rel);
|
||||||
if !(0 == dc_chat_update_param(chat)) {
|
if !(0 == dc_chat_update_param(chat)) {
|
||||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32)
|
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32)
|
||||||
@@ -1989,7 +1956,6 @@ pub unsafe fn dc_set_chat_profile_image(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
dc_chat_unref(chat);
|
dc_chat_unref(chat);
|
||||||
dc_msg_unref(msg);
|
dc_msg_unref(msg);
|
||||||
|
|||||||
@@ -1375,15 +1375,9 @@ pub unsafe fn dc_get_fine_pathNfilename(
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub unsafe fn dc_is_blobdir_path(context: &Context, path: *const libc::c_char) -> bool {
|
||||||
pub unsafe fn dc_is_blobdir_path(context: &Context, path: *const libc::c_char) -> libc::c_int {
|
return strncmp(path, context.get_blobdir(), strlen(context.get_blobdir())) == 0
|
||||||
if strncmp(path, context.get_blobdir(), strlen(context.get_blobdir())) == 0i32
|
|| strncmp(path, b"$BLOBDIR\x00" as *const u8 as *const libc::c_char, 8) == 0;
|
||||||
|| strncmp(path, b"$BLOBDIR\x00" as *const u8 as *const libc::c_char, 8) == 0i32
|
|
||||||
{
|
|
||||||
return 1i32;
|
|
||||||
}
|
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_make_rel_path(context: &Context, path: *mut *mut libc::c_char) {
|
pub unsafe fn dc_make_rel_path(context: &Context, path: *mut *mut libc::c_char) {
|
||||||
@@ -1399,15 +1393,14 @@ pub unsafe fn dc_make_rel_path(context: &Context, path: *mut *mut libc::c_char)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO should return bool /rtn
|
pub unsafe fn dc_make_rel_and_copy(context: &Context, path: *mut *mut libc::c_char) -> bool {
|
||||||
pub unsafe fn dc_make_rel_and_copy(context: &Context, path: *mut *mut libc::c_char) -> libc::c_int {
|
let mut success = false;
|
||||||
let mut success: libc::c_int = 0i32;
|
|
||||||
let mut filename: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut filename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
let mut blobdir_path: *mut libc::c_char = 0 as *mut libc::c_char;
|
let mut blobdir_path: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||||
if !(path.is_null() || (*path).is_null()) {
|
if !(path.is_null() || (*path).is_null()) {
|
||||||
if 0 != dc_is_blobdir_path(context, *path) {
|
if dc_is_blobdir_path(context, *path) {
|
||||||
dc_make_rel_path(context, path);
|
dc_make_rel_path(context, path);
|
||||||
success = 1i32
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
filename = dc_get_filename(*path);
|
filename = dc_get_filename(*path);
|
||||||
if !(filename.is_null()
|
if !(filename.is_null()
|
||||||
@@ -1425,7 +1418,7 @@ pub unsafe fn dc_make_rel_and_copy(context: &Context, path: *mut *mut libc::c_ch
|
|||||||
*path = blobdir_path;
|
*path = blobdir_path;
|
||||||
blobdir_path = 0 as *mut libc::c_char;
|
blobdir_path = 0 as *mut libc::c_char;
|
||||||
dc_make_rel_path(context, path);
|
dc_make_rel_path(context, path);
|
||||||
success = 1i32
|
success = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,21 +123,15 @@ unsafe fn stress_functions(context: &Context) {
|
|||||||
context.get_blobdir(),
|
context.get_blobdir(),
|
||||||
b"foobar\x00" as *const u8 as *const libc::c_char,
|
b"foobar\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
assert_ne!(0, dc_is_blobdir_path(context, abs_path));
|
assert!(dc_is_blobdir_path(context, abs_path));
|
||||||
assert_ne!(
|
assert!(dc_is_blobdir_path(
|
||||||
0,
|
|
||||||
dc_is_blobdir_path(
|
|
||||||
context,
|
context,
|
||||||
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
|
b"$BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
|
||||||
)
|
));
|
||||||
);
|
assert!(!dc_is_blobdir_path(
|
||||||
assert_eq!(
|
|
||||||
0,
|
|
||||||
dc_is_blobdir_path(
|
|
||||||
context,
|
context,
|
||||||
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
|
b"/BLOBDIR/fofo\x00" as *const u8 as *const libc::c_char,
|
||||||
)
|
));
|
||||||
);
|
|
||||||
assert_ne!(0, dc_file_exist(context, abs_path));
|
assert_ne!(0, dc_file_exist(context, abs_path));
|
||||||
free(abs_path as *mut libc::c_void);
|
free(abs_path as *mut libc::c_void);
|
||||||
assert_ne!(
|
assert_ne!(
|
||||||
|
|||||||
Reference in New Issue
Block a user