Compare commits

..

12 Commits

Author SHA1 Message Date
jikstra
ea7da1661b rename success to ok_to_continue 2019-08-09 19:22:40 +02:00
Jikstra
144858b318 Merge branch 'master' into remove_gotos_dc_msg 2019-08-09 15:36:58 +02:00
holger krekel
be605d8ea5 fix(peerstate): encryption-not-available
Add a test for failing e2e encryption and some info statement to hunt where the e2e encryption failure comes from, as well as fix the issue.


Closes #233
2019-08-09 13:28:48 +02:00
Friedel Ziegelmayer
4d8d5f4e1e Fix broken string allocations in message handling (#306)
Fix broken string allocations in message handling
2019-08-09 11:32:42 +02:00
holger krekel
750d6e99a8 fix some longer standing nonsense code that sent to misleading MSG_READ events instead of one correct one 2019-08-09 11:32:24 +02:00
holger krekel
a67892d414 (jikstra, hpk) fix a logic bug introduced with the stock-string merge which set the better message only if it was empty 2019-08-09 11:32:24 +02:00
holger krekel
1cd2a62caf fix a failure which blocked correctly sending out messages (dc_job_add_smtp mis-set filename) 2019-08-09 11:32:24 +02:00
dignifiedquire
6772d6f66c fix: improve some string handling in the message recieve path 2019-08-09 11:32:24 +02:00
Simon Laux
89531dfb62 fix(dc_lot): correct test2 2019-08-09 11:31:11 +02:00
jikstra
ba02406cb0 Rename OK_TO_CONTINUE variable to success and remove linter exception 2019-08-03 12:43:54 +02:00
jikstra
32fd3242e9 run cargo fmt 2019-07-29 16:31:33 +02:00
jikstra
ff3f96df48 Replace goto/current_block logic in dc_msg with OK_TO_CONTINUE approach. Keeps indentation 2019-07-29 16:30:42 +02:00
5 changed files with 48 additions and 63 deletions

View File

@@ -76,11 +76,6 @@ pub unsafe fn dc_e2ee_encrypt(
let mut peerstates: Vec<Peerstate> = Vec::new();
*helper = Default::default();
info!(
context,
0, "dc_e2ee_encrypt guaruanteed={}", e2ee_guaranteed
);
if !(recipients_addr.is_null()
|| in_out_message.is_null()
|| !(*in_out_message).mm_parent.is_null()
@@ -111,10 +106,6 @@ pub unsafe fn dc_e2ee_encrypt(
iter1 = (*recipients_addr).first;
while !iter1.is_null() {
let recipient_addr = to_string((*iter1).data as *const libc::c_char);
info!(
context,
0, "dc_e2ee_encrypt recipient_addr {}", recipient_addr
);
if recipient_addr != addr {
let peerstate =
Peerstate::from_addr(context, &context.sql, &recipient_addr);
@@ -594,7 +585,6 @@ pub unsafe fn dc_e2ee_decrypt(
}
} else if let Some(ref header) = autocryptheader {
let p = Peerstate::from_header(context, header, message_time);
info!(context, 0, "setting peerstate from header for {:?}", p.addr);
assert!(p.save_to_db(&context.sql, true));
peerstate = Some(p);
}

View File

@@ -6,8 +6,6 @@ use crate::dc_tools::*;
use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
use std::ffi::CString;
use std::ptr;
/* * Structure behind dc_lot_t */
#[derive(Copy, Clone)]
@@ -171,14 +169,15 @@ pub unsafe fn dc_lot_fill(
}
}
let msgtext_c = (*msg)
.text
.as_ref()
.map(|s| CString::yolo(String::as_str(s)));
let msgtext_ptr = msgtext_c.map_or(ptr::null(), |s| s.as_ptr());
let message_text = (*msg).text.as_ref().unwrap();
(*lot).text2 =
dc_msg_get_summarytext_by_raw((*msg).type_0, msgtext_ptr, &mut (*msg).param, 160, context);
(*lot).text2 = dc_msg_get_summarytext_by_raw(
(*msg).type_0,
message_text.strdup(),
&mut (*msg).param,
160,
context,
);
(*lot).timestamp = dc_msg_get_timestamp(msg);
(*lot).state = (*msg).state;

View File

@@ -1041,11 +1041,6 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
&mut e2ee_helper,
);
}
info!(
(*factory).context,
0, "encryption successful {}", e2ee_helper.encryption_successfull
);
if 0 != e2ee_helper.encryption_successfull {
(*factory).out_encrypted = 1;
if 0 != do_gossip {

View File

@@ -786,7 +786,7 @@ pub unsafe fn dc_msg_get_summary<'a>(
msg: *mut dc_msg_t<'a>,
mut chat: *const Chat<'a>,
) -> *mut dc_lot_t {
let current_block: u64;
let mut ok_to_continue = true;
let ret: *mut dc_lot_t = dc_lot_new();
let mut chat_to_delete: *mut Chat = 0 as *mut Chat;
@@ -794,27 +794,23 @@ pub unsafe fn dc_msg_get_summary<'a>(
if chat.is_null() {
chat_to_delete = dc_get_chat((*msg).context, (*msg).chat_id);
if chat_to_delete.is_null() {
current_block = 15204159476013091401;
} else {
chat = chat_to_delete;
current_block = 7815301370352969686;
ok_to_continue = false;
}
} else {
current_block = 7815301370352969686;
ok_to_continue = false;
}
match current_block {
15204159476013091401 => {}
_ => {
let contact = if (*msg).from_id != DC_CONTACT_ID_SELF as libc::c_uint
&& ((*chat).type_0 == 120 || (*chat).type_0 == 130)
{
Contact::get_by_id((*chat).context, (*msg).from_id).ok()
} else {
None
};
if ok_to_continue == false {
let contact = if (*msg).from_id != DC_CONTACT_ID_SELF as libc::c_uint
&& ((*chat).type_0 == 120 || (*chat).type_0 == 130)
{
Contact::get_by_id((*chat).context, (*msg).from_id).ok()
} else {
None
};
dc_lot_fill(ret, msg, chat, contact.as_ref(), (*msg).context);
}
dc_lot_fill(ret, msg, chat, contact.as_ref(), (*msg).context);
}
}

View File

@@ -166,7 +166,6 @@ impl<'a> Peerstate<'a> {
pub fn from_addr(context: &'a Context, _sql: &Sql, addr: &str) -> Option<Self> {
let query = "SELECT addr, last_seen, last_seen_autocrypt, prefer_encrypted, public_key, gossip_timestamp, gossip_key, public_key_fingerprint, gossip_key_fingerprint, verified_key, verified_key_fingerprint FROM acpeerstates WHERE addr=? COLLATE NOCASE;";
info!(context, 0, "peerstate.from_addr {}", addr);
Self::from_stmt(context, query, &[addr])
}
@@ -188,7 +187,6 @@ impl<'a> Peerstate<'a> {
P: IntoIterator,
P::Item: rusqlite::ToSql,
{
info!(context, 0, "from_stmt query {:?}", query);
context
.sql
.query_row(query, params, |row| {
@@ -200,28 +198,38 @@ impl<'a> Peerstate<'a> {
let mut res = Self::new(context);
res.addr = Some(row.get(0)?);
info!(context, 0, "from_stmt res.addr {:?} starting", res.addr);
res.last_seen = row.get(1)?;
res.last_seen_autocrypt = row.get(2)?;
res.prefer_encrypt = EncryptPreference::from_i32(row.get(3)?).unwrap_or_default();
res.gossip_timestamp = row.get(5)?;
let pkf: String = row.get(7)?;
res.public_key_fingerprint = if pkf.is_empty() { None } else { Some(pkf) };
let t: Result<String, rusqlite::Error> = row.get(8);
let gkf: String = match t {
Err(_) => String::from(""),
Ok(res) => res,
};
res.gossip_key_fingerprint = if gkf.is_empty() { None } else { Some(gkf) };
let t: Result<String, rusqlite::Error> = row.get(10);
let vkf: String = match t {
Err(_) => String::from(""),
Ok(res) => res,
};
res.verified_key_fingerprint = if vkf.is_empty() { None } else { Some(vkf) };
res.public_key_fingerprint = row.get(7)?;
if res
.public_key_fingerprint
.as_ref()
.map(|s| s.is_empty())
.unwrap_or_default()
{
res.public_key_fingerprint = None;
}
res.gossip_key_fingerprint = row.get(8)?;
if res
.gossip_key_fingerprint
.as_ref()
.map(|s| s.is_empty())
.unwrap_or_default()
{
res.gossip_key_fingerprint = None;
}
res.verified_key_fingerprint = row.get(10)?;
if res
.verified_key_fingerprint
.as_ref()
.map(|s| s.is_empty())
.unwrap_or_default()
{
res.verified_key_fingerprint = None;
}
res.public_key = row
.get(4)
.ok()
@@ -234,6 +242,7 @@ impl<'a> Peerstate<'a> {
.get(9)
.ok()
.and_then(|blob: Vec<u8>| Key::from_slice(&blob, KeyType::Public));
res.verified_key = if vk == res.gossip_key && res.gossip_key.is_some() {
VerifiedKey::Gossip
} else if vk == res.public_key {
@@ -417,10 +426,6 @@ impl<'a> Peerstate<'a> {
}
if self.to_save == Some(ToSave::All) || create {
info!(
self.context,
0, "update acpeerstates with peerstate {:?}", self
);
success = sql::execute(
self.context,
sql,