Compare commits

..

5 Commits

5 changed files with 63 additions and 48 deletions

View File

@@ -76,6 +76,11 @@ 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()
@@ -106,6 +111,10 @@ 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);
@@ -585,6 +594,7 @@ 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,6 +6,8 @@ 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)]
@@ -169,15 +171,14 @@ pub unsafe fn dc_lot_fill(
}
}
let message_text = (*msg).text.as_ref().unwrap();
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());
(*lot).text2 = dc_msg_get_summarytext_by_raw(
(*msg).type_0,
message_text.strdup(),
&mut (*msg).param,
160,
context,
);
(*lot).text2 =
dc_msg_get_summarytext_by_raw((*msg).type_0, msgtext_ptr, &mut (*msg).param, 160, context);
(*lot).timestamp = dc_msg_get_timestamp(msg);
(*lot).state = (*msg).state;

View File

@@ -1041,6 +1041,11 @@ 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 mut ok_to_continue = true;
let current_block: u64;
let ret: *mut dc_lot_t = dc_lot_new();
let mut chat_to_delete: *mut Chat = 0 as *mut Chat;
@@ -794,23 +794,27 @@ 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;
ok_to_continue = false;
current_block = 7815301370352969686;
}
} else {
ok_to_continue = false;
current_block = 7815301370352969686;
}
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
};
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
};
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,6 +166,7 @@ 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])
}
@@ -187,6 +188,7 @@ impl<'a> Peerstate<'a> {
P: IntoIterator,
P::Item: rusqlite::ToSql,
{
info!(context, 0, "from_stmt query {:?}", query);
context
.sql
.query_row(query, params, |row| {
@@ -198,38 +200,28 @@ 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()
@@ -242,7 +234,6 @@ 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 {
@@ -426,6 +417,10 @@ 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,