mirror of
https://github.com/chatmail/core.git
synced 2026-04-29 03:16:29 +03:00
refactor: rename dc_sqlite3 to sql
This commit is contained in:
@@ -11,12 +11,12 @@ use crate::dc_lot::dc_lot_t;
|
||||
use crate::dc_move::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_receive_imf::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::imap::*;
|
||||
use crate::key::*;
|
||||
use crate::smtp::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -68,7 +68,7 @@ pub struct Context {
|
||||
pub userdata: *mut libc::c_void,
|
||||
pub dbfile: Arc<RwLock<*mut libc::c_char>>,
|
||||
pub blobdir: Arc<RwLock<*mut libc::c_char>>,
|
||||
pub sql: SQLite,
|
||||
pub sql: Sql,
|
||||
pub inbox: Arc<RwLock<Imap>>,
|
||||
pub perform_inbox_jobs_needed: Arc<RwLock<i32>>,
|
||||
pub probe_imap_network: Arc<RwLock<i32>>,
|
||||
@@ -192,7 +192,7 @@ pub fn dc_context_new(
|
||||
cb,
|
||||
os_name: unsafe { dc_strdup_keep_null(os_name) },
|
||||
running_state: Arc::new(RwLock::new(Default::default())),
|
||||
sql: SQLite::new(),
|
||||
sql: Sql::new(),
|
||||
smtp: Arc::new(Mutex::new(Smtp::new())),
|
||||
smtp_state: Arc::new((Mutex::new(Default::default()), Condvar::new())),
|
||||
oauth2_critical: Arc::new(Mutex::new(())),
|
||||
@@ -304,7 +304,7 @@ unsafe fn cb_set_config(context: &Context, key: *const libc::c_char, value: *con
|
||||
} else {
|
||||
Some(as_str(value))
|
||||
};
|
||||
dc_sqlite3_set_config(context, &context.sql, as_str(key), v);
|
||||
sql::set_config(context, &context.sql, as_str(key), v);
|
||||
}
|
||||
|
||||
/* *
|
||||
@@ -324,7 +324,7 @@ unsafe fn cb_get_config(
|
||||
} else {
|
||||
Some(as_str(def))
|
||||
};
|
||||
let res = dc_sqlite3_get_config(context, &context.sql, as_str(key), d);
|
||||
let res = sql::get_config(context, &context.sql, as_str(key), d);
|
||||
if let Some(res) = res {
|
||||
strdup(to_cstring(res).as_ptr())
|
||||
} else {
|
||||
@@ -423,20 +423,20 @@ pub fn dc_set_config(context: &Context, key: impl AsRef<str>, value: Option<&str
|
||||
"selfavatar" if value.is_some() => {
|
||||
let mut rel_path = unsafe { dc_strdup(to_cstring(value.unwrap()).as_ptr()) };
|
||||
if 0 != unsafe { dc_make_rel_and_copy(context, &mut rel_path) } {
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, Some(as_str(rel_path)));
|
||||
ret = sql::set_config(context, &context.sql, key, Some(as_str(rel_path)));
|
||||
}
|
||||
unsafe { free(rel_path as *mut libc::c_void) };
|
||||
}
|
||||
"inbox_watch" => {
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, value);
|
||||
ret = sql::set_config(context, &context.sql, key, value);
|
||||
unsafe { dc_interrupt_imap_idle(context) };
|
||||
}
|
||||
"sentbox_watch" => {
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, value);
|
||||
ret = sql::set_config(context, &context.sql, key, value);
|
||||
unsafe { dc_interrupt_sentbox_idle(context) };
|
||||
}
|
||||
"mvbox_watch" => {
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, value);
|
||||
ret = sql::set_config(context, &context.sql, key, value);
|
||||
unsafe { dc_interrupt_mvbox_idle(context) };
|
||||
}
|
||||
"selfstatus" => {
|
||||
@@ -447,11 +447,11 @@ pub fn dc_set_config(context: &Context, key: impl AsRef<str>, value: Option<&str
|
||||
value
|
||||
};
|
||||
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, val);
|
||||
ret = sql::set_config(context, &context.sql, key, val);
|
||||
unsafe { free(def as *mut libc::c_void) };
|
||||
}
|
||||
_ => {
|
||||
ret = dc_sqlite3_set_config(context, &context.sql, key, value);
|
||||
ret = sql::set_config(context, &context.sql, key, value);
|
||||
}
|
||||
}
|
||||
ret
|
||||
@@ -479,7 +479,7 @@ pub fn dc_get_config(context: &Context, key: impl AsRef<str>) -> String {
|
||||
|
||||
let value = match key.as_ref() {
|
||||
"selfavatar" => {
|
||||
let rel_path = dc_sqlite3_get_config(context, &context.sql, key.as_ref(), None);
|
||||
let rel_path = sql::get_config(context, &context.sql, key.as_ref(), None);
|
||||
rel_path.map(|p| {
|
||||
let v = unsafe { dc_get_abs_path(context, to_cstring(p).as_ptr()) };
|
||||
let r = to_string(v);
|
||||
@@ -487,7 +487,7 @@ pub fn dc_get_config(context: &Context, key: impl AsRef<str>) -> String {
|
||||
r
|
||||
})
|
||||
}
|
||||
_ => dc_sqlite3_get_config(context, &context.sql, key.as_ref(), None),
|
||||
_ => sql::get_config(context, &context.sql, key.as_ref(), None),
|
||||
};
|
||||
|
||||
if value.is_some() {
|
||||
@@ -539,17 +539,17 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
||||
let unset = "0";
|
||||
let l = dc_loginparam_read(context, &context.sql, "");
|
||||
let l2 = dc_loginparam_read(context, &context.sql, "configured_");
|
||||
let displayname = dc_sqlite3_get_config(context, &context.sql, "displayname", None);
|
||||
let displayname = sql::get_config(context, &context.sql, "displayname", None);
|
||||
let chats = dc_get_chat_cnt(context) as usize;
|
||||
let real_msgs = dc_get_real_msg_cnt(context) as usize;
|
||||
let deaddrop_msgs = dc_get_deaddrop_msg_cnt(context) as usize;
|
||||
let contacts = dc_get_real_contact_cnt(context) as usize;
|
||||
let is_configured = dc_sqlite3_get_config_int(context, &context.sql, "configured", 0);
|
||||
let dbversion = dc_sqlite3_get_config_int(context, &context.sql, "dbversion", 0);
|
||||
let e2ee_enabled = dc_sqlite3_get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
let mdns_enabled = dc_sqlite3_get_config_int(context, &context.sql, "mdns_enabled", 1);
|
||||
let is_configured = sql::get_config_int(context, &context.sql, "configured", 0);
|
||||
let dbversion = sql::get_config_int(context, &context.sql, "dbversion", 0);
|
||||
let e2ee_enabled = sql::get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
let mdns_enabled = sql::get_config_int(context, &context.sql, "mdns_enabled", 1);
|
||||
|
||||
let prv_key_cnt: Option<isize> = dc_sqlite3_query_row(
|
||||
let prv_key_cnt: Option<isize> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM keypairs;",
|
||||
@@ -557,7 +557,7 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
||||
0,
|
||||
);
|
||||
|
||||
let pub_key_cnt: Option<isize> = dc_sqlite3_query_row(
|
||||
let pub_key_cnt: Option<isize> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM acpeerstates;",
|
||||
@@ -574,19 +574,18 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
|
||||
|
||||
let l_readable_str = dc_loginparam_get_readable(&l);
|
||||
let l2_readable_str = dc_loginparam_get_readable(&l2);
|
||||
let inbox_watch = dc_sqlite3_get_config_int(context, &context.sql, "inbox_watch", 1);
|
||||
let sentbox_watch = dc_sqlite3_get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
let mvbox_watch = dc_sqlite3_get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
let mvbox_move = dc_sqlite3_get_config_int(context, &context.sql, "mvbox_move", 1);
|
||||
let folders_configured =
|
||||
dc_sqlite3_get_config_int(context, &context.sql, "folders_configured", 0);
|
||||
let configured_sentbox_folder = dc_sqlite3_get_config(
|
||||
let inbox_watch = sql::get_config_int(context, &context.sql, "inbox_watch", 1);
|
||||
let sentbox_watch = sql::get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
let mvbox_watch = sql::get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
let mvbox_move = sql::get_config_int(context, &context.sql, "mvbox_move", 1);
|
||||
let folders_configured = sql::get_config_int(context, &context.sql, "folders_configured", 0);
|
||||
let configured_sentbox_folder = sql::get_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured_sentbox_folder",
|
||||
Some("<unset>"),
|
||||
);
|
||||
let configured_mvbox_folder = dc_sqlite3_get_config(
|
||||
let configured_mvbox_folder = sql::get_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured_mvbox_folder",
|
||||
@@ -753,8 +752,7 @@ pub fn dc_is_inbox(_context: &Context, folder_name: impl AsRef<str>) -> bool {
|
||||
}
|
||||
|
||||
pub fn dc_is_sentbox(context: &Context, folder_name: impl AsRef<str>) -> bool {
|
||||
let sentbox_name =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_sentbox_folder", None);
|
||||
let sentbox_name = sql::get_config(context, &context.sql, "configured_sentbox_folder", None);
|
||||
if let Some(name) = sentbox_name {
|
||||
name == folder_name.as_ref()
|
||||
} else {
|
||||
@@ -763,7 +761,7 @@ pub fn dc_is_sentbox(context: &Context, folder_name: impl AsRef<str>) -> bool {
|
||||
}
|
||||
|
||||
pub fn dc_is_mvbox(context: &Context, folder_name: impl AsRef<str>) -> bool {
|
||||
let mvbox_name = dc_sqlite3_get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
let mvbox_name = sql::get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
|
||||
if let Some(name) = mvbox_name {
|
||||
name == folder_name.as_ref()
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::dc_contact::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -101,7 +101,7 @@ pub unsafe fn dc_unblock_chat(context: &Context, chat_id: uint32_t) {
|
||||
}
|
||||
|
||||
pub fn dc_block_chat(context: &Context, chat_id: u32, new_blocking: libc::c_int) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET blocked=? WHERE id=?;",
|
||||
@@ -257,7 +257,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
|
||||
(*contact).addr
|
||||
};
|
||||
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO chats (type, name, param, blocked, grpid) VALUES(?, ?, ?, ?, ?)",
|
||||
@@ -269,7 +269,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
|
||||
as_str((*contact).addr),
|
||||
],
|
||||
) {
|
||||
chat_id = dc_sqlite3_get_rowid(
|
||||
chat_id = sql::get_rowid(
|
||||
context,
|
||||
&context.sql,
|
||||
"chats",
|
||||
@@ -277,7 +277,7 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
|
||||
as_str((*contact).addr),
|
||||
);
|
||||
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)",
|
||||
@@ -476,7 +476,7 @@ unsafe fn prepare_msg_raw(
|
||||
"Cannot send message; self not in group.",
|
||||
);
|
||||
} else {
|
||||
let from = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let from = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
if from.is_none() {
|
||||
error!(context, 0, "Cannot send message, not configured.",);
|
||||
} else {
|
||||
@@ -491,7 +491,7 @@ unsafe fn prepare_msg_raw(
|
||||
);
|
||||
|
||||
if (*chat).type_0 == 100 {
|
||||
if let Some(id) = dc_sqlite3_query_row(
|
||||
if let Some(id) = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT contact_id FROM chats_contacts WHERE chat_id=?;",
|
||||
@@ -526,8 +526,7 @@ unsafe fn prepare_msg_raw(
|
||||
so that E2EE is no longer available at a later point (reset, changed settings),
|
||||
we do not send the message out at all */
|
||||
do_guarantee_e2ee = 0;
|
||||
e2ee_enabled =
|
||||
dc_sqlite3_get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
e2ee_enabled = sql::get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
if 0 != e2ee_enabled && dc_param_get_int((*msg).param, 'u' as i32, 0) == 0 {
|
||||
let mut can_encrypt: libc::c_int = 1;
|
||||
let mut all_mutual: libc::c_int = 1;
|
||||
@@ -633,7 +632,7 @@ unsafe fn prepare_msg_raw(
|
||||
// add independent location to database
|
||||
|
||||
if 0 != dc_param_exists((*msg).param, DC_PARAM_SET_LATITUDE as libc::c_int) {
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO locations \
|
||||
@@ -655,7 +654,7 @@ unsafe fn prepare_msg_raw(
|
||||
),
|
||||
],
|
||||
) {
|
||||
location_id = dc_sqlite3_get_rowid2(
|
||||
location_id = sql::get_rowid2(
|
||||
context,
|
||||
&context.sql,
|
||||
"locations",
|
||||
@@ -669,7 +668,7 @@ unsafe fn prepare_msg_raw(
|
||||
|
||||
// add message to the database
|
||||
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO msgs (rfc724_mid, chat_id, from_id, to_id, timestamp, type, state, txt, param, hidden, mime_in_reply_to, mime_references, location_id) VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?);",
|
||||
@@ -689,7 +688,7 @@ unsafe fn prepare_msg_raw(
|
||||
location_id as i32,
|
||||
]
|
||||
) {
|
||||
msg_id = dc_sqlite3_get_rowid(
|
||||
msg_id = sql::get_rowid(
|
||||
context,
|
||||
&context.sql,
|
||||
"msgs",
|
||||
@@ -788,11 +787,11 @@ pub unsafe fn dc_chat_is_self_talk(chat: *const Chat) -> libc::c_int {
|
||||
// TODO should return bool /rtn
|
||||
unsafe fn last_msg_in_chat_encrypted(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
chat_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
let mut last_is_encrypted: libc::c_int = 0i32;
|
||||
let packed: Option<String> = dc_sqlite3_query_row(
|
||||
let packed: Option<String> = sql::query_row(
|
||||
context,
|
||||
sql,
|
||||
"SELECT param \
|
||||
@@ -818,7 +817,7 @@ unsafe fn last_msg_in_chat_encrypted(
|
||||
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_chat_update_param(chat: *mut Chat) -> libc::c_int {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
(*chat).context,
|
||||
&(*chat).context.sql,
|
||||
"UPDATE chats SET param=? WHERE id=?",
|
||||
@@ -844,7 +843,7 @@ pub unsafe fn dc_is_contact_in_chat(
|
||||
}
|
||||
|
||||
pub fn dc_unarchive_chat(context: &Context, chat_id: u32) {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET archived=0 WHERE id=?",
|
||||
@@ -980,7 +979,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
match current_block {
|
||||
14513523936503887211 => {}
|
||||
_ => {
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO msgs (chat_id, from_id, timestamp, type, state, txt, param, hidden) \
|
||||
@@ -1006,7 +1005,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
}
|
||||
|
||||
fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 {
|
||||
let draft_msg_id: i32 = dc_sqlite3_query_row(
|
||||
let draft_msg_id: i32 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
|
||||
@@ -1070,7 +1069,7 @@ pub unsafe fn dc_get_chat_msgs(
|
||||
};
|
||||
|
||||
let success = if chat_id == 1 {
|
||||
let show_emails = dc_sqlite3_get_config_int(context, &context.sql, "show_emails", 0);
|
||||
let show_emails = sql::get_config_int(context, &context.sql, "show_emails", 0);
|
||||
context.sql.query_map(
|
||||
"SELECT m.id, m.timestamp FROM msgs m \
|
||||
LEFT JOIN chats ON m.chat_id=chats.id \
|
||||
@@ -1119,7 +1118,7 @@ pub unsafe fn dc_get_chat_msgs(
|
||||
}
|
||||
|
||||
pub fn dc_get_msg_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM msgs WHERE chat_id=?;",
|
||||
@@ -1130,7 +1129,7 @@ pub fn dc_get_msg_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
||||
}
|
||||
|
||||
pub fn dc_get_fresh_msg_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM msgs \
|
||||
@@ -1154,7 +1153,7 @@ pub fn dc_marknoticed_chat(context: &Context, chat_id: u32) -> bool {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs \
|
||||
@@ -1180,7 +1179,7 @@ pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs \
|
||||
@@ -1286,7 +1285,7 @@ pub fn dc_archive_chat(context: &Context, chat_id: u32, archive: libc::c_int) ->
|
||||
return true;
|
||||
}
|
||||
if 0 != archive {
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET state=13 WHERE chat_id=? AND state=10;",
|
||||
@@ -1295,7 +1294,7 @@ pub fn dc_archive_chat(context: &Context, chat_id: u32, archive: libc::c_int) ->
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET archived=? WHERE id=?;",
|
||||
@@ -1320,7 +1319,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
|
||||
}
|
||||
unsafe { dc_chat_unref(obj) };
|
||||
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?);",
|
||||
@@ -1328,7 +1327,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM msgs WHERE chat_id=?;",
|
||||
@@ -1336,7 +1335,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats_contacts WHERE chat_id=?;",
|
||||
@@ -1344,7 +1343,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats WHERE id=?;",
|
||||
@@ -1421,7 +1420,7 @@ pub unsafe fn dc_create_group_chat(
|
||||
let draft_txt = dc_stock_str_repl_string(context, 14, chat_name);
|
||||
let grpid = as_str(dc_create_id());
|
||||
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO chats (type, name, grpid, param) VALUES(?, ?, ?, \'U=1\');",
|
||||
@@ -1431,7 +1430,7 @@ pub unsafe fn dc_create_group_chat(
|
||||
grpid
|
||||
],
|
||||
) {
|
||||
chat_id = dc_sqlite3_get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
||||
chat_id = sql::get_rowid(context, &context.sql, "chats", "grpid", grpid);
|
||||
if chat_id != 0 {
|
||||
if 0 != dc_add_to_chat_contacts_table(context, chat_id, 1) {
|
||||
let draft_msg = dc_msg_new(context, 10);
|
||||
@@ -1461,7 +1460,7 @@ pub fn dc_add_to_chat_contacts_table(
|
||||
) -> libc::c_int {
|
||||
// add a contact to a chat; the function does not check the type or if any of the record exist or are already
|
||||
// added to the chat!
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO chats_contacts (chat_id, contact_id) VALUES(?, ?)",
|
||||
@@ -1510,9 +1509,8 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
||||
dc_param_set((*chat).param, 'U' as i32, 0 as *const libc::c_char);
|
||||
dc_chat_update_param(chat);
|
||||
}
|
||||
let self_addr =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
if as_str((*contact).addr) != &self_addr {
|
||||
// ourself is added using DC_CONTACT_ID_SELF, do not add it explicitly.
|
||||
// if SELF is not in the group, members cannot be added at all.
|
||||
@@ -1619,7 +1617,7 @@ pub fn dc_set_gossiped_timestamp(context: &Context, chat_id: u32, timestamp: i64
|
||||
0, "set gossiped_timestamp for chat #{} to {}.", chat_id, timestamp,
|
||||
);
|
||||
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET gossiped_timestamp=? WHERE id=?;",
|
||||
@@ -1630,7 +1628,7 @@ pub fn dc_set_gossiped_timestamp(context: &Context, chat_id: u32, timestamp: i64
|
||||
context,
|
||||
0, "set gossiped_timestamp for all chats to {}.", timestamp,
|
||||
);
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET gossiped_timestamp=?;",
|
||||
@@ -1696,7 +1694,7 @@ pub unsafe fn dc_remove_contact_from_chat(
|
||||
);
|
||||
}
|
||||
}
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats_contacts WHERE chat_id=? AND contact_id=?;",
|
||||
@@ -1718,7 +1716,7 @@ pub unsafe fn dc_remove_contact_from_chat(
|
||||
|
||||
pub fn dc_set_group_explicitly_left(context: &Context, grpid: *const libc::c_char) {
|
||||
if 0 == dc_is_group_explicitly_left(context, grpid) {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO leftgrps (grpid) VALUES(?);",
|
||||
@@ -1765,7 +1763,7 @@ pub unsafe fn dc_set_chat_name(
|
||||
);
|
||||
} else {
|
||||
/* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET name=? WHERE id={};",
|
||||
@@ -2025,7 +2023,7 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
|
||||
if (*chat).type_0 == 100 && 0 != dc_param_exists((*chat).param, 'K' as i32) {
|
||||
ret = dc_stock_str((*chat).context, 50)
|
||||
} else if (*chat).type_0 == 100 {
|
||||
let ret_raw: String = dc_sqlite3_query_row(
|
||||
let ret_raw: String = sql::query_row(
|
||||
(*chat).context,
|
||||
&(*chat).context.sql,
|
||||
"SELECT c.addr FROM chats_contacts cc \
|
||||
@@ -2052,7 +2050,7 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
|
||||
}
|
||||
|
||||
pub fn dc_get_chat_contact_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM chats_contacts WHERE chat_id=?;",
|
||||
@@ -2150,7 +2148,7 @@ pub unsafe fn dc_chat_is_sending_locations(chat: *const Chat) -> libc::c_int {
|
||||
pub fn dc_get_chat_cnt(context: &Context) -> usize {
|
||||
if context.sql.is_open() {
|
||||
/* no database, no chats - this is no error (needed eg. for information) */
|
||||
dc_sqlite3_query_row::<_, isize>(
|
||||
sql::query_row::<_, isize>(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM chats WHERE id>9 AND blocked=0;",
|
||||
@@ -2224,7 +2222,7 @@ pub fn dc_add_device_msg(context: &Context, chat_id: uint32_t, text: *const libc
|
||||
return;
|
||||
}
|
||||
|
||||
let msg_id = dc_sqlite3_get_rowid(
|
||||
let msg_id = sql::get_rowid(
|
||||
context,
|
||||
&context.sql,
|
||||
"msgs",
|
||||
|
||||
@@ -4,9 +4,9 @@ use crate::dc_chat::*;
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_lot::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -243,7 +243,7 @@ unsafe fn dc_chatlist_load_from_db(
|
||||
|
||||
// Context functions to work with chatlist
|
||||
pub fn dc_get_archived_cnt(context: &Context) -> libc::c_int {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;",
|
||||
@@ -255,7 +255,7 @@ pub fn dc_get_archived_cnt(context: &Context) -> libc::c_int {
|
||||
|
||||
fn get_last_deaddrop_fresh_msg(context: &Context) -> u32 {
|
||||
// we have an index over the state-column, this should be sufficient as there are typically only few fresh messages
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \
|
||||
|
||||
@@ -6,10 +6,10 @@ use crate::dc_e2ee::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_saxparser::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::imap::*;
|
||||
use crate::oauth2::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -75,7 +75,7 @@ pub unsafe fn dc_has_ongoing(context: &Context) -> libc::c_int {
|
||||
}
|
||||
}
|
||||
pub fn dc_is_configured(context: &Context) -> libc::c_int {
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "configured", 0) > 0 {
|
||||
if sql::get_config_int(context, &context.sql, "configured", 0) > 0 {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
@@ -168,7 +168,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
|
||||
.and_then(|e| e.parse().ok())
|
||||
{
|
||||
param.addr = oauth2_addr;
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"addr",
|
||||
@@ -904,7 +904,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
|
||||
=
|
||||
if 0
|
||||
!=
|
||||
dc_sqlite3_get_config_int(
|
||||
sql::get_config_int(
|
||||
context, &context.sql,
|
||||
"mvbox_watch",
|
||||
1
|
||||
@@ -912,7 +912,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
|
||||
||
|
||||
0
|
||||
!=
|
||||
dc_sqlite3_get_config_int(
|
||||
sql::get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"mvbox_move",
|
||||
@@ -959,12 +959,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
|
||||
&context.sql,
|
||||
"configured_",
|
||||
);
|
||||
dc_sqlite3_set_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured",
|
||||
1,
|
||||
);
|
||||
sql::set_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured",
|
||||
1,
|
||||
);
|
||||
if !s.shall_stop_ongoing
|
||||
{
|
||||
context.call_cb(
|
||||
@@ -1489,7 +1489,7 @@ pub fn dc_connect_to_configured_imap(context: &Context, imap: &Imap) -> libc::c_
|
||||
|
||||
if imap.is_connected() {
|
||||
ret_connected = 1
|
||||
} else if dc_sqlite3_get_config_int(context, &context.sql, "configured", 0) == 0 {
|
||||
} else if sql::get_config_int(context, &context.sql, "configured", 0) == 0 {
|
||||
warn!(context, 0, "Not configured, cannot connect.",);
|
||||
} else {
|
||||
let param = dc_loginparam_read(context, &context.sql, "configured_");
|
||||
|
||||
@@ -5,11 +5,11 @@ use crate::context::*;
|
||||
use crate::dc_array::*;
|
||||
use crate::dc_e2ee::*;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::key::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -29,7 +29,7 @@ pub struct dc_contact_t<'a> {
|
||||
}
|
||||
|
||||
pub fn dc_marknoticed_contact(context: &Context, contact_id: u32) {
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET state=13 WHERE from_id=? AND state=10;",
|
||||
@@ -71,12 +71,12 @@ pub unsafe fn dc_lookup_contact_id_by_addr(
|
||||
let addr_normalized_c = dc_addr_normalize(addr);
|
||||
let addr_normalized = as_str(addr_normalized_c);
|
||||
let addr_self =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", None).unwrap_or_default();
|
||||
sql::get_config(context, &context.sql, "configured_addr", None).unwrap_or_default();
|
||||
|
||||
let contact_id = if addr_normalized == addr_self {
|
||||
1
|
||||
} else {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT id FROM contacts WHERE addr=?1 COLLATE NOCASE AND id>?2 AND origin>=?3 AND blocked=0;",
|
||||
@@ -155,7 +155,7 @@ pub unsafe fn dc_block_contact(context: &Context, contact_id: uint32_t, new_bloc
|
||||
if dc_contact_load_from_db(contact, &context.sql, contact_id)
|
||||
&& (*contact).blocked != new_blocking
|
||||
{
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE contacts SET blocked=? WHERE id=?;",
|
||||
@@ -166,7 +166,7 @@ pub unsafe fn dc_block_contact(context: &Context, contact_id: uint32_t, new_bloc
|
||||
// (Maybe, beside normal chats (type=100) we should also block group chats with only this user.
|
||||
// However, I'm not sure about this point; it may be confusing if the user wants to add other people;
|
||||
// this would result in recreating the same group...)
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET blocked=? WHERE type=? AND id IN (SELECT chat_id FROM chats_contacts WHERE contact_id=?);",
|
||||
@@ -260,7 +260,7 @@ pub unsafe fn dc_contact_empty(mut contact: *mut dc_contact_t) {
|
||||
/* contacts with at least this origin value start a new "normal" chat, defaults to off */
|
||||
pub unsafe fn dc_contact_load_from_db(
|
||||
contact: *mut dc_contact_t,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
contact_id: u32,
|
||||
) -> bool {
|
||||
if contact.is_null() || (*contact).magic != 0xc047ac7i32 as libc::c_uint {
|
||||
@@ -274,7 +274,7 @@ pub unsafe fn dc_contact_load_from_db(
|
||||
(*contact).name = dc_stock_str((*contact).context, 2);
|
||||
(*contact).addr = dc_strdup(
|
||||
to_cstring(
|
||||
dc_sqlite3_get_config((*contact).context, sql, "configured_addr", Some(""))
|
||||
sql::get_config((*contact).context, sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.as_ptr(),
|
||||
@@ -331,8 +331,8 @@ pub fn dc_add_or_lookup_contact(
|
||||
|
||||
let addr_c = unsafe { dc_addr_normalize(addr__) };
|
||||
let addr = as_str(addr_c);
|
||||
let addr_self = dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
let addr_self =
|
||||
sql::get_config(context, &context.sql, "configured_addr", Some("")).unwrap_or_default();
|
||||
|
||||
if addr == addr_self {
|
||||
return 1;
|
||||
@@ -388,7 +388,7 @@ pub fn dc_add_or_lookup_contact(
|
||||
update_addr = true;
|
||||
}
|
||||
if update_name || update_authname || update_addr || origin > row_origin {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;",
|
||||
@@ -414,7 +414,7 @@ pub fn dc_add_or_lookup_contact(
|
||||
);
|
||||
|
||||
if update_name {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET name=? WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?);",
|
||||
@@ -424,13 +424,13 @@ pub fn dc_add_or_lookup_contact(
|
||||
unsafe { *sth_modified = 1 };
|
||||
}
|
||||
} else {
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);",
|
||||
params![to_string(name), addr, origin,],
|
||||
) {
|
||||
row_id = dc_sqlite3_get_rowid(context, &context.sql, "contacts", "addr", addr);
|
||||
row_id = sql::get_rowid(context, &context.sql, "contacts", "addr", addr);
|
||||
unsafe { *sth_modified = 2 };
|
||||
} else {
|
||||
error!(context, 0, "Cannot add contact.");
|
||||
@@ -519,8 +519,8 @@ pub fn dc_get_contacts(
|
||||
listflags: u32,
|
||||
query: *const libc::c_char,
|
||||
) -> *mut dc_array_t {
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
let self_addr =
|
||||
sql::get_config(context, &context.sql, "configured_addr", Some("")).unwrap_or_default();
|
||||
|
||||
let mut add_self = false;
|
||||
let ret = unsafe { dc_array_new(100) };
|
||||
@@ -558,8 +558,8 @@ pub fn dc_get_contacts(
|
||||
)
|
||||
.unwrap(); // TODO: Better error handling
|
||||
|
||||
let self_name = dc_sqlite3_get_config(context, &context.sql, "displayname", Some(""))
|
||||
.unwrap_or_default();
|
||||
let self_name =
|
||||
sql::get_config(context, &context.sql, "displayname", Some("")).unwrap_or_default();
|
||||
|
||||
let self_name2 = unsafe { dc_stock_str(context, 2) };
|
||||
|
||||
@@ -595,7 +595,7 @@ pub fn dc_get_contacts(
|
||||
}
|
||||
|
||||
pub fn dc_get_blocked_cnt(context: &Context) -> libc::c_int {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM contacts WHERE id>? AND blocked!=0",
|
||||
@@ -757,7 +757,7 @@ pub fn dc_delete_contact(context: &Context, contact_id: u32) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
let count_contacts: i32 = dc_sqlite3_query_row(
|
||||
let count_contacts: i32 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;",
|
||||
@@ -767,7 +767,7 @@ pub fn dc_delete_contact(context: &Context, contact_id: u32) -> bool {
|
||||
.unwrap_or_default();
|
||||
|
||||
let count_msgs: i32 = if count_contacts > 0 {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM msgs WHERE from_id=? OR to_id=?;",
|
||||
@@ -780,7 +780,7 @@ pub fn dc_delete_contact(context: &Context, contact_id: u32) -> bool {
|
||||
};
|
||||
|
||||
if count_msgs > 0 {
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM contacts WHERE id=?;",
|
||||
@@ -974,9 +974,7 @@ pub fn dc_addr_equals_self(context: &Context, addr: *const libc::c_char) -> libc
|
||||
|
||||
if !addr.is_null() {
|
||||
let normalized_addr = unsafe { dc_addr_normalize(addr) };
|
||||
if let Some(self_addr) =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", None)
|
||||
{
|
||||
if let Some(self_addr) = sql::get_config(context, &context.sql, "configured_addr", None) {
|
||||
ret = (as_str(normalized_addr) == self_addr) as libc::c_int;
|
||||
}
|
||||
unsafe { free(normalized_addr as *mut libc::c_void) };
|
||||
@@ -1016,7 +1014,7 @@ pub fn dc_get_real_contact_cnt(context: &Context) -> usize {
|
||||
return 0;
|
||||
}
|
||||
|
||||
dc_sqlite3_query_row::<_, isize>(
|
||||
sql::query_row::<_, isize>(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM contacts WHERE id>?;",
|
||||
|
||||
@@ -19,12 +19,12 @@ use crate::aheader::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_mimeparser::*;
|
||||
use crate::dc_securejoin::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::key::*;
|
||||
use crate::keyring::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::pgp::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -81,14 +81,13 @@ pub unsafe fn dc_e2ee_encrypt(
|
||||
|| plain.is_null())
|
||||
{
|
||||
/* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */
|
||||
let prefer_encrypt =
|
||||
if 0 != dc_sqlite3_get_config_int(context, &context.sql, "e2ee_enabled", 1) {
|
||||
EncryptPreference::Mutual
|
||||
} else {
|
||||
EncryptPreference::NoPreference
|
||||
};
|
||||
let prefer_encrypt = if 0 != sql::get_config_int(context, &context.sql, "e2ee_enabled", 1) {
|
||||
EncryptPreference::Mutual
|
||||
} else {
|
||||
EncryptPreference::NoPreference
|
||||
};
|
||||
|
||||
let addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let addr = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
|
||||
if let Some(addr) = addr {
|
||||
if let Some(public_key) =
|
||||
@@ -598,7 +597,7 @@ pub unsafe fn dc_e2ee_decrypt(
|
||||
}
|
||||
}
|
||||
/* load private key for decryption */
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
if let Some(self_addr) = self_addr {
|
||||
if private_keyring.load_self_private_for_decrypting(context, self_addr, &context.sql) {
|
||||
if peerstate.as_ref().map(|p| p.last_seen).unwrap_or_else(|| 0) == 0 {
|
||||
@@ -1067,7 +1066,7 @@ pub unsafe fn dc_ensure_secret_key_exists(context: &Context) -> libc::c_int {
|
||||
(this is to gain some extra-random-seed by the message content and the timespan between program start and message sending) */
|
||||
let mut success: libc::c_int = 0i32;
|
||||
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
if self_addr.is_none() {
|
||||
warn!(
|
||||
context,
|
||||
|
||||
@@ -14,11 +14,11 @@ use crate::dc_e2ee::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::key::*;
|
||||
use crate::pgp::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -67,10 +67,10 @@ pub unsafe fn dc_imex_has_backup(
|
||||
let name = dirent.file_name();
|
||||
let name = name.to_string_lossy();
|
||||
if name.starts_with("delta-chat") && name.ends_with(".bak") {
|
||||
let sql = SQLite::new();
|
||||
let sql = Sql::new();
|
||||
if sql.open(context, &path, 0x1) {
|
||||
let curr_backup_time =
|
||||
dc_sqlite3_get_config_int(context, &sql, "backup_time", 0) as u64;
|
||||
sql::get_config_int(context, &sql, "backup_time", 0) as u64;
|
||||
if curr_backup_time > newest_backup_time {
|
||||
newest_backup_path = Some(path);
|
||||
newest_backup_time = curr_backup_time;
|
||||
@@ -223,10 +223,10 @@ pub unsafe extern "C" fn dc_render_setup_file(
|
||||
passphrase_begin[2usize] = 0i32 as libc::c_char;
|
||||
/* create the payload */
|
||||
if !(0 == dc_ensure_secret_key_exists(context)) {
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None)
|
||||
.unwrap_or_default();
|
||||
let self_addr =
|
||||
sql::get_config(context, &context.sql, "configured_addr", None).unwrap_or_default();
|
||||
let curr_private_key = Key::from_self_private(context, self_addr, &context.sql);
|
||||
let e2ee_enabled = dc_sqlite3_get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
let e2ee_enabled = sql::get_config_int(context, &context.sql, "e2ee_enabled", 1);
|
||||
|
||||
let headers = if 0 != e2ee_enabled {
|
||||
Some(("Autocrypt-Prefer-Encrypt", "mutual"))
|
||||
@@ -387,7 +387,7 @@ fn set_self_key(
|
||||
let (private_key, public_key, header) = keys.unwrap();
|
||||
let preferencrypt = header.get("Autocrypt-Prefer-Encrypt");
|
||||
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM keypairs WHERE public_key=? OR private_key=?;",
|
||||
@@ -397,7 +397,7 @@ fn set_self_key(
|
||||
}
|
||||
|
||||
if 0 != set_default {
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE keypairs SET is_default=0;",
|
||||
@@ -409,7 +409,7 @@ fn set_self_key(
|
||||
error!(context, 0, "File does not contain a private key.",);
|
||||
}
|
||||
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
|
||||
if self_addr.is_none() {
|
||||
error!(context, 0, "Missing self addr");
|
||||
@@ -430,8 +430,8 @@ fn set_self_key(
|
||||
|
||||
match preferencrypt.map(|s| s.as_str()) {
|
||||
Some("") => 0,
|
||||
Some("nopreference") => dc_sqlite3_set_config_int(context, &context.sql, "e2ee_enabled", 0),
|
||||
Some("mutual") => dc_sqlite3_set_config_int(context, &context.sql, "e2ee_enabled", 1),
|
||||
Some("nopreference") => sql::set_config_int(context, &context.sql, "e2ee_enabled", 0),
|
||||
Some("mutual") => sql::set_config_int(context, &context.sql, "e2ee_enabled", 1),
|
||||
_ => 1,
|
||||
}
|
||||
}
|
||||
@@ -781,7 +781,7 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
||||
return 0;
|
||||
}
|
||||
|
||||
let total_files_cnt = dc_sqlite3_query_row::<_, isize>(
|
||||
let total_files_cnt = sql::query_row::<_, isize>(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM backup_blobs;",
|
||||
@@ -859,8 +859,8 @@ unsafe fn import_backup(context: &Context, backup_to_import: *const libc::c_char
|
||||
if !loop_success {
|
||||
return Err(format_err!("fail").into());
|
||||
}
|
||||
dc_sqlite3_execute(context, &context.sql, "DROP TABLE backup_blobs;", params![]);
|
||||
dc_sqlite3_try_execute(context, &context.sql, "VACUUM;");
|
||||
sql::execute(context, &context.sql, "DROP TABLE backup_blobs;", params![]);
|
||||
sql::try_execute(context, &context.sql, "VACUUM;");
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
@@ -892,9 +892,9 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
return success;
|
||||
}
|
||||
|
||||
dc_housekeeping(context);
|
||||
sql::housekeeping(context);
|
||||
|
||||
dc_sqlite3_try_execute(context, &context.sql, "VACUUM;");
|
||||
sql::try_execute(context, &context.sql, "VACUUM;");
|
||||
context.sql.close(context);
|
||||
let mut closed = true;
|
||||
info!(
|
||||
@@ -909,10 +909,10 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
closed = false;
|
||||
/* add all files as blobs to the database copy (this does not require the source to be locked, neigher the destination as it is used only here) */
|
||||
/*for logging only*/
|
||||
let sql = SQLite::new();
|
||||
let sql = Sql::new();
|
||||
if sql.open(context, as_path(dest_pathNfilename), 0) {
|
||||
if !sql.table_exists("backup_blobs") {
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&sql,
|
||||
"CREATE TABLE backup_blobs (id INTEGER PRIMARY KEY, file_name, file_content);",
|
||||
@@ -1040,7 +1040,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
||||
match current_block {
|
||||
11487273724841241105 => {}
|
||||
_ => {
|
||||
if 0 != dc_sqlite3_set_config_int(
|
||||
if 0 != sql::set_config_int(
|
||||
context,
|
||||
&sql,
|
||||
"backup_time",
|
||||
|
||||
@@ -16,10 +16,10 @@ use crate::dc_loginparam::*;
|
||||
use crate::dc_mimefactory::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::imap::*;
|
||||
use crate::keyhistory::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -152,7 +152,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
|
||||
dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context, &mut job);
|
||||
}
|
||||
105 => {
|
||||
dc_housekeeping(context);
|
||||
sql::housekeeping(context);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ unsafe fn get_backoff_time_offset(c_tries: libc::c_int) -> i64 {
|
||||
}
|
||||
|
||||
fn dc_job_update(context: &Context, job: &dc_job_t) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE jobs SET desired_timestamp=?, tries=?, param=? WHERE id=?;",
|
||||
@@ -361,7 +361,7 @@ unsafe fn dc_job_do_DC_JOB_SEND(context: &Context, job: &mut dc_job_t) {
|
||||
dc_delete_file(context, filename);
|
||||
if 0 != job.foreign_id {
|
||||
dc_update_msg_state(context, job.foreign_id, 26i32);
|
||||
let chat_id: i32 = dc_sqlite3_query_row(
|
||||
let chat_id: i32 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT chat_id FROM msgs WHERE id=?",
|
||||
@@ -420,11 +420,11 @@ unsafe fn dc_job_do_DC_JOB_MOVE_MSG(context: &Context, job: &mut dc_job_t) {
|
||||
match current_block {
|
||||
2473556513754201174 => {
|
||||
if dc_msg_load_from_db(msg, context, job.foreign_id) {
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
if sql::get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
inbox.configure_folders(context, 0x1i32);
|
||||
}
|
||||
let dest_folder =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
sql::get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
|
||||
if let Some(dest_folder) = dest_folder {
|
||||
let server_folder = as_str((*msg).server_folder);
|
||||
@@ -516,11 +516,11 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context: &Context, job: &mut dc_
|
||||
dc_job_try_again_later(job, 3i32, 0 as *const libc::c_char);
|
||||
}
|
||||
if 0 != dc_param_get_int(job.param, 'M' as i32, 0i32) {
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
if sql::get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
inbox.configure_folders(context, 0x1i32);
|
||||
}
|
||||
let dest_folder =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
sql::get_config(context, &context.sql, "configured_mvbox_folder", None);
|
||||
if let Some(dest_folder) = dest_folder {
|
||||
if 1 == inbox.mv(context, folder, uid, dest_folder, &mut dest_uid)
|
||||
as libc::c_uint
|
||||
@@ -565,7 +565,7 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MSG_ON_IMAP(context: &Context, job: &mut dc_
|
||||
}
|
||||
_ => {
|
||||
if 0 != dc_param_get_int((*msg).param, 'r' as i32, 0i32)
|
||||
&& 0 != dc_sqlite3_get_config_int(
|
||||
&& 0 != sql::get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"mdns_enabled",
|
||||
@@ -621,7 +621,7 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MSG_ON_IMAP(context: &Context, job: &mut dc_
|
||||
}
|
||||
_ => {
|
||||
if 0 != dc_param_get_int((*msg).param, 'r' as i32, 0i32)
|
||||
&& 0 != dc_sqlite3_get_config_int(
|
||||
&& 0 != sql::get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"mdns_enabled",
|
||||
@@ -798,7 +798,7 @@ pub unsafe fn dc_job_add(
|
||||
return;
|
||||
};
|
||||
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO jobs (added_timestamp, thread, action, foreign_id, param, desired_timestamp) VALUES (?,?,?,?,?,?);",
|
||||
@@ -900,7 +900,7 @@ unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(context: &Context, job: &mut dc_jo
|
||||
|
||||
/* delete all pending jobs with the given action */
|
||||
pub fn dc_job_kill_action(context: &Context, action: libc::c_int) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM jobs WHERE action=?;",
|
||||
@@ -915,7 +915,7 @@ pub unsafe fn dc_perform_imap_fetch(context: &Context) {
|
||||
if 0 == connect_to_inbox(context, &inbox) {
|
||||
return;
|
||||
}
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "inbox_watch", 1) == 0 {
|
||||
if sql::get_config_int(context, &context.sql, "inbox_watch", 1) == 0 {
|
||||
info!(context, 0, "INBOX-watch disabled.",);
|
||||
return;
|
||||
}
|
||||
@@ -951,7 +951,7 @@ pub fn dc_perform_imap_idle(context: &Context) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_perform_mvbox_fetch(context: &Context) {
|
||||
let use_network = dc_sqlite3_get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
let use_network = sql::get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
dc_jobthread_fetch(
|
||||
context,
|
||||
&mut context.mvbox_thread.clone().write().unwrap(),
|
||||
@@ -960,7 +960,7 @@ pub unsafe fn dc_perform_mvbox_fetch(context: &Context) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_perform_mvbox_idle(context: &Context) {
|
||||
let use_network = dc_sqlite3_get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
let use_network = sql::get_config_int(context, &context.sql, "mvbox_watch", 1);
|
||||
|
||||
dc_jobthread_idle(
|
||||
context,
|
||||
@@ -974,7 +974,7 @@ pub unsafe fn dc_interrupt_mvbox_idle(context: &Context) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_perform_sentbox_fetch(context: &Context) {
|
||||
let use_network = dc_sqlite3_get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
let use_network = sql::get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
dc_jobthread_fetch(
|
||||
context,
|
||||
&mut context.sentbox_thread.clone().write().unwrap(),
|
||||
@@ -983,7 +983,7 @@ pub unsafe fn dc_perform_sentbox_fetch(context: &Context) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_perform_sentbox_idle(context: &Context) {
|
||||
let use_network = dc_sqlite3_get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
let use_network = sql::get_config_int(context, &context.sql, "sentbox_watch", 1);
|
||||
dc_jobthread_idle(
|
||||
context,
|
||||
&context.sentbox_thread.clone().read().unwrap(),
|
||||
@@ -1055,7 +1055,7 @@ pub unsafe fn dc_perform_smtp_idle(context: &Context) {
|
||||
}
|
||||
|
||||
unsafe fn get_next_wakeup_time(context: &Context, thread: libc::c_int) -> Duration {
|
||||
let t: i64 = dc_sqlite3_query_row(
|
||||
let t: i64 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT MIN(desired_timestamp) FROM jobs WHERE thread=?;",
|
||||
|
||||
@@ -2,8 +2,8 @@ use std::sync::{Arc, Condvar, Mutex};
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::dc_configure::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::imap::Imap;
|
||||
use crate::sql;
|
||||
use crate::x::*;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -137,11 +137,11 @@ unsafe fn connect_to_imap(context: &Context, jobthread: &dc_jobthread_t) -> libc
|
||||
} else {
|
||||
ret_connected = dc_connect_to_configured_imap(context, &jobthread.imap);
|
||||
if !(0 == ret_connected) {
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
if sql::get_config_int(context, &context.sql, "folders_configured", 0) < 3 {
|
||||
jobthread.imap.configure_folders(context, 0x1);
|
||||
}
|
||||
let mvbox_name =
|
||||
dc_sqlite3_get_config(context, &context.sql, jobthread.folder_config_name, None);
|
||||
sql::get_config(context, &context.sql, jobthread.folder_config_name, None);
|
||||
if let Some(name) = mvbox_name {
|
||||
jobthread.imap.set_watch_folder(name);
|
||||
} else {
|
||||
|
||||
@@ -6,9 +6,9 @@ use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_saxparser::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -48,7 +48,7 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
let is_sending_locations_before: bool;
|
||||
if !(seconds < 0i32 || chat_id <= 9i32 as libc::c_uint) {
|
||||
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id);
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats \
|
||||
@@ -244,7 +244,7 @@ unsafe fn is_marker(txt: *const libc::c_char) -> libc::c_int {
|
||||
}
|
||||
|
||||
pub fn dc_delete_all_locations(context: &Context) -> bool {
|
||||
if !dc_sqlite3_execute(context, &context.sql, "DELETE FROM locations;", params![]) {
|
||||
if !sql::execute(context, &context.sql, "DELETE FROM locations;", params![]) {
|
||||
return false;
|
||||
}
|
||||
context.call_cb(Event::LOCATION_CHANGED, 0, 0);
|
||||
@@ -261,7 +261,7 @@ pub fn dc_get_location_kml(
|
||||
let mut location_count: libc::c_int = 0;
|
||||
let mut ret = String::new();
|
||||
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""));
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", Some(""));
|
||||
|
||||
if self_addr.is_none() {
|
||||
return std::ptr::null_mut();
|
||||
@@ -380,7 +380,7 @@ pub unsafe fn dc_get_message_kml(
|
||||
}
|
||||
|
||||
pub fn dc_set_kml_sent_timestamp(context: &Context, chat_id: u32, timestamp: i64) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET locations_last_sent=? WHERE id=?;",
|
||||
@@ -389,7 +389,7 @@ pub fn dc_set_kml_sent_timestamp(context: &Context, chat_id: u32, timestamp: i64
|
||||
}
|
||||
|
||||
pub fn dc_set_msg_location_id(context: &Context, msg_id: u32, location_id: u32) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET location_id=? WHERE id=?;",
|
||||
@@ -438,7 +438,7 @@ pub unsafe fn dc_save_locations(
|
||||
|
||||
if (*location).timestamp > newest_timestamp {
|
||||
newest_timestamp = (*location).timestamp;
|
||||
newest_location_id = get_rowid2(
|
||||
newest_location_id = sql::get_rowid2_with_conn(
|
||||
context,
|
||||
conn,
|
||||
"locations",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::sql::{self, Sql};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct dc_loginparam_t {
|
||||
@@ -29,43 +29,43 @@ pub fn dc_loginparam_new() -> dc_loginparam_t {
|
||||
|
||||
pub fn dc_loginparam_read(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
prefix: impl AsRef<str>,
|
||||
) -> dc_loginparam_t {
|
||||
let prefix = prefix.as_ref();
|
||||
|
||||
let key = format!("{}addr", prefix);
|
||||
let addr = dc_sqlite3_get_config(context, sql, key, None)
|
||||
let addr = sql::get_config(context, sql, key, None)
|
||||
.unwrap_or_default()
|
||||
.trim()
|
||||
.to_string();
|
||||
|
||||
let key = format!("{}mail_server", prefix);
|
||||
let mail_server = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let mail_server = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}mail_port", prefix);
|
||||
let mail_port = dc_sqlite3_get_config_int(context, sql, key, 0);
|
||||
let mail_port = sql::get_config_int(context, sql, key, 0);
|
||||
|
||||
let key = format!("{}mail_user", prefix);
|
||||
let mail_user = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let mail_user = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}mail_pw", prefix);
|
||||
let mail_pw = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let mail_pw = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}send_server", prefix);
|
||||
let send_server = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let send_server = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}send_port", prefix);
|
||||
let send_port = dc_sqlite3_get_config_int(context, sql, key, 0);
|
||||
let send_port = sql::get_config_int(context, sql, key, 0);
|
||||
|
||||
let key = format!("{}send_user", prefix);
|
||||
let send_user = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let send_user = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}send_pw", prefix);
|
||||
let send_pw = dc_sqlite3_get_config(context, sql, key, None).unwrap_or_default();
|
||||
let send_pw = sql::get_config(context, sql, key, None).unwrap_or_default();
|
||||
|
||||
let key = format!("{}server_flags", prefix);
|
||||
let server_flags = dc_sqlite3_get_config_int(context, sql, key, 0);
|
||||
let server_flags = sql::get_config_int(context, sql, key, 0);
|
||||
|
||||
dc_loginparam_t {
|
||||
addr: addr.to_string(),
|
||||
@@ -84,40 +84,40 @@ pub fn dc_loginparam_read(
|
||||
pub fn dc_loginparam_write(
|
||||
context: &Context,
|
||||
loginparam: &dc_loginparam_t,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
prefix: impl AsRef<str>,
|
||||
) {
|
||||
let prefix = prefix.as_ref();
|
||||
|
||||
let key = format!("{}addr", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.addr));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.addr));
|
||||
|
||||
let key = format!("{}mail_server", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.mail_server));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.mail_server));
|
||||
|
||||
let key = format!("{}mail_port", prefix);
|
||||
dc_sqlite3_set_config_int(context, sql, key, loginparam.mail_port);
|
||||
sql::set_config_int(context, sql, key, loginparam.mail_port);
|
||||
|
||||
let key = format!("{}mail_user", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.mail_user));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.mail_user));
|
||||
|
||||
let key = format!("{}mail_pw", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.mail_pw));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.mail_pw));
|
||||
|
||||
let key = format!("{}send_server", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.send_server));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.send_server));
|
||||
|
||||
let key = format!("{}send_port", prefix);
|
||||
dc_sqlite3_set_config_int(context, sql, key, loginparam.send_port);
|
||||
sql::set_config_int(context, sql, key, loginparam.send_port);
|
||||
|
||||
let key = format!("{}send_user", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.send_user));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.send_user));
|
||||
|
||||
let key = format!("{}send_pw", prefix);
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&loginparam.send_pw));
|
||||
sql::set_config(context, sql, key, Some(&loginparam.send_pw));
|
||||
|
||||
let key = format!("{}server_flags", prefix);
|
||||
dc_sqlite3_set_config_int(context, sql, key, loginparam.server_flags);
|
||||
sql::set_config_int(context, sql, key, loginparam.server_flags);
|
||||
}
|
||||
|
||||
fn unset_empty(s: &String) -> Cow<String> {
|
||||
|
||||
@@ -16,10 +16,10 @@ use crate::dc_e2ee::*;
|
||||
use crate::dc_location::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_strencode::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -190,9 +190,8 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
let email_to_remove = to_string(email_to_remove_c);
|
||||
let self_addr =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
|
||||
if !email_to_remove.is_empty() && email_to_remove != self_addr {
|
||||
if clist_search_string_nocase((*factory).recipients_addr, email_to_remove_c)
|
||||
@@ -213,7 +212,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
}
|
||||
if command != 6
|
||||
&& command != 7
|
||||
&& 0 != dc_sqlite3_get_config_int(context, &context.sql, "mdns_enabled", 1)
|
||||
&& 0 != sql::get_config_int(context, &context.sql, "mdns_enabled", 1)
|
||||
{
|
||||
(*factory).req_mdn = 1
|
||||
}
|
||||
@@ -249,7 +248,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
||||
unsafe fn load_from(mut factory: *mut dc_mimefactory_t) {
|
||||
(*factory).from_addr = strdup(
|
||||
to_cstring(
|
||||
dc_sqlite3_get_config(
|
||||
sql::get_config(
|
||||
(*factory).context,
|
||||
&(*factory).context.sql,
|
||||
"configured_addr",
|
||||
@@ -261,7 +260,7 @@ unsafe fn load_from(mut factory: *mut dc_mimefactory_t) {
|
||||
);
|
||||
(*factory).from_displayname = strdup(
|
||||
to_cstring(
|
||||
dc_sqlite3_get_config(
|
||||
sql::get_config(
|
||||
(*factory).context,
|
||||
&(*factory).context.sql,
|
||||
"displayname",
|
||||
@@ -273,7 +272,7 @@ unsafe fn load_from(mut factory: *mut dc_mimefactory_t) {
|
||||
);
|
||||
(*factory).selfstatus = strdup(
|
||||
to_cstring(
|
||||
dc_sqlite3_get_config(
|
||||
sql::get_config(
|
||||
(*factory).context,
|
||||
&(*factory).context.sql,
|
||||
"selfstatus",
|
||||
@@ -302,7 +301,7 @@ pub unsafe fn dc_mimefactory_load_mdn(
|
||||
(*factory).recipients_names = clist_new();
|
||||
(*factory).recipients_addr = clist_new();
|
||||
(*factory).msg = dc_msg_new_untyped((*factory).context);
|
||||
if 0 != dc_sqlite3_get_config_int(
|
||||
if 0 != sql::get_config_int(
|
||||
(*factory).context,
|
||||
&(*factory).context.sql,
|
||||
"mdns_enabled",
|
||||
|
||||
@@ -2,10 +2,10 @@ use crate::constants::*;
|
||||
use crate::context::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::sql;
|
||||
|
||||
pub unsafe fn dc_do_heuristics_moves(context: &Context, folder: &str, msg_id: u32) {
|
||||
if dc_sqlite3_get_config_int(context, &context.sql, "mvbox_move", 1) == 0 {
|
||||
if sql::get_config_int(context, &context.sql, "mvbox_move", 1) == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ use crate::dc_job::*;
|
||||
use crate::dc_lot::dc_lot_t;
|
||||
use crate::dc_lot::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::pgp::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -52,7 +52,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
|
||||
dc_msg_load_from_db(msg, context, msg_id);
|
||||
dc_contact_load_from_db(contact_from, &context.sql, (*msg).from_id);
|
||||
|
||||
let rawtxt: Option<String> = dc_sqlite3_query_row(
|
||||
let rawtxt: Option<String> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT txt_raw FROM msgs WHERE id=?;",
|
||||
@@ -475,7 +475,7 @@ pub fn dc_msg_load_from_db<'a>(msg: *mut dc_msg_t<'a>, context: &'a Context, id:
|
||||
}
|
||||
|
||||
pub unsafe fn dc_get_mime_headers(context: &Context, msg_id: uint32_t) -> *mut libc::c_char {
|
||||
let headers: Option<String> = dc_sqlite3_query_row(
|
||||
let headers: Option<String> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT mime_headers FROM msgs WHERE id=?;",
|
||||
@@ -515,7 +515,7 @@ pub unsafe fn dc_delete_msgs(context: &Context, msg_ids: *const uint32_t, msg_cn
|
||||
}
|
||||
|
||||
pub fn dc_update_msg_chat_id(context: &Context, msg_id: u32, chat_id: u32) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET chat_id=? WHERE id=?;",
|
||||
@@ -570,7 +570,7 @@ pub fn dc_markseen_msgs(context: &Context, msg_ids: *const u32, msg_cnt: usize)
|
||||
}
|
||||
|
||||
pub fn dc_update_msg_state(context: &Context, msg_id: uint32_t, state: libc::c_int) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET state=? WHERE id=?;",
|
||||
@@ -1075,7 +1075,7 @@ pub unsafe fn dc_msg_save_param_to_disk(msg: *mut dc_msg_t) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
(*msg).context,
|
||||
&(*msg).context.sql,
|
||||
"UPDATE msgs SET param=? WHERE id=?;",
|
||||
@@ -1092,13 +1092,13 @@ pub unsafe fn dc_msg_new_load<'a>(context: &'a Context, msg_id: uint32_t) -> *mu
|
||||
pub unsafe fn dc_delete_msg_from_db(context: &Context, msg_id: uint32_t) {
|
||||
let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
||||
if dc_msg_load_from_db(msg, context, msg_id) {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM msgs WHERE id=?;",
|
||||
params![(*msg).id as i32],
|
||||
);
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM msgs_mdns WHERE msg_id=?;",
|
||||
@@ -1120,7 +1120,7 @@ pub unsafe fn dc_msg_exists(context: &Context, msg_id: uint32_t) -> libc::c_int
|
||||
return 0;
|
||||
}
|
||||
|
||||
let chat_id: Option<i32> = dc_sqlite3_query_row(
|
||||
let chat_id: Option<i32> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT chat_id FROM msgs WHERE id=?;",
|
||||
@@ -1144,7 +1144,7 @@ pub fn dc_update_msg_move_state(
|
||||
) -> bool {
|
||||
// we update the move_state for all messages belonging to a given Message-ID
|
||||
// so that the state stay intact when parts are deleted
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET move_state=? WHERE rfc724_mid=?;",
|
||||
@@ -1164,7 +1164,7 @@ pub unsafe fn dc_set_msg_failed(context: &Context, msg_id: uint32_t, error: *con
|
||||
error!(context, 0, "{}", as_str(error),);
|
||||
}
|
||||
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE msgs SET state=?, param=? WHERE id=?;",
|
||||
@@ -1243,7 +1243,7 @@ pub unsafe fn dc_mdn_from_ext(
|
||||
read_by_all = 1;
|
||||
} else {
|
||||
/* send event about new state */
|
||||
let ist_cnt: i32 = dc_sqlite3_query_row(
|
||||
let ist_cnt: i32 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT COUNT(*) FROM msgs_mdns WHERE msg_id=?;",
|
||||
|
||||
@@ -19,11 +19,11 @@ use crate::dc_move::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_securejoin::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_strencode::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -232,12 +232,8 @@ pub unsafe fn dc_receive_imf(
|
||||
by checking the state before the message body is downloaded */
|
||||
let mut allow_creation: libc::c_int = 1;
|
||||
if msgrmsg == 0 {
|
||||
let show_emails: libc::c_int = dc_sqlite3_get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"show_emails",
|
||||
0,
|
||||
);
|
||||
let show_emails: libc::c_int =
|
||||
sql::get_config_int(context, &context.sql, "show_emails", 0);
|
||||
if show_emails == 0 {
|
||||
chat_id = 3 as uint32_t;
|
||||
allow_creation = 0
|
||||
@@ -434,12 +430,8 @@ pub unsafe fn dc_receive_imf(
|
||||
dc_unarchive_chat(context, chat_id);
|
||||
// if the mime-headers should be saved, find out its size
|
||||
// (the mime-header ends with an empty line)
|
||||
let save_mime_headers = dc_sqlite3_get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"save_mime_headers",
|
||||
0,
|
||||
);
|
||||
let save_mime_headers =
|
||||
sql::get_config_int(context, &context.sql, "save_mime_headers", 0);
|
||||
field = dc_mimeparser_lookup_field(
|
||||
&mime_parser,
|
||||
b"In-Reply-To\x00" as *const u8 as *const libc::c_char,
|
||||
@@ -565,7 +557,7 @@ pub unsafe fn dc_receive_imf(
|
||||
} else {
|
||||
free(txt_raw as *mut libc::c_void);
|
||||
txt_raw = 0 as *mut libc::c_char;
|
||||
insert_msg_id = dc_sqlite3_get_rowid(
|
||||
insert_msg_id = sql::get_rowid(
|
||||
context,
|
||||
&context.sql,
|
||||
"msgs",
|
||||
@@ -632,7 +624,7 @@ pub unsafe fn dc_receive_imf(
|
||||
_ => {
|
||||
if carray_count(mime_parser.reports) > 0 as libc::c_uint {
|
||||
let mdns_enabled =
|
||||
dc_sqlite3_get_config_int(context, &context.sql, "mdns_enabled", 1);
|
||||
sql::get_config_int(context, &context.sql, "mdns_enabled", 1);
|
||||
icnt = carray_count(mime_parser.reports) as size_t;
|
||||
i = 0 as size_t;
|
||||
while i < icnt {
|
||||
@@ -812,7 +804,7 @@ pub unsafe fn dc_receive_imf(
|
||||
);
|
||||
dc_param_set_int(param, 'z' as i32, server_uid as i32);
|
||||
if 0 != mime_parser.is_send_by_messenger
|
||||
&& 0 != dc_sqlite3_get_config_int(
|
||||
&& 0 != sql::get_config_int(
|
||||
context,
|
||||
&context.sql,
|
||||
"mvbox_move",
|
||||
@@ -960,7 +952,7 @@ unsafe fn calc_timestamps(
|
||||
}
|
||||
*sort_timestamp = message_timestamp;
|
||||
if 0 != is_fresh_msg {
|
||||
let last_msg_time: Option<i64> = dc_sqlite3_query_row(
|
||||
let last_msg_time: Option<i64> = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT MAX(timestamp) FROM msgs WHERE chat_id=? and from_id!=? AND timestamp>=?",
|
||||
@@ -1216,9 +1208,8 @@ unsafe fn create_or_lookup_group(
|
||||
}
|
||||
/* check if the group does not exist but should be created */
|
||||
group_explicitly_left = dc_is_group_explicitly_left(context, grpid);
|
||||
let self_addr =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", Some(""))
|
||||
.unwrap_or_default();
|
||||
if chat_id == 0 as libc::c_uint
|
||||
&& 0 == dc_mimeparser_is_mailinglist_message(mime_parser)
|
||||
&& !grpid.is_null()
|
||||
@@ -1291,7 +1282,7 @@ unsafe fn create_or_lookup_group(
|
||||
&& !grpname.is_null()
|
||||
&& strlen(grpname) < 200
|
||||
{
|
||||
if dc_sqlite3_execute(
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"UPDATE chats SET name=? WHERE id=?;",
|
||||
@@ -1352,7 +1343,7 @@ unsafe fn create_or_lookup_group(
|
||||
} else {
|
||||
0 as *mut libc::c_char
|
||||
};
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"DELETE FROM chats_contacts WHERE chat_id=?;",
|
||||
@@ -1560,7 +1551,7 @@ fn create_group_record(
|
||||
create_blocked: libc::c_int,
|
||||
create_verified: libc::c_int,
|
||||
) -> u32 {
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO chats (type, name, grpid, blocked) VALUES(?, ?, ?, ?);",
|
||||
@@ -1574,7 +1565,7 @@ fn create_group_record(
|
||||
return 0;
|
||||
}
|
||||
|
||||
dc_sqlite3_get_rowid(context, &context.sql, "chats", "grpid", as_str(grpid))
|
||||
sql::get_rowid(context, &context.sql, "chats", "grpid", as_str(grpid))
|
||||
}
|
||||
|
||||
unsafe fn create_adhoc_grp_id(context: &Context, member_ids: *mut dc_array_t) -> *mut libc::c_char {
|
||||
@@ -1585,10 +1576,9 @@ unsafe fn create_adhoc_grp_id(context: &Context, member_ids: *mut dc_array_t) ->
|
||||
- encode the first 64 bits of the sha-256 output as lowercase hex (results in 16 characters from the set [0-9a-f])
|
||||
*/
|
||||
let member_ids_str = dc_array_get_string(member_ids, b",\x00" as *const u8 as *const _);
|
||||
let member_cs =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some("no-self"))
|
||||
.unwrap()
|
||||
.to_lowercase();
|
||||
let member_cs = sql::get_config(context, &context.sql, "configured_addr", Some("no-self"))
|
||||
.unwrap()
|
||||
.to_lowercase();
|
||||
|
||||
let members = context
|
||||
.sql
|
||||
@@ -2098,8 +2088,7 @@ unsafe fn add_or_lookup_contact_by_addr(
|
||||
return;
|
||||
}
|
||||
*check_self = 0;
|
||||
let self_addr =
|
||||
dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some("")).unwrap();
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", Some("")).unwrap();
|
||||
|
||||
if dc_addr_cmp(self_addr, as_str(addr_spec)) {
|
||||
*check_self = 1;
|
||||
|
||||
@@ -14,13 +14,13 @@ use crate::dc_mimeparser::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_qr::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_stock::*;
|
||||
use crate::dc_strencode::*;
|
||||
use crate::dc_token::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::key::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
@@ -52,7 +52,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
auth = dc_create_id();
|
||||
dc_token_save(context, DC_TOKEN_AUTH, group_chat_id, auth);
|
||||
}
|
||||
let self_addr = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None);
|
||||
let self_addr = sql::get_config(context, &context.sql, "configured_addr", None);
|
||||
|
||||
let cleanup = |fingerprint, chat, group_name, group_name_urlencoded| {
|
||||
free(fingerprint as *mut libc::c_void);
|
||||
@@ -75,7 +75,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
}
|
||||
|
||||
let self_addr = self_addr.unwrap();
|
||||
let self_name = dc_sqlite3_get_config(context, &context.sql, "displayname", Some("")).unwrap();
|
||||
let self_name = sql::get_config(context, &context.sql, "displayname", Some("")).unwrap();
|
||||
fingerprint = get_self_fingerprint(context);
|
||||
|
||||
if fingerprint.is_null() {
|
||||
@@ -124,7 +124,7 @@ pub unsafe fn dc_get_securejoin_qr(
|
||||
}
|
||||
|
||||
fn get_self_fingerprint(context: &Context) -> *mut libc::c_char {
|
||||
if let Some(self_addr) = dc_sqlite3_get_config(context, &context.sql, "configured_addr", None) {
|
||||
if let Some(self_addr) = sql::get_config(context, &context.sql, "configured_addr", None) {
|
||||
if let Some(key) = Key::from_self_public(context, self_addr, &context.sql) {
|
||||
return key.fingerprint_c();
|
||||
}
|
||||
@@ -941,7 +941,7 @@ pub unsafe fn dc_handle_degrade_event(context: &Context, peerstate: &Peerstate)
|
||||
// with things they cannot fix, so the user is just kicked from the verified group
|
||||
// (and he will know this and can fix this)
|
||||
if Some(DegradeEvent::FingerprintChanged) == peerstate.degrade_event {
|
||||
let contact_id: i32 = dc_sqlite3_query_row(
|
||||
let contact_id: i32 = sql::query_row(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT id FROM contacts WHERE addr=?;",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::context::Context;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql;
|
||||
use crate::x::strdup;
|
||||
|
||||
// Token namespaces
|
||||
@@ -20,7 +20,7 @@ pub fn dc_token_save(
|
||||
return false;
|
||||
}
|
||||
// foreign_id may be 0
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
"INSERT INTO tokens (namespc, foreign_id, token, timestamp) VALUES (?, ?, ?, ?);",
|
||||
@@ -33,7 +33,7 @@ pub fn dc_token_lookup(
|
||||
namespc: dc_tokennamespc_t,
|
||||
foreign_id: u32,
|
||||
) -> *mut libc::c_char {
|
||||
if let Some(token) = dc_sqlite3_query_row::<_, String>(
|
||||
if let Some(token) = sql::query_row::<_, String>(
|
||||
context,
|
||||
&context.sql,
|
||||
"SELECT token FROM tokens WHERE namespc=? AND foreign_id=?;",
|
||||
|
||||
@@ -6,9 +6,9 @@ use std::time::{Duration, SystemTime};
|
||||
use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::as_str;
|
||||
use crate::oauth2::dc_get_oauth2_access_token;
|
||||
use crate::sql;
|
||||
use crate::types::*;
|
||||
|
||||
pub const DC_IMAP_SEEN: usize = 0x0001;
|
||||
@@ -1598,9 +1598,9 @@ impl Imap {
|
||||
}
|
||||
}
|
||||
|
||||
dc_sqlite3_set_config_int(context, &context.sql, "folders_configured", 3);
|
||||
sql::set_config_int(context, &context.sql, "folders_configured", 3);
|
||||
if let Some(ref mvbox_folder) = mvbox_folder {
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured_mvbox_folder",
|
||||
@@ -1608,7 +1608,7 @@ impl Imap {
|
||||
);
|
||||
}
|
||||
if let Some(ref sentbox_folder) = sentbox_folder {
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"configured_sentbox_folder",
|
||||
|
||||
14
src/key.rs
14
src/key.rs
@@ -10,8 +10,8 @@ use pgp::types::{KeyTrait, SecretKeyTrait};
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
@@ -145,11 +145,11 @@ impl Key {
|
||||
pub fn from_self_public(
|
||||
context: &Context,
|
||||
self_addr: impl AsRef<str>,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
) -> Option<Self> {
|
||||
let addr = self_addr.as_ref();
|
||||
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
sql,
|
||||
"SELECT public_key FROM keypairs WHERE addr=? AND is_default=1;",
|
||||
@@ -162,9 +162,9 @@ impl Key {
|
||||
pub fn from_self_private(
|
||||
context: &Context,
|
||||
self_addr: impl AsRef<str>,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
) -> Option<Self> {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
sql,
|
||||
"SELECT private_key FROM keypairs WHERE addr=? AND is_default=1;",
|
||||
@@ -301,9 +301,9 @@ pub fn dc_key_save_self_keypair(
|
||||
private_key: &Key,
|
||||
addr: impl AsRef<str>,
|
||||
is_default: libc::c_int,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
) -> bool {
|
||||
dc_sqlite3_execute(
|
||||
sql::execute(
|
||||
context,
|
||||
sql,
|
||||
"INSERT INTO keypairs (addr, is_default, public_key, private_key, created) VALUES (?,?,?,?,?);",
|
||||
|
||||
@@ -2,8 +2,8 @@ use std::borrow::Cow;
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::key::*;
|
||||
use crate::sql::{self, Sql};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct Keyring<'a> {
|
||||
@@ -31,9 +31,9 @@ impl<'a> Keyring<'a> {
|
||||
&mut self,
|
||||
context: &Context,
|
||||
self_addr: impl AsRef<str>,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
) -> bool {
|
||||
dc_sqlite3_query_row(
|
||||
sql::query_row(
|
||||
context,
|
||||
sql,
|
||||
"SELECT private_key FROM keypairs ORDER BY addr=? DESC, is_default DESC;",
|
||||
|
||||
@@ -32,6 +32,7 @@ pub mod oauth2;
|
||||
pub mod peerstate;
|
||||
pub mod pgp;
|
||||
pub mod smtp;
|
||||
pub mod sql;
|
||||
pub mod types;
|
||||
pub mod x;
|
||||
|
||||
@@ -58,7 +59,6 @@ pub mod dc_receive_imf;
|
||||
pub mod dc_saxparser;
|
||||
pub mod dc_securejoin;
|
||||
pub mod dc_simplify;
|
||||
pub mod dc_sqlite3;
|
||||
pub mod dc_stock;
|
||||
pub mod dc_strencode;
|
||||
pub mod dc_token;
|
||||
|
||||
@@ -4,8 +4,8 @@ use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::context::Context;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::sql;
|
||||
|
||||
const OAUTH2_GMAIL: Oauth2 = Oauth2 {
|
||||
client_id: "959970109878-4mvtgf6feshskf7695nfln6002mom908.apps.googleusercontent.com",
|
||||
@@ -49,7 +49,7 @@ pub fn dc_get_oauth2_url(
|
||||
redirect_uri: impl AsRef<str>,
|
||||
) -> Option<String> {
|
||||
if let Some(oauth2) = Oauth2::from_address(addr) {
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"oauth2_pending_redirect_uri",
|
||||
@@ -78,45 +78,42 @@ pub fn dc_get_oauth2_access_token(
|
||||
|
||||
// read generated token
|
||||
if 0 == flags & 0x1 && !is_expired(context) {
|
||||
let access_token =
|
||||
dc_sqlite3_get_config(context, &context.sql, "oauth2_access_token", None);
|
||||
let access_token = sql::get_config(context, &context.sql, "oauth2_access_token", None);
|
||||
if access_token.is_some() {
|
||||
// success
|
||||
return access_token;
|
||||
}
|
||||
}
|
||||
|
||||
let refresh_token =
|
||||
dc_sqlite3_get_config(context, &context.sql, "oauth2_refresh_token", None);
|
||||
let refresh_token = sql::get_config(context, &context.sql, "oauth2_refresh_token", None);
|
||||
let refresh_token_for =
|
||||
dc_sqlite3_get_config(context, &context.sql, "oauth2_refresh_token_for", None)
|
||||
sql::get_config(context, &context.sql, "oauth2_refresh_token_for", None)
|
||||
.unwrap_or_else(|| "unset".into());
|
||||
|
||||
let (redirect_uri, token_url, update_redirect_uri_on_success) = if refresh_token.is_none()
|
||||
|| refresh_token_for != code.as_ref()
|
||||
{
|
||||
info!(
|
||||
context,
|
||||
0, "Generate OAuth2 refresh_token and access_token...",
|
||||
);
|
||||
(
|
||||
dc_sqlite3_get_config(context, &context.sql, "oauth2_pending_redirect_uri", None)
|
||||
.unwrap_or_else(|| "unset".into()),
|
||||
oauth2.init_token,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
info!(
|
||||
context,
|
||||
0, "Regenerate OAuth2 access_token by refresh_token...",
|
||||
);
|
||||
(
|
||||
dc_sqlite3_get_config(context, &context.sql, "oauth2_redirect_uri", None)
|
||||
.unwrap_or_else(|| "unset".into()),
|
||||
oauth2.refresh_token,
|
||||
false,
|
||||
)
|
||||
};
|
||||
let (redirect_uri, token_url, update_redirect_uri_on_success) =
|
||||
if refresh_token.is_none() || refresh_token_for != code.as_ref() {
|
||||
info!(
|
||||
context,
|
||||
0, "Generate OAuth2 refresh_token and access_token...",
|
||||
);
|
||||
(
|
||||
sql::get_config(context, &context.sql, "oauth2_pending_redirect_uri", None)
|
||||
.unwrap_or_else(|| "unset".into()),
|
||||
oauth2.init_token,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
info!(
|
||||
context,
|
||||
0, "Regenerate OAuth2 access_token by refresh_token...",
|
||||
);
|
||||
(
|
||||
sql::get_config(context, &context.sql, "oauth2_redirect_uri", None)
|
||||
.unwrap_or_else(|| "unset".into()),
|
||||
oauth2.refresh_token,
|
||||
false,
|
||||
)
|
||||
};
|
||||
let mut token_url = replace_in_uri(&token_url, "$CLIENT_ID", oauth2.client_id);
|
||||
token_url = replace_in_uri(&token_url, "$REDIRECT_URI", &redirect_uri);
|
||||
token_url = replace_in_uri(&token_url, "$CODE", code.as_ref());
|
||||
@@ -155,8 +152,8 @@ pub fn dc_get_oauth2_access_token(
|
||||
println!("response: {:?}", &parsed);
|
||||
let response = parsed.unwrap();
|
||||
if let Some(ref token) = response.refresh_token {
|
||||
dc_sqlite3_set_config(context, &context.sql, "oauth2_refresh_token", Some(token));
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(context, &context.sql, "oauth2_refresh_token", Some(token));
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"oauth2_refresh_token_for",
|
||||
@@ -167,13 +164,13 @@ pub fn dc_get_oauth2_access_token(
|
||||
// after that, save the access token.
|
||||
// if it's unset, we may get it in the next round as we have the refresh_token now.
|
||||
if let Some(ref token) = response.access_token {
|
||||
dc_sqlite3_set_config(context, &context.sql, "oauth2_access_token", Some(token));
|
||||
sql::set_config(context, &context.sql, "oauth2_access_token", Some(token));
|
||||
let expires_in = response
|
||||
.expires_in
|
||||
// refresh a bet before
|
||||
.map(|t| time() + t as i64 - 5)
|
||||
.unwrap_or_else(|| 0);
|
||||
dc_sqlite3_set_config_int64(
|
||||
sql::set_config_int64(
|
||||
context,
|
||||
&context.sql,
|
||||
"oauth2_timestamp_expires",
|
||||
@@ -181,7 +178,7 @@ pub fn dc_get_oauth2_access_token(
|
||||
);
|
||||
|
||||
if update_redirect_uri_on_success {
|
||||
dc_sqlite3_set_config(
|
||||
sql::set_config(
|
||||
context,
|
||||
&context.sql,
|
||||
"oauth2_redirect_uri",
|
||||
@@ -300,7 +297,7 @@ impl Oauth2 {
|
||||
|
||||
fn is_expired(context: &Context) -> bool {
|
||||
let expire_timestamp =
|
||||
dc_sqlite3_get_config_int64(context, &context.sql, "oauth2_timestamp_expires", Some(0));
|
||||
sql::get_config_int64(context, &context.sql, "oauth2_timestamp_expires", Some(0));
|
||||
|
||||
if expire_timestamp <= 0 {
|
||||
return false;
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::aheader::*;
|
||||
use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_chat::*;
|
||||
use crate::dc_sqlite3::*;
|
||||
use crate::key::*;
|
||||
use crate::sql::{self, Sql};
|
||||
|
||||
/// Peerstate represents the state of an Autocrypt peer.
|
||||
pub struct Peerstate<'a> {
|
||||
@@ -164,17 +164,13 @@ impl<'a> Peerstate<'a> {
|
||||
res
|
||||
}
|
||||
|
||||
pub fn from_addr(context: &'a Context, _sql: &SQLite, addr: &str) -> Option<Self> {
|
||||
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;";
|
||||
|
||||
Self::from_stmt(context, query, &[addr])
|
||||
}
|
||||
|
||||
pub fn from_fingerprint(
|
||||
context: &'a Context,
|
||||
_sql: &SQLite,
|
||||
fingerprint: &str,
|
||||
) -> Option<Self> {
|
||||
pub fn from_fingerprint(context: &'a Context, _sql: &Sql, fingerprint: &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 \
|
||||
@@ -383,7 +379,7 @@ impl<'a> Peerstate<'a> {
|
||||
success
|
||||
}
|
||||
|
||||
pub fn save_to_db(&self, sql: &SQLite, create: bool) -> bool {
|
||||
pub fn save_to_db(&self, sql: &Sql, create: bool) -> bool {
|
||||
let mut success = false;
|
||||
|
||||
if self.addr.is_none() {
|
||||
@@ -391,7 +387,7 @@ impl<'a> Peerstate<'a> {
|
||||
}
|
||||
|
||||
if create {
|
||||
if !dc_sqlite3_execute(
|
||||
if !sql::execute(
|
||||
self.context,
|
||||
sql,
|
||||
"INSERT INTO acpeerstates (addr) VALUES(?);",
|
||||
@@ -402,7 +398,7 @@ impl<'a> Peerstate<'a> {
|
||||
}
|
||||
|
||||
if self.to_save == Some(ToSave::All) || create {
|
||||
success = dc_sqlite3_execute(
|
||||
success = sql::execute(
|
||||
self.context,
|
||||
sql,
|
||||
"UPDATE acpeerstates \
|
||||
@@ -425,7 +421,7 @@ impl<'a> Peerstate<'a> {
|
||||
],
|
||||
);
|
||||
} else if self.to_save == Some(ToSave::Timestamps) {
|
||||
success = dc_sqlite3_execute(
|
||||
success = sql::execute(
|
||||
self.context,
|
||||
sql,
|
||||
"UPDATE acpeerstates SET last_seen=?, last_seen_autocrypt=?, gossip_timestamp=? \
|
||||
|
||||
@@ -14,13 +14,13 @@ use crate::x::*;
|
||||
const DC_OPEN_READONLY: usize = 0x01;
|
||||
|
||||
/// A wrapper around the underlying Sqlite3 object.
|
||||
pub struct SQLite {
|
||||
pub struct Sql {
|
||||
pool: RwLock<Option<r2d2::Pool<r2d2_sqlite::SqliteConnectionManager>>>,
|
||||
}
|
||||
|
||||
impl SQLite {
|
||||
pub fn new() -> SQLite {
|
||||
SQLite {
|
||||
impl Sql {
|
||||
pub fn new() -> Sql {
|
||||
Sql {
|
||||
pool: RwLock::new(None),
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ impl SQLite {
|
||||
|
||||
// return true on success, false on failure
|
||||
pub fn open(&self, context: &Context, dbfile: &std::path::Path, flags: libc::c_int) -> bool {
|
||||
match dc_sqlite3_open(context, self, dbfile, flags) {
|
||||
match open(context, self, dbfile, flags) {
|
||||
Ok(_) => true,
|
||||
Err(Error::SqlAlreadyOpen) => false,
|
||||
Err(_) => {
|
||||
@@ -155,9 +155,9 @@ fn table_exists(conn: &Connection, name: impl AsRef<str>) -> bool {
|
||||
|
||||
// Return 1 -> success
|
||||
// Return 0 -> failure
|
||||
fn dc_sqlite3_open(
|
||||
fn open(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
dbfile: impl AsRef<std::path::Path>,
|
||||
flags: libc::c_int,
|
||||
) -> Result<()> {
|
||||
@@ -321,11 +321,11 @@ fn dc_sqlite3_open(
|
||||
// cannot create the tables - maybe we cannot write?
|
||||
return Err(Error::SqlFailedToOpen);
|
||||
} else {
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 0);
|
||||
set_config_int(context, sql, "dbversion", 0);
|
||||
}
|
||||
} else {
|
||||
exists_before_update = 1;
|
||||
dbversion_before_update = dc_sqlite3_get_config_int(context, sql, "dbversion", 0);
|
||||
dbversion_before_update = get_config_int(context, sql, "dbversion", 0);
|
||||
}
|
||||
|
||||
// (1) update low-level database structure.
|
||||
@@ -346,7 +346,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 1;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 1);
|
||||
set_config_int(context, sql, "dbversion", 1);
|
||||
}
|
||||
if dbversion < 2 {
|
||||
sql.execute(
|
||||
@@ -354,7 +354,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 2;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 2);
|
||||
set_config_int(context, sql, "dbversion", 2);
|
||||
}
|
||||
if dbversion < 7 {
|
||||
sql.execute(
|
||||
@@ -368,7 +368,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 7;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 7);
|
||||
set_config_int(context, sql, "dbversion", 7);
|
||||
}
|
||||
if dbversion < 10 {
|
||||
sql.execute(
|
||||
@@ -386,7 +386,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 10;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 10);
|
||||
set_config_int(context, sql, "dbversion", 10);
|
||||
}
|
||||
if dbversion < 12 {
|
||||
sql.execute(
|
||||
@@ -398,7 +398,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 12;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 12);
|
||||
set_config_int(context, sql, "dbversion", 12);
|
||||
}
|
||||
if dbversion < 17 {
|
||||
sql.execute(
|
||||
@@ -412,7 +412,7 @@ fn dc_sqlite3_open(
|
||||
)?;
|
||||
sql.execute("CREATE INDEX msgs_index5 ON msgs (starred);", params![])?;
|
||||
dbversion = 17;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 17);
|
||||
set_config_int(context, sql, "dbversion", 17);
|
||||
}
|
||||
if dbversion < 18 {
|
||||
sql.execute(
|
||||
@@ -421,7 +421,7 @@ fn dc_sqlite3_open(
|
||||
)?;
|
||||
sql.execute("ALTER TABLE acpeerstates ADD COLUMN gossip_key;", params![])?;
|
||||
dbversion = 18;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 18);
|
||||
set_config_int(context, sql, "dbversion", 18);
|
||||
}
|
||||
if dbversion < 27 {
|
||||
sql.execute("DELETE FROM msgs WHERE chat_id=1 OR chat_id=2;", params![])?;
|
||||
@@ -438,7 +438,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 27;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 27);
|
||||
set_config_int(context, sql, "dbversion", 27);
|
||||
}
|
||||
if dbversion < 34 {
|
||||
sql.execute(
|
||||
@@ -467,7 +467,7 @@ fn dc_sqlite3_open(
|
||||
)?;
|
||||
recalc_fingerprints = 1;
|
||||
dbversion = 34;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 34);
|
||||
set_config_int(context, sql, "dbversion", 34);
|
||||
}
|
||||
if dbversion < 39 {
|
||||
sql.execute(
|
||||
@@ -497,7 +497,7 @@ fn dc_sqlite3_open(
|
||||
)?;
|
||||
}
|
||||
dbversion = 39;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 39);
|
||||
set_config_int(context, sql, "dbversion", 39);
|
||||
}
|
||||
if dbversion < 40 {
|
||||
sql.execute(
|
||||
@@ -505,22 +505,22 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 40;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 40);
|
||||
set_config_int(context, sql, "dbversion", 40);
|
||||
}
|
||||
if dbversion < 41 {
|
||||
update_file_paths = 1;
|
||||
dbversion = 41;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 41);
|
||||
set_config_int(context, sql, "dbversion", 41);
|
||||
}
|
||||
if dbversion < 42 {
|
||||
sql.execute("UPDATE msgs SET txt=\'\' WHERE type!=10", params![])?;
|
||||
dbversion = 42;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 42);
|
||||
set_config_int(context, sql, "dbversion", 42);
|
||||
}
|
||||
if dbversion < 44 {
|
||||
sql.execute("ALTER TABLE msgs ADD COLUMN mime_headers TEXT;", params![])?;
|
||||
dbversion = 44;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 44);
|
||||
set_config_int(context, sql, "dbversion", 44);
|
||||
}
|
||||
if dbversion < 46 {
|
||||
sql.execute(
|
||||
@@ -532,7 +532,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 46;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 46);
|
||||
set_config_int(context, sql, "dbversion", 46);
|
||||
}
|
||||
if dbversion < 47 {
|
||||
info!(context, 0, "[migration] v47");
|
||||
@@ -541,7 +541,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 47;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 47);
|
||||
set_config_int(context, sql, "dbversion", 47);
|
||||
}
|
||||
if dbversion < 48 {
|
||||
info!(context, 0, "[migration] v48");
|
||||
@@ -555,7 +555,7 @@ fn dc_sqlite3_open(
|
||||
assert_eq!(DC_MOVE_STATE_MOVING as libc::c_int, 3);
|
||||
|
||||
dbversion = 48;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 48);
|
||||
set_config_int(context, sql, "dbversion", 48);
|
||||
}
|
||||
if dbversion < 49 {
|
||||
info!(context, 0, "[migration] v49");
|
||||
@@ -564,15 +564,15 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 49;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 49);
|
||||
set_config_int(context, sql, "dbversion", 49);
|
||||
}
|
||||
if dbversion < 50 {
|
||||
info!(context, 0, "[migration] v50");
|
||||
if 0 != exists_before_update {
|
||||
dc_sqlite3_set_config_int(context, sql, "show_emails", 2);
|
||||
set_config_int(context, sql, "show_emails", 2);
|
||||
}
|
||||
dbversion = 50;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 50);
|
||||
set_config_int(context, sql, "dbversion", 50);
|
||||
}
|
||||
if dbversion < 53 {
|
||||
info!(context, 0, "[migration] v53");
|
||||
@@ -605,7 +605,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
dbversion = 53;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 53);
|
||||
set_config_int(context, sql, "dbversion", 53);
|
||||
}
|
||||
if dbversion < 54 {
|
||||
info!(context, 0, "[migration] v54");
|
||||
@@ -615,7 +615,7 @@ fn dc_sqlite3_open(
|
||||
)?;
|
||||
sql.execute("CREATE INDEX msgs_index6 ON msgs (location_id);", params![])?;
|
||||
dbversion = 54;
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 54);
|
||||
set_config_int(context, sql, "dbversion", 54);
|
||||
}
|
||||
if dbversion < 55 {
|
||||
sql.execute(
|
||||
@@ -623,7 +623,7 @@ fn dc_sqlite3_open(
|
||||
params![],
|
||||
)?;
|
||||
|
||||
dc_sqlite3_set_config_int(context, sql, "dbversion", 55);
|
||||
set_config_int(context, sql, "dbversion", 55);
|
||||
}
|
||||
|
||||
if 0 != recalc_fingerprints {
|
||||
@@ -650,7 +650,7 @@ fn dc_sqlite3_open(
|
||||
|
||||
info!(context, 0, "[open] update file paths");
|
||||
|
||||
let repl_from = dc_sqlite3_get_config(
|
||||
let repl_from = get_config(
|
||||
context,
|
||||
sql,
|
||||
"backup_for",
|
||||
@@ -675,7 +675,7 @@ fn dc_sqlite3_open(
|
||||
NO_PARAMS,
|
||||
)?;
|
||||
|
||||
dc_sqlite3_set_config(context, sql, "backup_for", None);
|
||||
set_config(context, sql, "backup_for", None);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,14 +685,14 @@ fn dc_sqlite3_open(
|
||||
}
|
||||
|
||||
// handle configurations, private
|
||||
pub fn dc_sqlite3_set_config(
|
||||
pub fn set_config(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
key: impl AsRef<str>,
|
||||
value: Option<&str>,
|
||||
) -> libc::c_int {
|
||||
if !sql.is_open() {
|
||||
error!(context, 0, "dc_sqlite3_set_config(): Database not ready.");
|
||||
error!(context, 0, "set_config(): Database not ready.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -704,14 +704,14 @@ pub fn dc_sqlite3_set_config(
|
||||
.exists("SELECT value FROM config WHERE keyname=?;", params![key])
|
||||
.unwrap_or_default();
|
||||
if exists {
|
||||
good = dc_sqlite3_execute(
|
||||
good = execute(
|
||||
context,
|
||||
sql,
|
||||
"UPDATE config SET value=? WHERE keyname=?;",
|
||||
params![value, key],
|
||||
);
|
||||
} else {
|
||||
good = dc_sqlite3_execute(
|
||||
good = execute(
|
||||
context,
|
||||
sql,
|
||||
"INSERT INTO config (keyname, value) VALUES (?, ?);",
|
||||
@@ -719,7 +719,7 @@ pub fn dc_sqlite3_set_config(
|
||||
);
|
||||
}
|
||||
} else {
|
||||
good = dc_sqlite3_execute(
|
||||
good = execute(
|
||||
context,
|
||||
sql,
|
||||
"DELETE FROM config WHERE keyname=?;",
|
||||
@@ -728,23 +728,23 @@ pub fn dc_sqlite3_set_config(
|
||||
}
|
||||
|
||||
if !good {
|
||||
error!(context, 0, "dc_sqlite3_set_config(): Cannot change value.",);
|
||||
error!(context, 0, "set_config(): Cannot change value.",);
|
||||
return 0;
|
||||
}
|
||||
|
||||
1
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_get_config(
|
||||
pub fn get_config(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
key: impl AsRef<str>,
|
||||
def: Option<&str>,
|
||||
) -> Option<String> {
|
||||
if !sql.is_open() || key.as_ref().is_empty() {
|
||||
return None;
|
||||
}
|
||||
dc_sqlite3_query_row(
|
||||
query_row(
|
||||
context,
|
||||
sql,
|
||||
"SELECT value FROM config WHERE keyname=?;",
|
||||
@@ -754,12 +754,7 @@ pub fn dc_sqlite3_get_config(
|
||||
.or_else(|| def.map(|s| s.to_string()))
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_execute<P>(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
querystr: impl AsRef<str>,
|
||||
params: P,
|
||||
) -> bool
|
||||
pub fn execute<P>(context: &Context, sql: &Sql, querystr: impl AsRef<str>, params: P) -> bool
|
||||
where
|
||||
P: IntoIterator,
|
||||
P::Item: rusqlite::ToSql,
|
||||
@@ -767,16 +762,16 @@ where
|
||||
match sql.execute(querystr.as_ref(), params) {
|
||||
Ok(_) => true,
|
||||
Err(err) => {
|
||||
error!(context, 0, "dc_sqlite3_execute failed: {:?}", err);
|
||||
error!(context, 0, "execute failed: {:?}", err);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Remove the Option<> from the return type.
|
||||
pub fn dc_sqlite3_query_row<P, T>(
|
||||
pub fn query_row<P, T>(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
query: &str,
|
||||
params: P,
|
||||
column: usize,
|
||||
@@ -799,52 +794,43 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_set_config_int(
|
||||
pub fn set_config_int(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
key: impl AsRef<str>,
|
||||
value: i32,
|
||||
) -> libc::c_int {
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&format!("{}", value)))
|
||||
set_config(context, sql, key, Some(&format!("{}", value)))
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_get_config_int(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
key: impl AsRef<str>,
|
||||
def: i32,
|
||||
) -> i32 {
|
||||
dc_sqlite3_get_config(context, sql, key, None)
|
||||
pub fn get_config_int(context: &Context, sql: &Sql, key: impl AsRef<str>, def: i32) -> i32 {
|
||||
get_config(context, sql, key, None)
|
||||
.and_then(|s| s.parse().ok())
|
||||
.unwrap_or_else(|| def)
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_set_config_int64(
|
||||
pub fn set_config_int64(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
key: impl AsRef<str>,
|
||||
value: i64,
|
||||
) -> libc::c_int {
|
||||
dc_sqlite3_set_config(context, sql, key, Some(&format!("{}", value)))
|
||||
set_config(context, sql, key, Some(&format!("{}", value)))
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_get_config_int64(
|
||||
pub fn get_config_int64(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
key: impl AsRef<str>,
|
||||
def: Option<i64>,
|
||||
) -> i64 {
|
||||
let ret = dc_sqlite3_get_config(context, sql, key, None);
|
||||
let ret = get_config(context, sql, key, None);
|
||||
ret.map(|r| r.parse().unwrap_or_default())
|
||||
.unwrap_or_else(|| def.unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_try_execute(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
querystr: impl AsRef<str>,
|
||||
) -> libc::c_int {
|
||||
// same as dc_sqlite3_execute() but does not pass error to ui
|
||||
pub fn try_execute(context: &Context, sql: &Sql, querystr: impl AsRef<str>) -> libc::c_int {
|
||||
// same as execute() but does not pass error to ui
|
||||
match sql.execute(querystr.as_ref(), params![]) {
|
||||
Ok(_) => 1,
|
||||
Err(err) => {
|
||||
@@ -860,9 +846,9 @@ pub fn dc_sqlite3_try_execute(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_get_rowid(
|
||||
pub fn get_rowid(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
table: impl AsRef<str>,
|
||||
field: impl AsRef<str>,
|
||||
value: impl AsRef<str>,
|
||||
@@ -889,9 +875,9 @@ pub fn dc_sqlite3_get_rowid(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_sqlite3_get_rowid2(
|
||||
pub fn get_rowid2(
|
||||
context: &Context,
|
||||
sql: &SQLite,
|
||||
sql: &Sql,
|
||||
table: impl AsRef<str>,
|
||||
field: impl AsRef<str>,
|
||||
value: i64,
|
||||
@@ -899,14 +885,14 @@ pub fn dc_sqlite3_get_rowid2(
|
||||
value2: i32,
|
||||
) -> u32 {
|
||||
sql.with_conn(|conn| {
|
||||
Ok(get_rowid2(
|
||||
Ok(get_rowid2_with_conn(
|
||||
context, conn, table, field, value, field2, value2,
|
||||
))
|
||||
})
|
||||
.unwrap_or_else(|_| 0)
|
||||
}
|
||||
|
||||
pub fn get_rowid2(
|
||||
pub fn get_rowid2_with_conn(
|
||||
context: &Context,
|
||||
conn: &Connection,
|
||||
table: impl AsRef<str>,
|
||||
@@ -935,7 +921,7 @@ pub fn get_rowid2(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dc_housekeeping(context: &Context) {
|
||||
pub fn housekeeping(context: &Context) {
|
||||
let mut files_in_use = HashSet::new();
|
||||
let mut unreferenced_count = 0;
|
||||
|
||||
Reference in New Issue
Block a user