Clean up the worst rebase mistakes

This commit is contained in:
Floris Bruynooghe
2019-06-19 22:34:10 +02:00
committed by dignifiedquire
parent ab41679855
commit a791af2d90
11 changed files with 87 additions and 170 deletions

View File

@@ -121,7 +121,7 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
if let Some(mut stmt) = dc_sqlite3_prepare(
context,
&context.sql.read().unwrap(),
&context.sql,
"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \
c.blocked, c.gossiped_timestamp, c.locations_send_until \
FROM chats c WHERE c.id=?;",
@@ -723,7 +723,7 @@ unsafe fn prepare_msg_raw(
) {
msg_id = dc_sqlite3_get_rowid(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"msgs",
"rfc724_mid",
as_str(new_rfc724_mid),
@@ -1127,7 +1127,7 @@ pub unsafe fn dc_get_chat_msgs(
} else {
if let Some(mut stmt) = dc_sqlite3_prepare(
context,
&sql,
&context.sql,
"SELECT m.id, m.timestamp FROM msgs m \
WHERE m.chat_id=? \
AND m.hidden=0 \
@@ -1203,7 +1203,6 @@ pub fn dc_marknoticed_chat(context: &Context, chat_id: u32) -> bool {
) {
return false;
}
if !dc_sqlite3_execute(
context,
&context.sql,
@@ -1213,16 +1212,14 @@ pub fn dc_marknoticed_chat(context: &Context, chat_id: u32) -> bool {
) {
return false;
}
unsafe { (context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t) };
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
true
}
pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
if !dc_sqlite3_execute(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"SELECT id FROM msgs \
WHERE state=10;",
params![],
@@ -1240,7 +1237,7 @@ pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
return false;
}
unsafe { (context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t) };
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
true
}
@@ -1415,7 +1412,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
return;
}
unsafe { (context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t) };
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
dc_job_kill_action(context, 105);
unsafe { dc_job_add(context, 105, 0, 0 as *const libc::c_char, 10) };
}
@@ -1769,12 +1766,7 @@ pub unsafe fn dc_remove_contact_from_chat(
"DELETE FROM chats_contacts WHERE chat_id=? AND contact_id=?;",
params![chat_id as i32, contact_id as i32],
) {
(context.cb)(
context,
Event::CHAT_MODIFIED,
chat_id as uintptr_t,
0 as uintptr_t,
);
context.call_cb(Event::CHAT_MODIFIED, chat_id as uintptr_t, 0 as uintptr_t);
success = 1;
}
}
@@ -2251,7 +2243,7 @@ pub unsafe fn dc_get_chat_id_by_grpid(
dc_sqlite3_prepare(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"SELECT id, blocked, type FROM chats WHERE grpid=?;",
)
.and_then(|mut stmt| {
@@ -2284,7 +2276,7 @@ pub fn dc_add_device_msg(context: &Context, chat_id: uint32_t, text: *const libc
if !dc_sqlite3_execute(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);",
params![
chat_id as i32,
@@ -2302,18 +2294,15 @@ pub fn dc_add_device_msg(context: &Context, chat_id: uint32_t, text: *const libc
let msg_id = dc_sqlite3_get_rowid(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"msgs",
"rfc724_mid",
as_str(rfc724_mid),
);
unsafe { free(rfc724_mid as *mut libc::c_void) };
unsafe {
(context.cb)(
context,
Event::MSGS_CHANGED,
chat_id as uintptr_t,
msg_id as uintptr_t,
)
};
context.call_cb(
Event::MSGS_CHANGED,
chat_id as uintptr_t,
msg_id as uintptr_t,
);
}

View File

@@ -169,7 +169,7 @@ unsafe fn dc_chatlist_load_from_db(
} else if 0 != listflags & 0x1 {
if let Some(mut stmt) = dc_sqlite3_prepare(
(*chatlist).context,
&(*chatlist).context,
&(*chatlist).context.sql,
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
ON c.id=m.chat_id \
AND m.timestamp=( SELECT MAX(timestamp) \
@@ -220,7 +220,7 @@ unsafe fn dc_chatlist_load_from_db(
let strLikeCmd = format!("%{}%", query);
if let Some(mut stmt) = dc_sqlite3_prepare(
(*chatlist).context,
&(*chatlist).context.sql.clone().read().unwrap(),
&(*chatlist).context.sql,
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
ON c.id=m.chat_id \
AND m.timestamp=( SELECT MAX(timestamp) \

View File

@@ -152,8 +152,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
0i32 as uintptr_t,
);
let mut param =
dc_loginparam_read(context, &context.sql.clone().read().unwrap(), "");
let mut param = dc_loginparam_read(context, &context.sql, "");
if param.addr.is_empty() {
error!(context, 0, "Please enter an email address.",);
} else {

View File

@@ -33,7 +33,7 @@ pub fn dc_marknoticed_contact(context: &Context, contact_id: u32) {
"UPDATE msgs SET state=13 WHERE from_id=? AND state=10;",
params![contact_id as i32],
) {
unsafe { ((*context).cb)(context, Event::MSGS_CHANGED, 0, 0) };
context.call_cb(Event::MSGS_CHANGED, 0, 0);
}
}
@@ -68,13 +68,8 @@ 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.clone().read().unwrap(),
"configured_addr",
None,
)
.unwrap_or_default();
let addr_self =
dc_sqlite3_get_config(context, &context.sql, "configured_addr", None).unwrap_or_default();
let contact_id = if addr_normalized == addr_self {
1
@@ -338,13 +333,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.clone().read().unwrap(),
"configured_addr",
Some(""),
)
.unwrap_or_default();
let addr_self = dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
.unwrap_or_default();
if addr == addr_self {
return 1;
@@ -428,7 +418,7 @@ pub fn dc_add_or_lookup_contact(
if update_name {
dc_sqlite3_execute(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"UPDATE chats SET name=? WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?);",
params![as_str(name), 100, row_id]
);
@@ -438,7 +428,7 @@ pub fn dc_add_or_lookup_contact(
} else {
if dc_sqlite3_execute(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);",
params![
if !name.is_null() { as_str(name) } else { "" },
@@ -446,13 +436,7 @@ pub fn dc_add_or_lookup_contact(
origin,
],
) {
row_id = dc_sqlite3_get_rowid(
context,
&context.sql.clone().read().unwrap(),
"contacts",
"addr",
addr,
);
row_id = dc_sqlite3_get_rowid(context, &context.sql, "contacts", "addr", addr);
unsafe { *sth_modified = 2 };
} else {
error!(context, 0, "Cannot add contact.");
@@ -602,13 +586,8 @@ pub fn dc_get_contacts(
}
}
let self_name = dc_sqlite3_get_config(
context,
&context.sql.clone().read().unwrap(),
"displayname",
Some(""),
)
.unwrap_or_default();
let self_name = dc_sqlite3_get_config(context, &context.sql, "displayname", Some(""))
.unwrap_or_default();
let self_name2 = unsafe { dc_stock_str(context, 2) };
@@ -798,7 +777,7 @@ pub fn dc_delete_contact(context: &Context, contact_id: u32) -> bool {
let count_contacts: i32 = dc_sqlite3_query_row(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;",
params![contact_id as i32],
0,
@@ -1057,7 +1036,7 @@ pub fn dc_get_real_contact_cnt(context: &Context) -> usize {
dc_sqlite3_query_row::<_, isize>(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"SELECT COUNT(*) FROM contacts WHERE id>?;",
params![9],
0,
@@ -1094,13 +1073,9 @@ pub fn dc_real_contact_exists(context: &Context, contact_id: u32) -> bool {
return false;
}
dc_sqlite3_prepare(
context,
&context.sql.clone().read().unwrap(),
"SELECT id FROM contacts WHERE id=?;",
)
.map(|mut stmt| stmt.exists(params![contact_id as i32]).unwrap_or_default())
.unwrap_or_default()
dc_sqlite3_prepare(context, &context.sql, "SELECT id FROM contacts WHERE id=?;")
.map(|mut stmt| stmt.exists(params![contact_id as i32]).unwrap_or_default())
.unwrap_or_default()
}
pub fn dc_scaleup_contact_origin(context: &Context, contact_id: u32, origin: libc::c_int) -> bool {

View File

@@ -69,11 +69,11 @@ 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 mut sql = SQLite::new();
if sql.open(context, &path, 0x1i32) {
let sql = SQLite::new();
if sql.open(context, &path, 0x1) {
let curr_backup_time = dc_sqlite3_get_config_int(
context,
&mut sql,
&sql,
b"backup_time\x00" as *const u8 as *const libc::c_char,
0i32,
) as u64;
@@ -955,7 +955,7 @@ The macro avoids weird values of 0% or 100% while still working. */
unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_int {
let mut current_block: u64;
let mut success: libc::c_int = 0;
let mut closed: libc::c_int;
let mut closed: bool = false;
let mut delete_dest_file: libc::c_int = 0;
// get a fine backup file name (the name includes the date so that multiple backup instances are possible)
@@ -979,8 +979,8 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
dc_housekeeping(context);
dc_sqlite3_try_execute(context, &context.sql, "VACUUM;");
dc_sqlite3_close(context, &mut context.sql);
closed = 1;
context.sql.close();
closed = true;
dc_log_info(
context,
0,
@@ -990,7 +990,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
);
if !(0 == dc_copy_file(context, context.get_dbfile(), dest_pathNfilename)) {
context.sql.open(&context, as_path(context.get_dbfile()), 0);
closed = 0;
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();
@@ -1110,7 +1110,6 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
current_block = 11487273724841241105;
break;
}
// TODO: do we need to reset the stmt?
} else {
continue;
}
@@ -1145,13 +1144,9 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
}
}
}
if 0 != closed {
if closed {
context.sql.open(&context, as_path(context.get_dbfile()), 0);
}
sqlite3_finalize(stmt);
if let Some(sql) = dest_sql.take() {
sql.close(&context);
}
if 0 != delete_dest_file {
dc_delete_file(context, dest_pathNfilename);
}

View File

@@ -97,8 +97,8 @@ macro_rules! info {
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {{
let formatted = format!($msg, $($args),*);
let formatted_c = $crate::dc_tools::to_cstring(formatted);
$ctx.call_cb($crate::constants::Event::INFO, $data1 as uintptr_t,
formatted_c.as_ptr() as uintptr_t)
$ctx.call_cb($crate::constants::Event::INFO, $data1 as libc::uintptr_t,
formatted_c.as_ptr() as libc::uintptr_t)
}};
}
@@ -123,8 +123,8 @@ macro_rules! error {
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
let formatted = format!($msg, $($args),*);
let formatted_c = $crate::dc_tools::to_cstring(formatted);
$ctx.call_cb($crate::constants::Event::ERROR, $data1 as uintptr_t,
formatted_c.as_ptr() as uintptr_t)
$ctx.call_cb($crate::constants::Event::ERROR, $data1 as libc::uintptr_t,
formatted_c.as_ptr() as libc::uintptr_t)
};
}
@@ -136,7 +136,7 @@ macro_rules! log_event {
($ctx:expr, $event:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
let formatted = format!($msg, $($args),*);
let formatted_c = $crate::dc_tools::to_cstring(formatted);
$ctx.call_cb($event, $data1 as uintptr_t,
formatted_c.as_ptr() as uintptr_t)
$ctx.call_cb($event, $data1 as libc::uintptr_t,
formatted_c.as_ptr() as libc::uintptr_t)
};
}

View File

@@ -851,7 +851,7 @@ pub fn dc_sqlite3_prepare<'a>(
}
}
pub fn dc_sqlite3_is_open(sql: &dc_sqlite3_t) -> libc::c_int {
pub fn dc_sqlite3_is_open(sql: &SQLite) -> libc::c_int {
unsafe { sql.raw().is_none() as libc::c_int }
}

View File

@@ -1598,12 +1598,7 @@ impl Imap {
}
}
dc_sqlite3_set_config_int(
context,
&context.sql.read().unwrap(),
"folders_configured",
3,
);
dc_sqlite3_set_config_int(context, &context.sql, "folders_configured", 3);
if let Some(ref mvbox_folder) = mvbox_folder {
dc_sqlite3_set_config(
context,

View File

@@ -12,7 +12,6 @@ use crate::constants::*;
use crate::context::Context;
use crate::dc_sqlite3::*;
use crate::dc_tools::*;
use crate::types::*;
use crate::x::*;
#[derive(Debug, PartialEq, Eq, Clone)]

View File

@@ -6,7 +6,6 @@ use serde::Deserialize;
use crate::context::Context;
use crate::dc_sqlite3::*;
use crate::dc_tools::*;
use crate::types::*;
const OAUTH2_GMAIL: Oauth2 = Oauth2 {
client_id: "959970109878-4mvtgf6feshskf7695nfln6002mom908.apps.googleusercontent.com",
@@ -52,7 +51,7 @@ pub fn dc_get_oauth2_url(
if let Some(oauth2) = Oauth2::from_address(addr) {
dc_sqlite3_set_config(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"oauth2_pending_redirect_uri",
Some(redirect_uri.as_ref()),
);
@@ -79,66 +78,45 @@ 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.clone().read().unwrap(),
"oauth2_access_token",
None,
);
let access_token =
dc_sqlite3_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.clone().read().unwrap(),
"oauth2_refresh_token",
None,
);
let refresh_token_for = dc_sqlite3_get_config(
context,
&context.sql.clone().read().unwrap(),
"oauth2_refresh_token_for",
None,
)
.unwrap_or_else(|| "unset".into());
let refresh_token =
dc_sqlite3_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)
.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.clone().read().unwrap(),
"oauth2_pending_redirect_uri",
None,
)
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.clone().read().unwrap(),
"oauth2_redirect_uri",
None,
)
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,
)
};
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());
@@ -177,15 +155,10 @@ 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(
context,
&context.sql.clone().read().unwrap(),
"oauth2_refresh_token",
Some(token),
);
dc_sqlite3_set_config(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"oauth2_refresh_token_for",
Some(code.as_ref()),
);
@@ -194,12 +167,7 @@ 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.clone().read().unwrap(),
"oauth2_access_token",
Some(token),
);
dc_sqlite3_set_config(context, &context.sql, "oauth2_access_token", Some(token));
let expires_in = response
.expires_in
// refresh a bet before
@@ -207,7 +175,7 @@ pub fn dc_get_oauth2_access_token(
.unwrap_or_else(|| 0);
dc_sqlite3_set_config_int64(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"oauth2_timestamp_expires",
expires_in,
);
@@ -215,7 +183,7 @@ pub fn dc_get_oauth2_access_token(
if update_redirect_uri_on_success {
dc_sqlite3_set_config(
context,
&context.sql.clone().read().unwrap(),
&context.sql,
"oauth2_redirect_uri",
Some(redirect_uri.as_ref()),
);

View File

@@ -9,7 +9,6 @@ use crate::context::Context;
use crate::dc_chat::*;
use crate::dc_sqlite3::*;
use crate::key::*;
use crate::types::*;
/// Peerstate represents the state of an Autocrypt peer.
pub struct Peerstate<'a> {
@@ -195,9 +194,7 @@ impl<'a> Peerstate<'a> {
{
let mut res = Self::new(context);
if let Some(mut stmt) =
dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), query)
{
if let Some(mut stmt) = dc_sqlite3_prepare(context, &context.sql, query) {
stmt.query_row(params, |row| {
res.addr = Some(row.get(0)?);
res.last_seen = row.get(1)?;