mirror of
https://github.com/librespot-org/librespot.git
synced 2024-11-08 16:45:43 +00:00
discovery::server: fix activeUser field of getInfo (#1235)
This commit is contained in:
parent
fdf62d199d
commit
8fab3d66e2
1 changed files with 23 additions and 8 deletions
|
@ -4,7 +4,7 @@ use std::{
|
||||||
convert::Infallible,
|
convert::Infallible,
|
||||||
net::{Ipv4Addr, SocketAddr, TcpListener},
|
net::{Ipv4Addr, SocketAddr, TcpListener},
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
sync::Arc,
|
sync::{Arc, Mutex},
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ pub struct Config {
|
||||||
|
|
||||||
struct RequestHandler {
|
struct RequestHandler {
|
||||||
config: Config,
|
config: Config,
|
||||||
username: Option<String>,
|
username: Mutex<Option<String>>,
|
||||||
keys: DhLocalKeys,
|
keys: DhLocalKeys,
|
||||||
tx: mpsc::UnboundedSender<Credentials>,
|
tx: mpsc::UnboundedSender<Credentials>,
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ impl RequestHandler {
|
||||||
|
|
||||||
let discovery = Self {
|
let discovery = Self {
|
||||||
config,
|
config,
|
||||||
username: None,
|
username: Mutex::new(None),
|
||||||
keys: DhLocalKeys::random(&mut rand::thread_rng()),
|
keys: DhLocalKeys::random(&mut rand::thread_rng()),
|
||||||
tx,
|
tx,
|
||||||
};
|
};
|
||||||
|
@ -64,13 +64,20 @@ impl RequestHandler {
|
||||||
(discovery, rx)
|
(discovery, rx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn active_user(&self) -> String {
|
||||||
|
if let Ok(maybe_username) = self.username.lock() {
|
||||||
|
maybe_username.clone().unwrap_or(String::new())
|
||||||
|
} else {
|
||||||
|
warn!("username lock corrupted; read failed");
|
||||||
|
String::from("!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_get_info(&self) -> Response<Full<Bytes>> {
|
fn handle_get_info(&self) -> Response<Full<Bytes>> {
|
||||||
let public_key = BASE64.encode(self.keys.public_key());
|
let public_key = BASE64.encode(self.keys.public_key());
|
||||||
let device_type: &str = self.config.device_type.into();
|
let device_type: &str = self.config.device_type.into();
|
||||||
let mut active_user = String::new();
|
let active_user = self.active_user();
|
||||||
if let Some(username) = &self.username {
|
|
||||||
active_user = username.to_string();
|
|
||||||
}
|
|
||||||
// options based on zeroconf guide, search for `groupStatus` on page
|
// options based on zeroconf guide, search for `groupStatus` on page
|
||||||
let group_status = if self.config.is_group {
|
let group_status = if self.config.is_group {
|
||||||
"GROUP"
|
"GROUP"
|
||||||
|
@ -193,7 +200,15 @@ impl RequestHandler {
|
||||||
|
|
||||||
let credentials = Credentials::with_blob(username, decrypted, &self.config.device_id)?;
|
let credentials = Credentials::with_blob(username, decrypted, &self.config.device_id)?;
|
||||||
|
|
||||||
self.tx.send(credentials)?;
|
{
|
||||||
|
let maybe_username = self.username.lock();
|
||||||
|
self.tx.send(credentials)?;
|
||||||
|
if let Ok(mut username_field) = maybe_username {
|
||||||
|
*username_field = Some(String::from(username));
|
||||||
|
} else {
|
||||||
|
warn!("username lock corrupted; write failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let result = json!({
|
let result = json!({
|
||||||
"status": 101,
|
"status": 101,
|
||||||
|
|
Loading…
Reference in a new issue