make secure_join flow more readable by using and adding a few macros, tiny api changes

This commit is contained in:
holger krekel
2019-09-05 03:27:55 +02:00
parent 4bbab876ae
commit 9f09c73ec1
4 changed files with 150 additions and 229 deletions

View File

@@ -10,20 +10,17 @@ pub const DC_TOKEN_INVITENUMBER: dc_tokennamespc_t = 100;
// Functions to read/write token from/to the database. A token is any string associated with a key.
pub fn dc_token_save(
context: &Context,
namespc: dc_tokennamespc_t,
foreign_id: u32,
token: &str,
) -> bool {
pub fn dc_token_save(context: &Context, namespc: dc_tokennamespc_t, foreign_id: u32) -> String {
// foreign_id may be 0
let token = dc_create_id();
sql::execute(
context,
&context.sql,
"INSERT INTO tokens (namespc, foreign_id, token, timestamp) VALUES (?, ?, ?, ?);",
params![namespc as i32, foreign_id as i32, token, time()],
params![namespc as i32, foreign_id as i32, &token, time()],
)
.is_ok()
.ok();
token
}
pub fn dc_token_lookup(
@@ -39,6 +36,15 @@ pub fn dc_token_lookup(
)
}
pub fn dc_token_lookup_or_new(
context: &Context,
namespc: dc_tokennamespc_t,
foreign_id: u32,
) -> String {
dc_token_lookup(context, namespc, foreign_id)
.unwrap_or_else(|| dc_token_save(context, namespc, foreign_id))
}
pub fn dc_token_exists(context: &Context, namespc: dc_tokennamespc_t, token: &str) -> bool {
context
.sql