mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
refactor(context): simpler info formatting
This commit is contained in:
170
src/context.rs
170
src/context.rs
@@ -607,41 +607,9 @@ unsafe fn get_config_keys_str() -> *mut libc::c_char {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
||||||
let unset = b"0\x00" as *const u8 as *const libc::c_char;
|
let unset = "0";
|
||||||
let displayname;
|
let l = dc_loginparam_new();
|
||||||
let temp;
|
let l2 = dc_loginparam_new();
|
||||||
let l_readable_str;
|
|
||||||
let l2_readable_str;
|
|
||||||
let fingerprint_str;
|
|
||||||
let l;
|
|
||||||
let l2;
|
|
||||||
let inbox_watch;
|
|
||||||
let sentbox_watch;
|
|
||||||
let mvbox_watch;
|
|
||||||
let mvbox_move;
|
|
||||||
let folders_configured;
|
|
||||||
let configured_sentbox_folder;
|
|
||||||
let configured_mvbox_folder;
|
|
||||||
let contacts;
|
|
||||||
let chats;
|
|
||||||
let real_msgs;
|
|
||||||
let deaddrop_msgs;
|
|
||||||
let is_configured;
|
|
||||||
let dbversion;
|
|
||||||
let mdns_enabled;
|
|
||||||
let e2ee_enabled;
|
|
||||||
let prv_key_cnt;
|
|
||||||
let pub_key_cnt;
|
|
||||||
|
|
||||||
let mut ret = dc_strbuilder_t {
|
|
||||||
buf: 0 as *mut libc::c_char,
|
|
||||||
allocated: 0,
|
|
||||||
free: 0,
|
|
||||||
eos: 0 as *mut libc::c_char,
|
|
||||||
};
|
|
||||||
dc_strbuilder_init(&mut ret, 0);
|
|
||||||
l = dc_loginparam_new();
|
|
||||||
l2 = dc_loginparam_new();
|
|
||||||
dc_loginparam_read(
|
dc_loginparam_read(
|
||||||
context,
|
context,
|
||||||
l,
|
l,
|
||||||
@@ -654,47 +622,47 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
|||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"configured_\x00" as *const u8 as *const libc::c_char,
|
b"configured_\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
displayname = dc_sqlite3_get_config(
|
let displayname = dc_sqlite3_get_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"displayname\x00" as *const u8 as *const libc::c_char,
|
b"displayname\x00" as *const u8 as *const libc::c_char,
|
||||||
0 as *const libc::c_char,
|
0 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
chats = dc_get_chat_cnt(context) as libc::c_int;
|
let chats = dc_get_chat_cnt(context) as usize;
|
||||||
real_msgs = dc_get_real_msg_cnt(context) as libc::c_int;
|
let real_msgs = dc_get_real_msg_cnt(context) as usize;
|
||||||
deaddrop_msgs = dc_get_deaddrop_msg_cnt(context) as libc::c_int;
|
let deaddrop_msgs = dc_get_deaddrop_msg_cnt(context) as usize;
|
||||||
contacts = dc_get_real_contact_cnt(context) as libc::c_int;
|
let contacts = dc_get_real_contact_cnt(context) as usize;
|
||||||
is_configured = dc_sqlite3_get_config_int(
|
let is_configured = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"configured\x00" as *const u8 as *const libc::c_char,
|
b"configured\x00" as *const u8 as *const libc::c_char,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
dbversion = dc_sqlite3_get_config_int(
|
let dbversion = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"dbversion\x00" as *const u8 as *const libc::c_char,
|
b"dbversion\x00" as *const u8 as *const libc::c_char,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
e2ee_enabled = dc_sqlite3_get_config_int(
|
let e2ee_enabled = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
|
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
mdns_enabled = dc_sqlite3_get_config_int(
|
let mdns_enabled = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
|
b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
|
let mut stmt = dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"SELECT COUNT(*) FROM keypairs;\x00" as *const u8 as *const libc::c_char,
|
b"SELECT COUNT(*) FROM keypairs;\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
sqlite3_step(stmt);
|
sqlite3_step(stmt);
|
||||||
prv_key_cnt = sqlite3_column_int(stmt, 0);
|
let prv_key_cnt = sqlite3_column_int(stmt, 0);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
stmt = dc_sqlite3_prepare(
|
stmt = dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
@@ -702,94 +670,93 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
|||||||
b"SELECT COUNT(*) FROM acpeerstates;\x00" as *const u8 as *const libc::c_char,
|
b"SELECT COUNT(*) FROM acpeerstates;\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
sqlite3_step(stmt);
|
sqlite3_step(stmt);
|
||||||
pub_key_cnt = sqlite3_column_int(stmt, 0);
|
let pub_key_cnt = sqlite3_column_int(stmt, 0);
|
||||||
sqlite3_finalize(stmt);
|
sqlite3_finalize(stmt);
|
||||||
if let Some(key) =
|
let fingerprint_str = if let Some(key) =
|
||||||
Key::from_self_public(context, (*l2).addr, &context.sql.clone().read().unwrap())
|
Key::from_self_public(context, (*l2).addr, &context.sql.clone().read().unwrap())
|
||||||
{
|
{
|
||||||
fingerprint_str = key.fingerprint_c();
|
key.fingerprint()
|
||||||
} else {
|
} else {
|
||||||
fingerprint_str =
|
"<Not yet calculated>".into()
|
||||||
dc_strdup(b"<Not yet calculated>\x00" as *const u8 as *const libc::c_char);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
l_readable_str = dc_loginparam_get_readable(l);
|
let l_readable_str = dc_loginparam_get_readable(l);
|
||||||
l2_readable_str = dc_loginparam_get_readable(l2);
|
let l2_readable_str = dc_loginparam_get_readable(l2);
|
||||||
inbox_watch = dc_sqlite3_get_config_int(
|
let inbox_watch = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"inbox_watch\x00" as *const u8 as *const libc::c_char,
|
b"inbox_watch\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
sentbox_watch = dc_sqlite3_get_config_int(
|
let sentbox_watch = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"sentbox_watch\x00" as *const u8 as *const libc::c_char,
|
b"sentbox_watch\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
mvbox_watch = dc_sqlite3_get_config_int(
|
let mvbox_watch = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"mvbox_watch\x00" as *const u8 as *const libc::c_char,
|
b"mvbox_watch\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
mvbox_move = dc_sqlite3_get_config_int(
|
let mvbox_move = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"mvbox_move\x00" as *const u8 as *const libc::c_char,
|
b"mvbox_move\x00" as *const u8 as *const libc::c_char,
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
folders_configured = dc_sqlite3_get_config_int(
|
let folders_configured = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"folders_configured\x00" as *const u8 as *const libc::c_char,
|
b"folders_configured\x00" as *const u8 as *const libc::c_char,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
configured_sentbox_folder = dc_sqlite3_get_config(
|
let configured_sentbox_folder = dc_sqlite3_get_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
|
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
|
||||||
b"<unset>\x00" as *const u8 as *const libc::c_char,
|
b"<unset>\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
configured_mvbox_folder = dc_sqlite3_get_config(
|
let configured_mvbox_folder = dc_sqlite3_get_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql.clone().read().unwrap(),
|
||||||
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
|
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
|
||||||
b"<unset>\x00" as *const u8 as *const libc::c_char,
|
b"<unset>\x00" as *const u8 as *const libc::c_char,
|
||||||
);
|
);
|
||||||
|
|
||||||
temp = dc_mprintf(
|
let res = format!(
|
||||||
b"deltachat_core_version=v%s\n\
|
"deltachat_core_version=v{}\n\
|
||||||
sqlite_version=%s\n\
|
sqlite_version={}\n\
|
||||||
sqlite_thread_safe=%i\n\
|
sqlite_thread_safe={}\n\
|
||||||
compile_date=Apr 26 2019, 00:51:50\n\
|
compile_date=Apr 26 2019, 00:51:50\n\
|
||||||
arch=%i\n\
|
arch={}\n\
|
||||||
number_of_chats=%i\n\
|
number_of_chats={}\n\
|
||||||
number_of_chat_messages=%i\n\
|
number_of_chat_messages={}\n\
|
||||||
messages_in_contact_requests=%i\n\
|
messages_in_contact_requests={}\n\
|
||||||
number_of_contacts=%i\n\
|
number_of_contacts={}\n\
|
||||||
database_dir=%s\n\
|
database_dir={}\n\
|
||||||
database_version=%i\n\
|
database_version={}\n\
|
||||||
blobdir=%s\n\
|
blobdir={}\n\
|
||||||
display_name=%s\n\
|
display_name={}\n\
|
||||||
is_configured=%i\n\
|
is_configured={}\n\
|
||||||
entered_account_settings=%s\n\
|
entered_account_settings={}\n\
|
||||||
used_account_settings=%s\n\
|
used_account_settings={}\n\
|
||||||
inbox_watch=%i\n\
|
inbox_watch={}\n\
|
||||||
sentbox_watch=%i\n\
|
sentbox_watch={}\n\
|
||||||
mvbox_watch=%i\n\
|
mvbox_watch={}\n\
|
||||||
mvbox_move=%i\n\
|
mvbox_move={}\n\
|
||||||
folders_configured=%i\n\
|
folders_configured={}\n\
|
||||||
configured_sentbox_folder=%s\n\
|
configured_sentbox_folder={}\n\
|
||||||
configured_mvbox_folder=%s\n\
|
configured_mvbox_folder={}\n\
|
||||||
mdns_enabled=%i\n\
|
mdns_enabled={}\n\
|
||||||
e2ee_enabled=%i\n\
|
e2ee_enabled={}\n\
|
||||||
private_key_count=%i\n\
|
private_key_count={}\n\
|
||||||
public_key_count=%i\n\
|
public_key_count={}\n\
|
||||||
fingerprint=%s\n\
|
fingerprint={}\n\
|
||||||
level=awesome\n\x00" as *const u8 as *const libc::c_char,
|
level=awesome\n",
|
||||||
VERSION as *const u8 as *const libc::c_char,
|
to_str(VERSION as *const u8 as *const _),
|
||||||
libsqlite3_sys::SQLITE_VERSION as *const u8 as *const libc::c_char,
|
to_str(libsqlite3_sys::SQLITE_VERSION as *const u8 as *const libc::c_char),
|
||||||
sqlite3_threadsafe(),
|
sqlite3_threadsafe(),
|
||||||
// arch
|
// arch
|
||||||
(::std::mem::size_of::<*mut libc::c_void>()).wrapping_mul(8),
|
(::std::mem::size_of::<*mut libc::c_void>()).wrapping_mul(8),
|
||||||
@@ -798,31 +765,31 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
|||||||
deaddrop_msgs,
|
deaddrop_msgs,
|
||||||
contacts,
|
contacts,
|
||||||
if context.has_dbfile() {
|
if context.has_dbfile() {
|
||||||
context.get_dbfile()
|
to_str(context.get_dbfile())
|
||||||
} else {
|
} else {
|
||||||
unset
|
unset
|
||||||
},
|
},
|
||||||
dbversion,
|
dbversion,
|
||||||
if context.has_blobdir() {
|
if context.has_blobdir() {
|
||||||
context.get_blobdir()
|
to_str(context.get_blobdir())
|
||||||
} else {
|
} else {
|
||||||
unset
|
unset
|
||||||
},
|
},
|
||||||
if !displayname.is_null() {
|
if !displayname.is_null() {
|
||||||
displayname
|
to_str(displayname)
|
||||||
} else {
|
} else {
|
||||||
unset
|
unset
|
||||||
},
|
},
|
||||||
is_configured,
|
is_configured,
|
||||||
l_readable_str,
|
to_str(l_readable_str),
|
||||||
l2_readable_str,
|
to_str(l2_readable_str),
|
||||||
inbox_watch,
|
inbox_watch,
|
||||||
sentbox_watch,
|
sentbox_watch,
|
||||||
mvbox_watch,
|
mvbox_watch,
|
||||||
mvbox_move,
|
mvbox_move,
|
||||||
folders_configured,
|
folders_configured,
|
||||||
configured_sentbox_folder,
|
to_str(configured_sentbox_folder),
|
||||||
configured_mvbox_folder,
|
to_str(configured_mvbox_folder),
|
||||||
mdns_enabled,
|
mdns_enabled,
|
||||||
e2ee_enabled,
|
e2ee_enabled,
|
||||||
prv_key_cnt,
|
prv_key_cnt,
|
||||||
@@ -830,8 +797,6 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
|||||||
fingerprint_str,
|
fingerprint_str,
|
||||||
);
|
);
|
||||||
|
|
||||||
dc_strbuilder_cat(&mut ret, temp);
|
|
||||||
free(temp as *mut libc::c_void);
|
|
||||||
dc_loginparam_unref(l);
|
dc_loginparam_unref(l);
|
||||||
dc_loginparam_unref(l2);
|
dc_loginparam_unref(l2);
|
||||||
free(displayname as *mut libc::c_void);
|
free(displayname as *mut libc::c_void);
|
||||||
@@ -839,9 +804,8 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
|||||||
free(l2_readable_str as *mut libc::c_void);
|
free(l2_readable_str as *mut libc::c_void);
|
||||||
free(configured_sentbox_folder as *mut libc::c_void);
|
free(configured_sentbox_folder as *mut libc::c_void);
|
||||||
free(configured_mvbox_folder as *mut libc::c_void);
|
free(configured_mvbox_folder as *mut libc::c_void);
|
||||||
free(fingerprint_str as *mut libc::c_void);
|
|
||||||
|
|
||||||
ret.buf
|
strdup(to_cstring(res).as_ptr())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_get_version_str() -> *mut libc::c_char {
|
pub unsafe fn dc_get_version_str() -> *mut libc::c_char {
|
||||||
|
|||||||
Reference in New Issue
Block a user