mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
Clean up the worst rebase mistakes
This commit is contained in:
committed by
dignifiedquire
parent
ab41679855
commit
a791af2d90
@@ -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(
|
if let Some(mut stmt) = dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
&context.sql.read().unwrap(),
|
&context.sql,
|
||||||
"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \
|
"SELECT c.id,c.type,c.name, c.grpid,c.param,c.archived, \
|
||||||
c.blocked, c.gossiped_timestamp, c.locations_send_until \
|
c.blocked, c.gossiped_timestamp, c.locations_send_until \
|
||||||
FROM chats c WHERE c.id=?;",
|
FROM chats c WHERE c.id=?;",
|
||||||
@@ -723,7 +723,7 @@ unsafe fn prepare_msg_raw(
|
|||||||
) {
|
) {
|
||||||
msg_id = dc_sqlite3_get_rowid(
|
msg_id = dc_sqlite3_get_rowid(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"msgs",
|
"msgs",
|
||||||
"rfc724_mid",
|
"rfc724_mid",
|
||||||
as_str(new_rfc724_mid),
|
as_str(new_rfc724_mid),
|
||||||
@@ -1127,7 +1127,7 @@ pub unsafe fn dc_get_chat_msgs(
|
|||||||
} else {
|
} else {
|
||||||
if let Some(mut stmt) = dc_sqlite3_prepare(
|
if let Some(mut stmt) = dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
&sql,
|
&context.sql,
|
||||||
"SELECT m.id, m.timestamp FROM msgs m \
|
"SELECT m.id, m.timestamp FROM msgs m \
|
||||||
WHERE m.chat_id=? \
|
WHERE m.chat_id=? \
|
||||||
AND m.hidden=0 \
|
AND m.hidden=0 \
|
||||||
@@ -1203,7 +1203,6 @@ pub fn dc_marknoticed_chat(context: &Context, chat_id: u32) -> bool {
|
|||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dc_sqlite3_execute(
|
if !dc_sqlite3_execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
@@ -1213,16 +1212,14 @@ pub fn dc_marknoticed_chat(context: &Context, chat_id: u32) -> bool {
|
|||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
||||||
unsafe { (context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t) };
|
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
|
pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
|
||||||
if !dc_sqlite3_execute(
|
if !dc_sqlite3_execute(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"SELECT id FROM msgs \
|
"SELECT id FROM msgs \
|
||||||
WHERE state=10;",
|
WHERE state=10;",
|
||||||
params![],
|
params![],
|
||||||
@@ -1240,7 +1237,7 @@ pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
|
|||||||
return false;
|
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
|
true
|
||||||
}
|
}
|
||||||
@@ -1415,7 +1412,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) {
|
|||||||
return;
|
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);
|
dc_job_kill_action(context, 105);
|
||||||
unsafe { dc_job_add(context, 105, 0, 0 as *const libc::c_char, 10) };
|
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=?;",
|
"DELETE FROM chats_contacts WHERE chat_id=? AND contact_id=?;",
|
||||||
params![chat_id as i32, contact_id as i32],
|
params![chat_id as i32, contact_id as i32],
|
||||||
) {
|
) {
|
||||||
(context.cb)(
|
context.call_cb(Event::CHAT_MODIFIED, chat_id as uintptr_t, 0 as uintptr_t);
|
||||||
context,
|
|
||||||
Event::CHAT_MODIFIED,
|
|
||||||
chat_id as uintptr_t,
|
|
||||||
0 as uintptr_t,
|
|
||||||
);
|
|
||||||
success = 1;
|
success = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2251,7 +2243,7 @@ pub unsafe fn dc_get_chat_id_by_grpid(
|
|||||||
|
|
||||||
dc_sqlite3_prepare(
|
dc_sqlite3_prepare(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"SELECT id, blocked, type FROM chats WHERE grpid=?;",
|
"SELECT id, blocked, type FROM chats WHERE grpid=?;",
|
||||||
)
|
)
|
||||||
.and_then(|mut stmt| {
|
.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(
|
if !dc_sqlite3_execute(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);",
|
"INSERT INTO msgs (chat_id,from_id,to_id, timestamp,type,state, txt,rfc724_mid) VALUES (?,?,?, ?,?,?, ?,?);",
|
||||||
params![
|
params![
|
||||||
chat_id as i32,
|
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(
|
let msg_id = dc_sqlite3_get_rowid(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"msgs",
|
"msgs",
|
||||||
"rfc724_mid",
|
"rfc724_mid",
|
||||||
as_str(rfc724_mid),
|
as_str(rfc724_mid),
|
||||||
);
|
);
|
||||||
unsafe { free(rfc724_mid as *mut libc::c_void) };
|
unsafe { free(rfc724_mid as *mut libc::c_void) };
|
||||||
unsafe {
|
context.call_cb(
|
||||||
(context.cb)(
|
Event::MSGS_CHANGED,
|
||||||
context,
|
chat_id as uintptr_t,
|
||||||
Event::MSGS_CHANGED,
|
msg_id as uintptr_t,
|
||||||
chat_id as uintptr_t,
|
);
|
||||||
msg_id as uintptr_t,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ unsafe fn dc_chatlist_load_from_db(
|
|||||||
} else if 0 != listflags & 0x1 {
|
} else if 0 != listflags & 0x1 {
|
||||||
if let Some(mut stmt) = dc_sqlite3_prepare(
|
if let Some(mut stmt) = dc_sqlite3_prepare(
|
||||||
(*chatlist).context,
|
(*chatlist).context,
|
||||||
&(*chatlist).context,
|
&(*chatlist).context.sql,
|
||||||
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
|
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
|
||||||
ON c.id=m.chat_id \
|
ON c.id=m.chat_id \
|
||||||
AND m.timestamp=( SELECT MAX(timestamp) \
|
AND m.timestamp=( SELECT MAX(timestamp) \
|
||||||
@@ -220,7 +220,7 @@ unsafe fn dc_chatlist_load_from_db(
|
|||||||
let strLikeCmd = format!("%{}%", query);
|
let strLikeCmd = format!("%{}%", query);
|
||||||
if let Some(mut stmt) = dc_sqlite3_prepare(
|
if let Some(mut stmt) = dc_sqlite3_prepare(
|
||||||
(*chatlist).context,
|
(*chatlist).context,
|
||||||
&(*chatlist).context.sql.clone().read().unwrap(),
|
&(*chatlist).context.sql,
|
||||||
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
|
"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m \
|
||||||
ON c.id=m.chat_id \
|
ON c.id=m.chat_id \
|
||||||
AND m.timestamp=( SELECT MAX(timestamp) \
|
AND m.timestamp=( SELECT MAX(timestamp) \
|
||||||
|
|||||||
@@ -152,8 +152,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
|
|||||||
0i32 as uintptr_t,
|
0i32 as uintptr_t,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut param =
|
let mut param = dc_loginparam_read(context, &context.sql, "");
|
||||||
dc_loginparam_read(context, &context.sql.clone().read().unwrap(), "");
|
|
||||||
if param.addr.is_empty() {
|
if param.addr.is_empty() {
|
||||||
error!(context, 0, "Please enter an email address.",);
|
error!(context, 0, "Please enter an email address.",);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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;",
|
"UPDATE msgs SET state=13 WHERE from_id=? AND state=10;",
|
||||||
params![contact_id as i32],
|
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_c = dc_addr_normalize(addr);
|
||||||
let addr_normalized = as_str(addr_normalized_c);
|
let addr_normalized = as_str(addr_normalized_c);
|
||||||
let addr_self = dc_sqlite3_get_config(
|
let addr_self =
|
||||||
context,
|
dc_sqlite3_get_config(context, &context.sql, "configured_addr", None).unwrap_or_default();
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"configured_addr",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let contact_id = if addr_normalized == addr_self {
|
let contact_id = if addr_normalized == addr_self {
|
||||||
1
|
1
|
||||||
@@ -338,13 +333,8 @@ pub fn dc_add_or_lookup_contact(
|
|||||||
|
|
||||||
let addr_c = unsafe { dc_addr_normalize(addr__) };
|
let addr_c = unsafe { dc_addr_normalize(addr__) };
|
||||||
let addr = as_str(addr_c);
|
let addr = as_str(addr_c);
|
||||||
let addr_self = dc_sqlite3_get_config(
|
let addr_self = dc_sqlite3_get_config(context, &context.sql, "configured_addr", Some(""))
|
||||||
context,
|
.unwrap_or_default();
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"configured_addr",
|
|
||||||
Some(""),
|
|
||||||
)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
if addr == addr_self {
|
if addr == addr_self {
|
||||||
return 1;
|
return 1;
|
||||||
@@ -428,7 +418,7 @@ pub fn dc_add_or_lookup_contact(
|
|||||||
if update_name {
|
if update_name {
|
||||||
dc_sqlite3_execute(
|
dc_sqlite3_execute(
|
||||||
context,
|
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=?);",
|
"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]
|
params![as_str(name), 100, row_id]
|
||||||
);
|
);
|
||||||
@@ -438,7 +428,7 @@ pub fn dc_add_or_lookup_contact(
|
|||||||
} else {
|
} else {
|
||||||
if dc_sqlite3_execute(
|
if dc_sqlite3_execute(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);",
|
"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);",
|
||||||
params![
|
params![
|
||||||
if !name.is_null() { as_str(name) } else { "" },
|
if !name.is_null() { as_str(name) } else { "" },
|
||||||
@@ -446,13 +436,7 @@ pub fn dc_add_or_lookup_contact(
|
|||||||
origin,
|
origin,
|
||||||
],
|
],
|
||||||
) {
|
) {
|
||||||
row_id = dc_sqlite3_get_rowid(
|
row_id = dc_sqlite3_get_rowid(context, &context.sql, "contacts", "addr", addr);
|
||||||
context,
|
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"contacts",
|
|
||||||
"addr",
|
|
||||||
addr,
|
|
||||||
);
|
|
||||||
unsafe { *sth_modified = 2 };
|
unsafe { *sth_modified = 2 };
|
||||||
} else {
|
} else {
|
||||||
error!(context, 0, "Cannot add contact.");
|
error!(context, 0, "Cannot add contact.");
|
||||||
@@ -602,13 +586,8 @@ pub fn dc_get_contacts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let self_name = dc_sqlite3_get_config(
|
let self_name = dc_sqlite3_get_config(context, &context.sql, "displayname", Some(""))
|
||||||
context,
|
.unwrap_or_default();
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"displayname",
|
|
||||||
Some(""),
|
|
||||||
)
|
|
||||||
.unwrap_or_default();
|
|
||||||
|
|
||||||
let self_name2 = unsafe { dc_stock_str(context, 2) };
|
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(
|
let count_contacts: i32 = dc_sqlite3_query_row(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;",
|
"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;",
|
||||||
params![contact_id as i32],
|
params![contact_id as i32],
|
||||||
0,
|
0,
|
||||||
@@ -1057,7 +1036,7 @@ pub fn dc_get_real_contact_cnt(context: &Context) -> usize {
|
|||||||
|
|
||||||
dc_sqlite3_query_row::<_, isize>(
|
dc_sqlite3_query_row::<_, isize>(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"SELECT COUNT(*) FROM contacts WHERE id>?;",
|
"SELECT COUNT(*) FROM contacts WHERE id>?;",
|
||||||
params![9],
|
params![9],
|
||||||
0,
|
0,
|
||||||
@@ -1094,13 +1073,9 @@ pub fn dc_real_contact_exists(context: &Context, contact_id: u32) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_sqlite3_prepare(
|
dc_sqlite3_prepare(context, &context.sql, "SELECT id FROM contacts WHERE id=?;")
|
||||||
context,
|
.map(|mut stmt| stmt.exists(params![contact_id as i32]).unwrap_or_default())
|
||||||
&context.sql.clone().read().unwrap(),
|
.unwrap_or_default()
|
||||||
"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 {
|
pub fn dc_scaleup_contact_origin(context: &Context, contact_id: u32, origin: libc::c_int) -> bool {
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ pub unsafe fn dc_imex_has_backup(
|
|||||||
let name = dirent.file_name();
|
let name = dirent.file_name();
|
||||||
let name = name.to_string_lossy();
|
let name = name.to_string_lossy();
|
||||||
if name.starts_with("delta-chat") && name.ends_with(".bak") {
|
if name.starts_with("delta-chat") && name.ends_with(".bak") {
|
||||||
let mut sql = SQLite::new();
|
let sql = SQLite::new();
|
||||||
if sql.open(context, &path, 0x1i32) {
|
if sql.open(context, &path, 0x1) {
|
||||||
let curr_backup_time = dc_sqlite3_get_config_int(
|
let curr_backup_time = dc_sqlite3_get_config_int(
|
||||||
context,
|
context,
|
||||||
&mut sql,
|
&sql,
|
||||||
b"backup_time\x00" as *const u8 as *const libc::c_char,
|
b"backup_time\x00" as *const u8 as *const libc::c_char,
|
||||||
0i32,
|
0i32,
|
||||||
) as u64;
|
) 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 {
|
unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_int {
|
||||||
let mut current_block: u64;
|
let mut current_block: u64;
|
||||||
let mut success: libc::c_int = 0;
|
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;
|
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)
|
// 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_housekeeping(context);
|
||||||
|
|
||||||
dc_sqlite3_try_execute(context, &context.sql, "VACUUM;");
|
dc_sqlite3_try_execute(context, &context.sql, "VACUUM;");
|
||||||
dc_sqlite3_close(context, &mut context.sql);
|
context.sql.close();
|
||||||
closed = 1;
|
closed = true;
|
||||||
dc_log_info(
|
dc_log_info(
|
||||||
context,
|
context,
|
||||||
0,
|
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)) {
|
if !(0 == dc_copy_file(context, context.get_dbfile(), dest_pathNfilename)) {
|
||||||
context.sql.open(&context, as_path(context.get_dbfile()), 0);
|
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) */
|
/* 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*/
|
/*for logging only*/
|
||||||
let sql = SQLite::new();
|
let sql = SQLite::new();
|
||||||
@@ -1110,7 +1110,6 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
|
|||||||
current_block = 11487273724841241105;
|
current_block = 11487273724841241105;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO: do we need to reset the stmt?
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
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);
|
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 {
|
if 0 != delete_dest_file {
|
||||||
dc_delete_file(context, dest_pathNfilename);
|
dc_delete_file(context, dest_pathNfilename);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ macro_rules! info {
|
|||||||
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {{
|
||||||
let formatted = format!($msg, $($args),*);
|
let formatted = format!($msg, $($args),*);
|
||||||
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
||||||
$ctx.call_cb($crate::constants::Event::INFO, $data1 as uintptr_t,
|
$ctx.call_cb($crate::constants::Event::INFO, $data1 as libc::uintptr_t,
|
||||||
formatted_c.as_ptr() as 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),* $(,)?) => {
|
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||||
let formatted = format!($msg, $($args),*);
|
let formatted = format!($msg, $($args),*);
|
||||||
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
||||||
$ctx.call_cb($crate::constants::Event::ERROR, $data1 as uintptr_t,
|
$ctx.call_cb($crate::constants::Event::ERROR, $data1 as libc::uintptr_t,
|
||||||
formatted_c.as_ptr() as 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),* $(,)?) => {
|
($ctx:expr, $event:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
||||||
let formatted = format!($msg, $($args),*);
|
let formatted = format!($msg, $($args),*);
|
||||||
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
let formatted_c = $crate::dc_tools::to_cstring(formatted);
|
||||||
$ctx.call_cb($event, $data1 as uintptr_t,
|
$ctx.call_cb($event, $data1 as libc::uintptr_t,
|
||||||
formatted_c.as_ptr() as uintptr_t)
|
formatted_c.as_ptr() as libc::uintptr_t)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 }
|
unsafe { sql.raw().is_none() as libc::c_int }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1598,12 +1598,7 @@ impl Imap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_sqlite3_set_config_int(
|
dc_sqlite3_set_config_int(context, &context.sql, "folders_configured", 3);
|
||||||
context,
|
|
||||||
&context.sql.read().unwrap(),
|
|
||||||
"folders_configured",
|
|
||||||
3,
|
|
||||||
);
|
|
||||||
if let Some(ref mvbox_folder) = mvbox_folder {
|
if let Some(ref mvbox_folder) = mvbox_folder {
|
||||||
dc_sqlite3_set_config(
|
dc_sqlite3_set_config(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ use crate::constants::*;
|
|||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_sqlite3::*;
|
use crate::dc_sqlite3::*;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::types::*;
|
|
||||||
use crate::x::*;
|
use crate::x::*;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
|
|||||||
104
src/oauth2.rs
104
src/oauth2.rs
@@ -6,7 +6,6 @@ use serde::Deserialize;
|
|||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_sqlite3::*;
|
use crate::dc_sqlite3::*;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::types::*;
|
|
||||||
|
|
||||||
const OAUTH2_GMAIL: Oauth2 = Oauth2 {
|
const OAUTH2_GMAIL: Oauth2 = Oauth2 {
|
||||||
client_id: "959970109878-4mvtgf6feshskf7695nfln6002mom908.apps.googleusercontent.com",
|
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) {
|
if let Some(oauth2) = Oauth2::from_address(addr) {
|
||||||
dc_sqlite3_set_config(
|
dc_sqlite3_set_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"oauth2_pending_redirect_uri",
|
"oauth2_pending_redirect_uri",
|
||||||
Some(redirect_uri.as_ref()),
|
Some(redirect_uri.as_ref()),
|
||||||
);
|
);
|
||||||
@@ -79,66 +78,45 @@ pub fn dc_get_oauth2_access_token(
|
|||||||
|
|
||||||
// read generated token
|
// read generated token
|
||||||
if 0 == flags & 0x1 && !is_expired(context) {
|
if 0 == flags & 0x1 && !is_expired(context) {
|
||||||
let access_token = dc_sqlite3_get_config(
|
let access_token =
|
||||||
context,
|
dc_sqlite3_get_config(context, &context.sql, "oauth2_access_token", None);
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"oauth2_access_token",
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
if access_token.is_some() {
|
if access_token.is_some() {
|
||||||
// success
|
// success
|
||||||
return access_token;
|
return access_token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let refresh_token = dc_sqlite3_get_config(
|
let refresh_token =
|
||||||
context,
|
dc_sqlite3_get_config(context, &context.sql, "oauth2_refresh_token", None);
|
||||||
&context.sql.clone().read().unwrap(),
|
let refresh_token_for =
|
||||||
"oauth2_refresh_token",
|
dc_sqlite3_get_config(context, &context.sql, "oauth2_refresh_token_for", None)
|
||||||
None,
|
.unwrap_or_else(|| "unset".into());
|
||||||
);
|
|
||||||
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 (redirect_uri, token_url, update_redirect_uri_on_success) =
|
let (redirect_uri, token_url, update_redirect_uri_on_success) = if refresh_token.is_none()
|
||||||
if refresh_token.is_none() || refresh_token_for != code.as_ref() {
|
|| refresh_token_for != code.as_ref()
|
||||||
info!(
|
{
|
||||||
context,
|
info!(
|
||||||
0, "Generate OAuth2 refresh_token and access_token...",
|
context,
|
||||||
);
|
0, "Generate OAuth2 refresh_token and access_token...",
|
||||||
(
|
);
|
||||||
dc_sqlite3_get_config(
|
(
|
||||||
context,
|
dc_sqlite3_get_config(context, &context.sql, "oauth2_pending_redirect_uri", None)
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"oauth2_pending_redirect_uri",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|| "unset".into()),
|
.unwrap_or_else(|| "unset".into()),
|
||||||
oauth2.init_token,
|
oauth2.init_token,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
0, "Regenerate OAuth2 access_token by refresh_token...",
|
0, "Regenerate OAuth2 access_token by refresh_token...",
|
||||||
);
|
);
|
||||||
(
|
(
|
||||||
dc_sqlite3_get_config(
|
dc_sqlite3_get_config(context, &context.sql, "oauth2_redirect_uri", None)
|
||||||
context,
|
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"oauth2_redirect_uri",
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|| "unset".into()),
|
.unwrap_or_else(|| "unset".into()),
|
||||||
oauth2.refresh_token,
|
oauth2.refresh_token,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let mut token_url = replace_in_uri(&token_url, "$CLIENT_ID", oauth2.client_id);
|
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, "$REDIRECT_URI", &redirect_uri);
|
||||||
token_url = replace_in_uri(&token_url, "$CODE", code.as_ref());
|
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);
|
println!("response: {:?}", &parsed);
|
||||||
let response = parsed.unwrap();
|
let response = parsed.unwrap();
|
||||||
if let Some(ref token) = response.refresh_token {
|
if let Some(ref token) = response.refresh_token {
|
||||||
|
dc_sqlite3_set_config(context, &context.sql, "oauth2_refresh_token", Some(token));
|
||||||
dc_sqlite3_set_config(
|
dc_sqlite3_set_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"oauth2_refresh_token",
|
|
||||||
Some(token),
|
|
||||||
);
|
|
||||||
dc_sqlite3_set_config(
|
|
||||||
context,
|
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"oauth2_refresh_token_for",
|
"oauth2_refresh_token_for",
|
||||||
Some(code.as_ref()),
|
Some(code.as_ref()),
|
||||||
);
|
);
|
||||||
@@ -194,12 +167,7 @@ pub fn dc_get_oauth2_access_token(
|
|||||||
// after that, save the 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 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 {
|
if let Some(ref token) = response.access_token {
|
||||||
dc_sqlite3_set_config(
|
dc_sqlite3_set_config(context, &context.sql, "oauth2_access_token", Some(token));
|
||||||
context,
|
|
||||||
&context.sql.clone().read().unwrap(),
|
|
||||||
"oauth2_access_token",
|
|
||||||
Some(token),
|
|
||||||
);
|
|
||||||
let expires_in = response
|
let expires_in = response
|
||||||
.expires_in
|
.expires_in
|
||||||
// refresh a bet before
|
// refresh a bet before
|
||||||
@@ -207,7 +175,7 @@ pub fn dc_get_oauth2_access_token(
|
|||||||
.unwrap_or_else(|| 0);
|
.unwrap_or_else(|| 0);
|
||||||
dc_sqlite3_set_config_int64(
|
dc_sqlite3_set_config_int64(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"oauth2_timestamp_expires",
|
"oauth2_timestamp_expires",
|
||||||
expires_in,
|
expires_in,
|
||||||
);
|
);
|
||||||
@@ -215,7 +183,7 @@ pub fn dc_get_oauth2_access_token(
|
|||||||
if update_redirect_uri_on_success {
|
if update_redirect_uri_on_success {
|
||||||
dc_sqlite3_set_config(
|
dc_sqlite3_set_config(
|
||||||
context,
|
context,
|
||||||
&context.sql.clone().read().unwrap(),
|
&context.sql,
|
||||||
"oauth2_redirect_uri",
|
"oauth2_redirect_uri",
|
||||||
Some(redirect_uri.as_ref()),
|
Some(redirect_uri.as_ref()),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use crate::context::Context;
|
|||||||
use crate::dc_chat::*;
|
use crate::dc_chat::*;
|
||||||
use crate::dc_sqlite3::*;
|
use crate::dc_sqlite3::*;
|
||||||
use crate::key::*;
|
use crate::key::*;
|
||||||
use crate::types::*;
|
|
||||||
|
|
||||||
/// Peerstate represents the state of an Autocrypt peer.
|
/// Peerstate represents the state of an Autocrypt peer.
|
||||||
pub struct Peerstate<'a> {
|
pub struct Peerstate<'a> {
|
||||||
@@ -195,9 +194,7 @@ impl<'a> Peerstate<'a> {
|
|||||||
{
|
{
|
||||||
let mut res = Self::new(context);
|
let mut res = Self::new(context);
|
||||||
|
|
||||||
if let Some(mut stmt) =
|
if let Some(mut stmt) = dc_sqlite3_prepare(context, &context.sql, query) {
|
||||||
dc_sqlite3_prepare(context, &context.sql.clone().read().unwrap(), query)
|
|
||||||
{
|
|
||||||
stmt.query_row(params, |row| {
|
stmt.query_row(params, |row| {
|
||||||
res.addr = Some(row.get(0)?);
|
res.addr = Some(row.get(0)?);
|
||||||
res.last_seen = row.get(1)?;
|
res.last_seen = row.get(1)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user