mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 15:06:30 +03:00
Use enum type for Bob status
This commit is contained in:
committed by
link2xt
parent
0f164861c7
commit
8f290530fd
@@ -205,8 +205,6 @@ pub const DC_LP_AUTH_FLAGS: i32 = DC_LP_AUTH_OAUTH2 | DC_LP_AUTH_NORMAL;
|
||||
// QR code scanning (view from Bob, the joiner)
|
||||
pub const DC_VC_AUTH_REQUIRED: i32 = 2;
|
||||
pub const DC_VC_CONTACT_CONFIRM: i32 = 6;
|
||||
pub const DC_BOB_ERROR: i32 = 0;
|
||||
pub const DC_BOB_SUCCESS: i32 = 1;
|
||||
|
||||
// max. width/height of an avatar
|
||||
pub const AVATAR_SIZE: u32 = 192;
|
||||
|
||||
@@ -17,9 +17,9 @@ use crate::error::*;
|
||||
use crate::events::{Event, EventEmitter, EventType, Events};
|
||||
use crate::key::{DcKey, SignedPublicKey};
|
||||
use crate::login_param::LoginParam;
|
||||
use crate::lot::Lot;
|
||||
use crate::message::{self, MsgId};
|
||||
use crate::scheduler::Scheduler;
|
||||
use crate::securejoin::Bob;
|
||||
use crate::sql::Sql;
|
||||
use std::time::SystemTime;
|
||||
|
||||
@@ -44,7 +44,7 @@ pub struct InnerContext {
|
||||
pub(crate) blobdir: PathBuf,
|
||||
pub(crate) sql: Sql,
|
||||
pub(crate) os_name: Option<String>,
|
||||
pub(crate) bob: RwLock<BobStatus>,
|
||||
pub(crate) bob: RwLock<Bob>,
|
||||
pub(crate) last_smeared_timestamp: RwLock<i64>,
|
||||
pub(crate) running_state: RwLock<RunningState>,
|
||||
/// Mutex to avoid generating the key for the user more than once.
|
||||
@@ -508,13 +508,6 @@ impl Default for RunningState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct BobStatus {
|
||||
pub expects: i32,
|
||||
pub status: i32,
|
||||
pub qr_scan: Option<Lot>,
|
||||
}
|
||||
|
||||
pub fn get_version_str() -> &'static str {
|
||||
&DC_VERSION_STR
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ use crate::message::{self, MessageState, MessengerMessage, MsgId};
|
||||
use crate::mimeparser::*;
|
||||
use crate::param::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::securejoin::{self, handle_securejoin_handshake, observe_securejoin_on_other_device};
|
||||
use crate::securejoin::{
|
||||
self, handle_securejoin_handshake, observe_securejoin_on_other_device, BobStatus,
|
||||
};
|
||||
use crate::stock::StockMessage;
|
||||
use crate::{contact, location};
|
||||
|
||||
@@ -417,7 +419,7 @@ async fn add_parts(
|
||||
Err(err) => {
|
||||
*hidden = true;
|
||||
|
||||
context.bob.write().await.status = 0; // secure-join failed
|
||||
context.bob.write().await.status = BobStatus::Error; // secure-join failed
|
||||
context.stop_ongoing().await;
|
||||
warn!(context, "Error in Secure-Join message handling: {}", err);
|
||||
return Ok(());
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::error::{bail, Error};
|
||||
use crate::events::EventType;
|
||||
use crate::headerdef::HeaderDef;
|
||||
use crate::key::{DcKey, Fingerprint, SignedPublicKey};
|
||||
use crate::lot::LotState;
|
||||
use crate::lot::{Lot, LotState};
|
||||
use crate::message::Message;
|
||||
use crate::mimeparser::*;
|
||||
use crate::param::*;
|
||||
@@ -67,6 +67,25 @@ macro_rules! get_qr_attr {
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) enum BobStatus {
|
||||
Error,
|
||||
Success,
|
||||
}
|
||||
|
||||
impl Default for BobStatus {
|
||||
fn default() -> Self {
|
||||
Self::Error
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Bob {
|
||||
pub expects: i32,
|
||||
pub status: BobStatus,
|
||||
pub qr_scan: Option<Lot>,
|
||||
}
|
||||
|
||||
pub async fn dc_get_securejoin_qr(context: &Context, group_chat_id: ChatId) -> Option<String> {
|
||||
/*=======================================================
|
||||
==== Alice - the inviter side ====
|
||||
@@ -160,7 +179,7 @@ async fn cleanup(
|
||||
) -> ChatId {
|
||||
let mut bob = context.bob.write().await;
|
||||
bob.expects = 0;
|
||||
let ret_chat_id: ChatId = if bob.status == DC_BOB_SUCCESS {
|
||||
let ret_chat_id: ChatId = if bob.status == BobStatus::Success {
|
||||
if join_vg {
|
||||
chat::get_chat_id_by_grpid(
|
||||
context,
|
||||
@@ -223,7 +242,7 @@ async fn securejoin(context: &Context, qr: &str) -> ChatId {
|
||||
join_vg = qr_scan.get_state() == LotState::QrAskVerifyGroup;
|
||||
{
|
||||
let mut bob = context.bob.write().await;
|
||||
bob.status = 0;
|
||||
bob.status = BobStatus::Error;
|
||||
bob.qr_scan = Some(qr_scan);
|
||||
}
|
||||
if fingerprint_equals_sender(
|
||||
@@ -545,7 +564,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
||||
},
|
||||
)
|
||||
.await;
|
||||
context.bob.write().await.status = 0; // secure-join failed
|
||||
context.bob.write().await.status = BobStatus::Error; // secure-join failed
|
||||
context.stop_ongoing().await;
|
||||
return Ok(HandshakeMessage::Ignore);
|
||||
}
|
||||
@@ -558,7 +577,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
||||
"Fingerprint mismatch on joiner-side.",
|
||||
)
|
||||
.await;
|
||||
context.bob.write().await.status = 0; // secure-join failed
|
||||
context.bob.write().await.status = BobStatus::Error; // secure-join failed
|
||||
context.stop_ongoing().await;
|
||||
return Ok(HandshakeMessage::Ignore);
|
||||
}
|
||||
@@ -756,7 +775,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
||||
"Contact confirm message not encrypted.",
|
||||
)
|
||||
.await;
|
||||
context.bob.write().await.status = 0;
|
||||
context.bob.write().await.status = BobStatus::Error;
|
||||
return Ok(abort_retval);
|
||||
}
|
||||
|
||||
@@ -805,7 +824,7 @@ pub(crate) async fn handle_securejoin_handshake(
|
||||
)
|
||||
.await?;
|
||||
|
||||
context.bob.write().await.status = 1;
|
||||
context.bob.write().await.status = BobStatus::Success;
|
||||
context.stop_ongoing().await;
|
||||
Ok(if join_vg {
|
||||
HandshakeMessage::Propagate
|
||||
|
||||
Reference in New Issue
Block a user