Merge remote-tracking branch 'origin/master' into flub-sqlite

This commit is contained in:
dignifiedquire
2019-07-13 11:25:56 +02:00
5 changed files with 675 additions and 832 deletions

View File

@@ -1,15 +1,17 @@
deltachat python bindings deltachat python bindings
========================= =========================
The ``deltachat`` Python package provides two bindings for the core C-library The ``deltachat`` Python package provides two bindings for the core Rust-library
of the https://delta.chat messaging ecosystem: of the https://delta.chat messaging ecosystem:
- :doc:`capi` is a lowlevel CFFI-binding to the - :doc:`api` is a high level interface to deltachat-core which aims
`deltachat-core C-API <https://c.delta.chat>`_.
- :doc:`api` [work-in-progress] is a high level interface to deltachat-core which aims
to be memory safe and thoroughly tested through continous tox/pytest runs. to be memory safe and thoroughly tested through continous tox/pytest runs.
- :doc:`capi` is a lowlevel CFFI-binding to the previous
`deltachat-core C-API <https://c.delta.chat>`_ (so far the Rust library
replicates exactly the same C-level API).
getting started getting started
--------------- ---------------

View File

@@ -483,6 +483,8 @@ pub const DC_STR_MSGLOCATIONDISABLED: usize = 65;
pub const DC_STR_LOCATION: usize = 66; pub const DC_STR_LOCATION: usize = 66;
pub const DC_STR_COUNT: usize = 66; pub const DC_STR_COUNT: usize = 66;
pub const DC_JOB_DELETE_MSG_ON_IMAP: i32 = 110;
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)] #[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum KeyType { pub enum KeyType {

View File

@@ -175,10 +175,7 @@ pub unsafe fn dc_mimeparser_parse(
&mut (*mimeparser).e2ee_helper, &mut (*mimeparser).e2ee_helper,
); );
dc_mimeparser_parse_mime_recursive(mimeparser, (*mimeparser).mimeroot); dc_mimeparser_parse_mime_recursive(mimeparser, (*mimeparser).mimeroot);
let field: *mut mailimf_field = dc_mimeparser_lookup_field( let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, "Subject");
mimeparser,
b"Subject\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_SUBJECT as libc::c_int {
(*mimeparser).subject = (*mimeparser).subject =
dc_decode_header_words((*(*field).fld_data.fld_subject).sbj_value) dc_decode_header_words((*(*field).fld_data.fld_subject).sbj_value)
@@ -191,12 +188,7 @@ pub unsafe fn dc_mimeparser_parse(
{ {
(*mimeparser).is_send_by_messenger = 1i32 (*mimeparser).is_send_by_messenger = 1i32
} }
if !dc_mimeparser_lookup_field( if !dc_mimeparser_lookup_field(mimeparser, "Autocrypt-Setup-Message").is_null() {
mimeparser,
b"Autocrypt-Setup-Message\x00" as *const u8 as *const libc::c_char,
)
.is_null()
{
let mut i: libc::c_int; let mut i: libc::c_int;
let mut has_setup_file: libc::c_int = 0i32; let mut has_setup_file: libc::c_int = 0i32;
i = 0i32; i = 0i32;
@@ -237,11 +229,7 @@ pub unsafe fn dc_mimeparser_parse(
} }
} }
} }
if !dc_mimeparser_lookup_field( if !dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image").is_null()
mimeparser,
b"Chat-Group-Image\x00" as *const u8 as *const libc::c_char,
)
.is_null()
&& carray_count((*mimeparser).parts) >= 1i32 as libc::c_uint && carray_count((*mimeparser).parts) >= 1i32 as libc::c_uint
{ {
let textpart: *mut dc_mimepart_t = let textpart: *mut dc_mimepart_t =
@@ -383,10 +371,8 @@ pub unsafe fn dc_mimeparser_parse(
{ {
let dn_to_addr: *mut libc::c_char = mailimf_find_first_addr(mb_list); let dn_to_addr: *mut libc::c_char = mailimf_find_first_addr(mb_list);
if !dn_to_addr.is_null() { if !dn_to_addr.is_null() {
let from_field: *mut mailimf_field = dc_mimeparser_lookup_field( let from_field: *mut mailimf_field =
mimeparser, dc_mimeparser_lookup_field(mimeparser, "From");
b"From\x00" as *const u8 as *const libc::c_char,
);
if !from_field.is_null() if !from_field.is_null()
&& (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int && (*from_field).fld_type == MAILIMF_FIELD_FROM as libc::c_int
&& !(*from_field).fld_data.fld_from.is_null() && !(*from_field).fld_data.fld_from.is_null()
@@ -487,13 +473,14 @@ pub unsafe fn mailimf_find_first_addr(mb_list: *const mailimf_mailbox_list) -> *
} }
/* the following functions can be used only after a call to dc_mimeparser_parse() */ /* the following functions can be used only after a call to dc_mimeparser_parse() */
pub fn dc_mimeparser_lookup_field( pub fn dc_mimeparser_lookup_field(
mimeparser: &dc_mimeparser_t, mimeparser: &dc_mimeparser_t,
field_name: *const libc::c_char, field_name: &str,
) -> *mut mailimf_field { ) -> *mut mailimf_field {
mimeparser mimeparser
.header .header
.get(as_str(field_name)) .get(field_name)
.map(|v| *v) .map(|v| *v)
.unwrap_or_else(|| std::ptr::null_mut()) .unwrap_or_else(|| std::ptr::null_mut())
} }
@@ -1621,12 +1608,7 @@ pub unsafe fn mailmime_transfer_decode(
// TODO should return bool /rtn // TODO should return bool /rtn
pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> libc::c_int { pub unsafe fn dc_mimeparser_is_mailinglist_message(mimeparser: &dc_mimeparser_t) -> libc::c_int {
if !dc_mimeparser_lookup_field( if !dc_mimeparser_lookup_field(&mimeparser, "List-Id").is_null() {
&mimeparser,
b"List-Id\x00" as *const u8 as *const libc::c_char,
)
.is_null()
{
return 1i32; return 1i32;
} }
let precedence: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field( let precedence: *mut mailimf_optional_field = dc_mimeparser_lookup_optional_field(

View File

@@ -39,7 +39,6 @@ pub unsafe fn dc_receive_imf(
/* the function returns the number of created messages in the database */ /* the function returns the number of created messages in the database */
let mut incoming: libc::c_int = 1; let mut incoming: libc::c_int = 1;
let mut incoming_origin: libc::c_int = 0; let mut incoming_origin: libc::c_int = 0;
let to_ids: *mut dc_array_t;
let mut to_self: libc::c_int = 0; let mut to_self: libc::c_int = 0;
let mut from_id: uint32_t = 0 as uint32_t; let mut from_id: uint32_t = 0 as uint32_t;
let mut from_id_blocked: libc::c_int = 0; let mut from_id_blocked: libc::c_int = 0;
@@ -59,15 +58,19 @@ pub unsafe fn dc_receive_imf(
let mut sort_timestamp = 0; let mut sort_timestamp = 0;
let mut sent_timestamp = 0; let mut sent_timestamp = 0;
let mut rcvd_timestamp = 0; let mut rcvd_timestamp = 0;
let mut mime_parser = dc_mimeparser_new(context);
let mut field: *const mailimf_field; let mut field: *const mailimf_field;
let mut mime_in_reply_to = 0 as *mut libc::c_char; let mut mime_in_reply_to = 0 as *mut libc::c_char;
let mut mime_references = 0 as *mut libc::c_char; let mut mime_references = 0 as *mut libc::c_char;
let created_db_entries = carray_new(16 as libc::c_uint); let mut created_db_entries = Vec::new();
let mut create_event_to_send = Some(Event::MSGS_CHANGED); let mut create_event_to_send = Some(Event::MSGS_CHANGED);
let rr_event_to_send = carray_new(16 as libc::c_uint); let mut rr_event_to_send = Vec::new();
let mut txt_raw = 0 as *mut libc::c_char; let mut txt_raw = 0 as *mut libc::c_char;
// XXX converting the below "to_ids" to a Vec quickly leads to lots of changes
// so we keep it as a dc_array for now
let to_ids = dc_array_new(16);
assert!(!to_ids.is_null());
info!( info!(
context, context,
0, 0,
@@ -79,29 +82,21 @@ pub unsafe fn dc_receive_imf(
}, },
server_uid, server_uid,
); );
to_ids = dc_array_new(16 as size_t);
if to_ids.is_null() || created_db_entries.is_null() || rr_event_to_send.is_null() { let mut mime_parser = dc_mimeparser_new(context);
info!(context, 0, "Bad param.",);
} else {
dc_mimeparser_parse(&mut mime_parser, imf_raw_not_terminated, imf_raw_bytes); dc_mimeparser_parse(&mut mime_parser, imf_raw_not_terminated, imf_raw_bytes);
if mime_parser.header.is_empty() { if mime_parser.header.is_empty() {
info!(context, 0, "No header.",); info!(context, 0, "No header.",);
} else { } else {
/* Error - even adding an empty record won't help as we do not know the message ID */ /* Error - even adding an empty record won't help as we do not know the message ID */
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mut mime_parser, "Date");
&mut mime_parser,
b"Date\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_ORIG_DATE as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_ORIG_DATE as libc::c_int {
let orig_date: *mut mailimf_orig_date = (*field).fld_data.fld_orig_date; let orig_date: *mut mailimf_orig_date = (*field).fld_data.fld_orig_date;
if !orig_date.is_null() { if !orig_date.is_null() {
sent_timestamp = dc_timestamp_from_date((*orig_date).dt_date_time) sent_timestamp = dc_timestamp_from_date((*orig_date).dt_date_time)
} }
} }
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "From");
&mime_parser,
b"From\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_FROM as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_FROM as libc::c_int {
let fld_from: *mut mailimf_from = (*field).fld_data.fld_from; let fld_from: *mut mailimf_from = (*field).fld_data.fld_from;
if !fld_from.is_null() { if !fld_from.is_null() {
@@ -121,16 +116,12 @@ pub unsafe fn dc_receive_imf(
} }
} else if dc_array_get_cnt(from_list) >= 1 { } else if dc_array_get_cnt(from_list) >= 1 {
from_id = dc_array_get_id(from_list, 0 as size_t); from_id = dc_array_get_id(from_list, 0 as size_t);
incoming_origin = incoming_origin = dc_get_contact_origin(context, from_id, &mut from_id_blocked)
dc_get_contact_origin(context, from_id, &mut from_id_blocked)
} }
dc_array_unref(from_list); dc_array_unref(from_list);
} }
} }
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "To");
&mime_parser,
b"To\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_TO as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_TO as libc::c_int {
let fld_to: *mut mailimf_to = (*field).fld_data.fld_to; let fld_to: *mut mailimf_to = (*field).fld_data.fld_to;
if !fld_to.is_null() { if !fld_to.is_null() {
@@ -150,10 +141,7 @@ pub unsafe fn dc_receive_imf(
} }
} }
if !dc_mimeparser_get_last_nonmeta(&mime_parser).is_null() { if !dc_mimeparser_get_last_nonmeta(&mime_parser).is_null() {
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "Cc");
&mime_parser,
b"Cc\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_CC as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_CC as libc::c_int {
let fld_cc: *mut mailimf_cc = (*field).fld_data.fld_cc; let fld_cc: *mut mailimf_cc = (*field).fld_data.fld_cc;
if !fld_cc.is_null() { if !fld_cc.is_null() {
@@ -172,12 +160,8 @@ pub unsafe fn dc_receive_imf(
); );
} }
} }
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "Message-ID");
&mime_parser, if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_MESSAGE_ID as libc::c_int {
b"Message-ID\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_MESSAGE_ID as libc::c_int
{
let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id; let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id;
if !fld_message_id.is_null() { if !fld_message_id.is_null() {
rfc724_mid = dc_strdup((*fld_message_id).mid_value) rfc724_mid = dc_strdup((*fld_message_id).mid_value)
@@ -244,20 +228,12 @@ pub unsafe fn dc_receive_imf(
if 0 != incoming { if 0 != incoming {
state = if 0 != flags & 0x1 { 16 } else { 10 }; state = if 0 != flags & 0x1 { 16 } else { 10 };
to_id = 1 as uint32_t; to_id = 1 as uint32_t;
if !dc_mimeparser_lookup_field( if !dc_mimeparser_lookup_field(&mime_parser, "Secure-Join").is_null() {
&mime_parser,
b"Secure-Join\x00" as *const u8 as *const libc::c_char,
)
.is_null()
{
msgrmsg = 1; msgrmsg = 1;
chat_id = 0 as uint32_t; chat_id = 0 as uint32_t;
allow_creation = 1; allow_creation = 1;
let handshake: libc::c_int = dc_handle_securejoin_handshake( let handshake: libc::c_int =
context, dc_handle_securejoin_handshake(context, &mime_parser, from_id);
&mime_parser,
from_id,
);
if 0 != handshake & 0x2 { if 0 != handshake & 0x2 {
hidden = 1; hidden = 1;
add_delete_job = handshake & 0x4; add_delete_job = handshake & 0x4;
@@ -375,9 +351,8 @@ pub unsafe fn dc_receive_imf(
} }
} }
if chat_id == 0 as libc::c_uint && 0 != allow_creation { if chat_id == 0 as libc::c_uint && 0 != allow_creation {
let create_blocked_1: libc::c_int = if 0 != msgrmsg let create_blocked_1: libc::c_int =
&& !dc_is_contact_blocked(context, to_id) if 0 != msgrmsg && !dc_is_contact_blocked(context, to_id) {
{
0 0
} else { } else {
2 2
@@ -389,9 +364,7 @@ pub unsafe fn dc_receive_imf(
&mut chat_id, &mut chat_id,
&mut chat_id_blocked, &mut chat_id_blocked,
); );
if 0 != chat_id if 0 != chat_id && 0 != chat_id_blocked && 0 == create_blocked_1
&& 0 != chat_id_blocked
&& 0 == create_blocked_1
{ {
dc_unblock_chat(context, chat_id); dc_unblock_chat(context, chat_id);
chat_id_blocked = 0 chat_id_blocked = 0
@@ -432,10 +405,7 @@ pub unsafe fn dc_receive_imf(
// (the mime-header ends with an empty line) // (the mime-header ends with an empty line)
let save_mime_headers = let save_mime_headers =
sql::get_config_int(context, &context.sql, "save_mime_headers", 0); sql::get_config_int(context, &context.sql, "save_mime_headers", 0);
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "In-Reply-To");
&mime_parser,
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() if !field.is_null()
&& (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int
{ {
@@ -448,10 +418,7 @@ pub unsafe fn dc_receive_imf(
) )
} }
} }
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(&mime_parser, "References");
&mime_parser,
b"References\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() if !field.is_null()
&& (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int
{ {
@@ -564,16 +531,7 @@ pub unsafe fn dc_receive_imf(
"rfc724_mid", "rfc724_mid",
as_str(rfc724_mid), as_str(rfc724_mid),
); );
carray_add( created_db_entries.push((chat_id as usize, insert_msg_id as usize));
created_db_entries,
chat_id as uintptr_t as *mut libc::c_void,
0 as *mut libc::c_uint,
);
carray_add(
created_db_entries,
insert_msg_id as uintptr_t as *mut libc::c_void,
0 as *mut libc::c_uint,
);
} }
} }
i = i.wrapping_add(1) i = i.wrapping_add(1)
@@ -641,16 +599,13 @@ pub unsafe fn dc_receive_imf(
{ {
if strcmp( if strcmp(
(*report_type).pa_value, (*report_type).pa_value,
b"disposition-notification\x00" as *const u8 b"disposition-notification\x00" as *const u8 as *const libc::c_char,
as *const libc::c_char,
) == 0 ) == 0
&& (*(*report_root).mm_data.mm_multipart.mm_mp_list).count >= 2 && (*(*report_root).mm_data.mm_multipart.mm_mp_list).count >= 2
{ {
if 0 != mdns_enabled { if 0 != mdns_enabled {
let report_data: *mut mailmime = (if !if !(*(*report_root) let report_data: *mut mailmime =
.mm_data (if !if !(*(*report_root).mm_data.mm_multipart.mm_mp_list)
.mm_multipart
.mm_mp_list)
.first .first
.is_null() .is_null()
{ {
@@ -675,8 +630,7 @@ pub unsafe fn dc_receive_imf(
.data .data
} else { } else {
0 as *mut libc::c_void 0 as *mut libc::c_void
}) }) as *mut mailmime;
as *mut mailmime;
if !report_data.is_null() if !report_data.is_null()
&& (*(*(*report_data).mm_content_type).ct_type).tp_type && (*(*(*report_data).mm_content_type).ct_type).tp_type
== MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int == MAILMIME_TYPE_COMPOSITE_TYPE as libc::c_int
@@ -724,25 +678,19 @@ pub unsafe fn dc_receive_imf(
*const u8 *const u8
as as
*const libc::c_char); *const libc::c_char);
let of_org_msgid: let of_org_msgid: *mut mailimf_optional_field =
*mut mailimf_optional_field = mailimf_find_optional_field(
mailimf_find_optional_field(report_fields, report_fields,
b"Original-Message-ID\x00" b"Original-Message-ID\x00" as *const u8
as as *const libc::c_char,
*const u8 );
as
*const libc::c_char);
if !of_disposition.is_null() if !of_disposition.is_null()
&& !(*of_disposition) && !(*of_disposition).fld_value.is_null()
.fld_value
.is_null()
&& !of_org_msgid.is_null() && !of_org_msgid.is_null()
&& !(*of_org_msgid).fld_value.is_null() && !(*of_org_msgid).fld_value.is_null()
{ {
let mut rfc724_mid_0: let mut rfc724_mid_0: *mut libc::c_char =
*mut libc::c_char = 0 as *mut libc::c_char;
0 as
*mut libc::c_char;
dummy = 0 as size_t; dummy = 0 as size_t;
if mailimf_msg_id_parse( if mailimf_msg_id_parse(
(*of_org_msgid).fld_value, (*of_org_msgid).fld_value,
@@ -764,26 +712,14 @@ pub unsafe fn dc_receive_imf(
&mut chat_id_0, &mut chat_id_0,
&mut msg_id, &mut msg_id,
) { ) {
carray_add( rr_event_to_send
rr_event_to_send, .push((chat_id_0, 0));
chat_id_0 as uintptr_t rr_event_to_send.push((msg_id, 0));
as *mut libc::c_void,
0 as *mut libc::c_uint,
);
carray_add(
rr_event_to_send,
msg_id as uintptr_t
as *mut libc::c_void,
0 as *mut libc::c_uint,
);
} }
mdn_consumed = (msg_id mdn_consumed = (msg_id
!= 0 as libc::c_uint) != 0 as libc::c_uint)
as libc::c_int; as libc::c_int;
free( free(rfc724_mid_0 as *mut libc::c_void);
rfc724_mid_0
as *mut libc::c_void,
);
} }
} }
} }
@@ -849,8 +785,7 @@ pub unsafe fn dc_receive_imf(
if !(*mime_parser.location_kml).addr.is_null() if !(*mime_parser.location_kml).addr.is_null()
&& !contact.is_null() && !contact.is_null()
&& !(*contact).addr.is_null() && !(*contact).addr.is_null()
&& strcasecmp((*contact).addr, (*mime_parser.location_kml).addr) && strcasecmp((*contact).addr, (*mime_parser.location_kml).addr) == 0
== 0
{ {
let newest_location_id = dc_save_locations( let newest_location_id = dc_save_locations(
context, context,
@@ -860,11 +795,7 @@ pub unsafe fn dc_receive_imf(
0, 0,
); );
if newest_location_id != 0 && hidden == 0 && !location_id_written { if newest_location_id != 0 && hidden == 0 && !location_id_written {
dc_set_msg_location_id( dc_set_msg_location_id(context, insert_msg_id, newest_location_id);
context,
insert_msg_id,
newest_location_id,
);
} }
send_event = true; send_event = true;
} }
@@ -879,13 +810,11 @@ pub unsafe fn dc_receive_imf(
} }
} }
if 0 != add_delete_job && carray_count(created_db_entries) >= 2 as libc::c_uint if 0 != add_delete_job && !created_db_entries.is_empty() {
{
dc_job_add( dc_job_add(
context, context,
110, DC_JOB_DELETE_MSG_ON_IMAP,
carray_get(created_db_entries, 1 as libc::c_uint) as uintptr_t created_db_entries[0].1 as i32,
as libc::c_int,
0 as *const libc::c_char, 0 as *const libc::c_char,
0, 0,
); );
@@ -893,42 +822,21 @@ pub unsafe fn dc_receive_imf(
} }
} }
} }
}
free(rfc724_mid as *mut libc::c_void); free(rfc724_mid as *mut libc::c_void);
free(mime_in_reply_to as *mut libc::c_void); free(mime_in_reply_to as *mut libc::c_void);
free(mime_references as *mut libc::c_void); free(mime_references as *mut libc::c_void);
dc_array_unref(to_ids); dc_array_unref(to_ids);
if !created_db_entries.is_null() {
if let Some(create_event_to_send) = create_event_to_send { if let Some(create_event_to_send) = create_event_to_send {
let mut i_0: size_t = 0; for (msg_id, insert_id) in &created_db_entries {
let icnt_0: size_t = carray_count(created_db_entries) as size_t; context.call_cb(create_event_to_send, *msg_id, *insert_id);
while i_0 < icnt_0 {
context.call_cb(
create_event_to_send,
carray_get(created_db_entries, i_0 as libc::c_uint) as uintptr_t,
carray_get(created_db_entries, i_0.wrapping_add(1) as libc::c_uint)
as uintptr_t,
);
i_0 = (i_0 as libc::c_ulong).wrapping_add(2 as libc::c_ulong) as size_t as size_t
} }
} }
carray_free(created_db_entries); for (chat_id, msg_id) in &rr_event_to_send {
} context.call_cb(Event::MSG_READ, *chat_id as uintptr_t, *msg_id as uintptr_t);
if !rr_event_to_send.is_null() {
let mut i_1: size_t;
let icnt_1: size_t = carray_count(rr_event_to_send) as size_t;
i_1 = 0 as size_t;
while i_1 < icnt_1 {
context.call_cb(
Event::MSG_READ,
carray_get(rr_event_to_send, i_1 as libc::c_uint) as uintptr_t,
carray_get(rr_event_to_send, i_1.wrapping_add(1) as libc::c_uint) as uintptr_t,
);
i_1 = (i_1 as libc::c_ulong).wrapping_add(2 as libc::c_ulong) as size_t as size_t
}
carray_free(rr_event_to_send);
} }
free(txt_raw as *mut libc::c_void); free(txt_raw as *mut libc::c_void);
} }
@@ -1034,10 +942,7 @@ unsafe fn create_or_lookup_group(
grpid = dc_strdup((*optional_field).fld_value) grpid = dc_strdup((*optional_field).fld_value)
} }
if grpid.is_null() { if grpid.is_null() {
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(mime_parser, "Message-ID");
mime_parser,
b"Message-ID\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_MESSAGE_ID as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_MESSAGE_ID as libc::c_int {
let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id; let fld_message_id: *mut mailimf_message_id = (*field).fld_data.fld_message_id;
if !fld_message_id.is_null() { if !fld_message_id.is_null() {
@@ -1045,10 +950,7 @@ unsafe fn create_or_lookup_group(
} }
} }
if grpid.is_null() { if grpid.is_null() {
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(mime_parser, "In-Reply-To");
mime_parser,
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to; let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to;
if !fld_in_reply_to.is_null() { if !fld_in_reply_to.is_null() {
@@ -1056,10 +958,7 @@ unsafe fn create_or_lookup_group(
} }
} }
if grpid.is_null() { if grpid.is_null() {
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(mime_parser, "References");
mime_parser,
b"References\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int
{ {
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references; let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
@@ -1221,12 +1120,7 @@ unsafe fn create_or_lookup_group(
/*otherwise, a pending "quit" message may pop up*/ /*otherwise, a pending "quit" message may pop up*/
/*re-create explicitly left groups only if ourself is re-added*/ /*re-create explicitly left groups only if ourself is re-added*/
let mut create_verified: libc::c_int = 0; let mut create_verified: libc::c_int = 0;
if !dc_mimeparser_lookup_field( if !dc_mimeparser_lookup_field(mime_parser, "Chat-Verified").is_null() {
mime_parser,
b"Chat-Verified\x00" as *const u8 as *const libc::c_char,
)
.is_null()
{
create_verified = 1; create_verified = 1;
if 0 == check_verified_properties( if 0 == check_verified_properties(
context, context,
@@ -1815,8 +1709,7 @@ unsafe fn dc_is_reply_to_known_message(
) -> libc::c_int { ) -> libc::c_int {
/* check if the message is a reply to a known message; the replies are identified by the Message-ID from /* check if the message is a reply to a known message; the replies are identified by the Message-ID from
`In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */ `In-Reply-To`/`References:` (to support non-Delta-Clients) or from `Chat-Predecessor:` (Delta clients, see comment in dc_chat.c) */
let optional_field: *mut mailimf_optional_field; let optional_field = dc_mimeparser_lookup_optional_field(
optional_field = dc_mimeparser_lookup_optional_field(
mime_parser, mime_parser,
b"Chat-Predecessor\x00" as *const u8 as *const libc::c_char, b"Chat-Predecessor\x00" as *const u8 as *const libc::c_char,
); );
@@ -1825,11 +1718,7 @@ unsafe fn dc_is_reply_to_known_message(
return 1; return 1;
} }
} }
let mut field: *mut mailimf_field; let field = dc_mimeparser_lookup_field(mime_parser, "In-Reply-To");
field = dc_mimeparser_lookup_field(
mime_parser,
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to; let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to;
if !fld_in_reply_to.is_null() { if !fld_in_reply_to.is_null() {
@@ -1841,10 +1730,7 @@ unsafe fn dc_is_reply_to_known_message(
} }
} }
} }
field = dc_mimeparser_lookup_field( let field = dc_mimeparser_lookup_field(mime_parser, "References");
mime_parser,
b"References\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references; let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
if !fld_references.is_null() { if !fld_references.is_null() {
@@ -1912,11 +1798,7 @@ unsafe fn dc_is_reply_to_messenger_message(
- checks also if any of the referenced IDs are send by a messenger - checks also if any of the referenced IDs are send by a messenger
- it is okay, if the referenced messages are moved to trash here - it is okay, if the referenced messages are moved to trash here
- no check for the Chat-* headers (function is only called if it is no messenger message itself) */ - no check for the Chat-* headers (function is only called if it is no messenger message itself) */
let mut field: *mut mailimf_field; let field = dc_mimeparser_lookup_field(mime_parser, "In-Reply-To");
field = dc_mimeparser_lookup_field(
mime_parser,
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_IN_REPLY_TO as libc::c_int {
let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to; let fld_in_reply_to: *mut mailimf_in_reply_to = (*field).fld_data.fld_in_reply_to;
if !fld_in_reply_to.is_null() { if !fld_in_reply_to.is_null() {
@@ -1928,10 +1810,7 @@ unsafe fn dc_is_reply_to_messenger_message(
} }
} }
} }
field = dc_mimeparser_lookup_field( let field = dc_mimeparser_lookup_field(mime_parser, "References");
mime_parser,
b"References\x00" as *const u8 as *const libc::c_char,
);
if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int { if !field.is_null() && (*field).fld_type == MAILIMF_FIELD_REFERENCES as libc::c_int {
let fld_references: *mut mailimf_references = (*field).fld_data.fld_references; let fld_references: *mut mailimf_references = (*field).fld_data.fld_references;
if !fld_references.is_null() { if !fld_references.is_null() {

View File

@@ -353,10 +353,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t; let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
if !(contact_id <= 9i32 as libc::c_uint) { if !(contact_id <= 9i32 as libc::c_uint) {
step = lookup_field( step = lookup_field(mimeparser, "Secure-Join");
mimeparser,
b"Secure-Join\x00" as *const u8 as *const libc::c_char,
);
if !step.is_null() { if !step.is_null() {
info!( info!(
context, context,
@@ -389,10 +386,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
// send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here. // send_message() will fail with the error "End-to-end-encryption unavailable unexpectedly.", so, there is no additional check needed here.
// verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code // verify that the `Secure-Join-Invitenumber:`-header matches invitenumber written to the QR code
let invitenumber: *const libc::c_char; let invitenumber: *const libc::c_char;
invitenumber = lookup_field( invitenumber = lookup_field(mimeparser, "Secure-Join-Invitenumber");
mimeparser,
b"Secure-Join-Invitenumber\x00" as *const u8 as *const libc::c_char,
);
if invitenumber.is_null() { if invitenumber.is_null() {
warn!(context, 0, "Secure-join denied (invitenumber missing).",); warn!(context, 0, "Secure-join denied (invitenumber missing).",);
current_block = 4378276786830486580; current_block = 4378276786830486580;
@@ -518,10 +512,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
============================================================ */ ============================================================ */
// verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob // verify that Secure-Join-Fingerprint:-header matches the fingerprint of Bob
let fingerprint: *const libc::c_char; let fingerprint: *const libc::c_char;
fingerprint = lookup_field( fingerprint = lookup_field(mimeparser, "Secure-Join-Fingerprint");
mimeparser,
b"Secure-Join-Fingerprint\x00" as *const u8 as *const libc::c_char,
);
if fingerprint.is_null() { if fingerprint.is_null() {
could_not_establish_secure_connection( could_not_establish_secure_connection(
context, context,
@@ -548,10 +539,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
info!(context, 0, "Fingerprint verified.",); info!(context, 0, "Fingerprint verified.",);
// verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code // verify that the `Secure-Join-Auth:`-header matches the secret written to the QR code
let auth_0: *const libc::c_char; let auth_0: *const libc::c_char;
auth_0 = lookup_field( auth_0 = lookup_field(mimeparser, "Secure-Join-Auth");
mimeparser,
b"Secure-Join-Auth\x00" as *const u8 as *const libc::c_char,
);
if auth_0.is_null() { if auth_0.is_null() {
could_not_establish_secure_connection( could_not_establish_secure_connection(
context, context,
@@ -589,10 +577,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
600i32 as uintptr_t, 600i32 as uintptr_t,
); );
if 0 != join_vg { if 0 != join_vg {
grpid = dc_strdup(lookup_field( grpid = dc_strdup(lookup_field(mimeparser, "Secure-Join-Group"));
mimeparser,
b"Secure-Join-Group\x00" as *const u8 as *const libc::c_char,
));
let group_chat_id: uint32_t = dc_get_chat_id_by_grpid( let group_chat_id: uint32_t = dc_get_chat_id_by_grpid(
context, context,
grpid, grpid,
@@ -714,11 +699,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
if 0 != join_vg { if 0 != join_vg {
if 0 == dc_addr_equals_self( if 0 == dc_addr_equals_self(
context, context,
lookup_field( lookup_field(mimeparser, "Chat-Group-Member-Added"),
mimeparser,
b"Chat-Group-Member-Added\x00" as *const u8
as *const libc::c_char,
),
) { ) {
info!( info!(
context, context,
@@ -832,10 +813,7 @@ unsafe fn secure_connection_established(context: &Context, contact_chat_id: uint
dc_contact_unref(contact); dc_contact_unref(contact);
} }
unsafe fn lookup_field( unsafe fn lookup_field(mimeparser: &dc_mimeparser_t, key: &str) -> *const libc::c_char {
mimeparser: &dc_mimeparser_t,
key: *const libc::c_char,
) -> *const libc::c_char {
let mut value: *const libc::c_char = 0 as *const libc::c_char; let mut value: *const libc::c_char = 0 as *const libc::c_char;
let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, key); let field: *mut mailimf_field = dc_mimeparser_lookup_field(mimeparser, key);
if field.is_null() if field.is_null()