mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
refactor(peerstate): safe implementation of peerstate
This commit is contained in:
committed by
GitHub
parent
d926b3536d
commit
94aa314f30
@@ -3,7 +3,6 @@ use std::sync::{Arc, RwLock};
|
||||
|
||||
use deltachat::constants::*;
|
||||
use deltachat::dc_aheader::*;
|
||||
use deltachat::dc_apeerstate::*;
|
||||
use deltachat::dc_array::*;
|
||||
use deltachat::dc_chat::*;
|
||||
use deltachat::dc_chatlist::*;
|
||||
@@ -44,6 +43,7 @@ use deltachat::dc_strbuilder::*;
|
||||
use deltachat::dc_strencode::*;
|
||||
use deltachat::dc_token::*;
|
||||
use deltachat::dc_tools::*;
|
||||
use deltachat::peerstate::*;
|
||||
use deltachat::types::*;
|
||||
use deltachat::x::*;
|
||||
use num_traits::FromPrimitive;
|
||||
@@ -407,7 +407,6 @@ unsafe fn log_msglist(context: &dc_context_t, msglist: *mut dc_array_t) {
|
||||
}
|
||||
unsafe fn log_contactlist(context: &dc_context_t, contacts: *mut dc_array_t) {
|
||||
let mut contact: *mut dc_contact_t;
|
||||
let mut peerstate = dc_apeerstate_new(context);
|
||||
if !dc_array_search_id(contacts, 1i32 as uint32_t, 0 as *mut size_t) {
|
||||
dc_array_add_id(contacts, 1i32 as uint32_t);
|
||||
}
|
||||
@@ -444,29 +443,14 @@ unsafe fn log_contactlist(context: &dc_context_t, contacts: *mut dc_array_t) {
|
||||
b"addr unset\x00" as *const u8 as *const libc::c_char
|
||||
},
|
||||
);
|
||||
let peerstate_ok: libc::c_int = dc_apeerstate_load_by_addr(
|
||||
&mut peerstate,
|
||||
&context.sql.clone().read().unwrap(),
|
||||
addr,
|
||||
);
|
||||
if 0 != peerstate_ok && contact_id != 1i32 as libc::c_uint {
|
||||
let pe: *mut libc::c_char;
|
||||
match peerstate.prefer_encrypt {
|
||||
1 => pe = dc_strdup(b"mutual\x00" as *const u8 as *const libc::c_char),
|
||||
0 => pe = dc_strdup(b"no-preference\x00" as *const u8 as *const libc::c_char),
|
||||
20 => pe = dc_strdup(b"reset\x00" as *const u8 as *const libc::c_char),
|
||||
_ => {
|
||||
pe = dc_mprintf(
|
||||
b"unknown-value (%i)\x00" as *const u8 as *const libc::c_char,
|
||||
peerstate.prefer_encrypt,
|
||||
)
|
||||
}
|
||||
}
|
||||
let peerstate =
|
||||
Peerstate::from_addr(context, &context.sql.clone().read().unwrap(), to_str(addr));
|
||||
if peerstate.is_some() && contact_id != 1i32 as libc::c_uint {
|
||||
let pe = to_cstring(format!("{}", peerstate.as_ref().unwrap().prefer_encrypt));
|
||||
line2 = dc_mprintf(
|
||||
b", prefer-encrypt=%s\x00" as *const u8 as *const libc::c_char,
|
||||
pe,
|
||||
pe.as_ptr(),
|
||||
);
|
||||
free(pe as *mut libc::c_void);
|
||||
}
|
||||
dc_contact_unref(contact);
|
||||
free(name as *mut libc::c_void);
|
||||
@@ -488,8 +472,8 @@ unsafe fn log_contactlist(context: &dc_context_t, contacts: *mut dc_array_t) {
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
dc_apeerstate_unref(&mut peerstate);
|
||||
}
|
||||
|
||||
static mut s_is_auth: libc::c_int = 0i32;
|
||||
|
||||
pub unsafe fn dc_cmdline_skip_auth() {
|
||||
|
||||
Reference in New Issue
Block a user