From 0c648a976551b5dc36409ff505bcac1059ede935 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Sun, 19 Oct 2025 16:34:44 +0200 Subject: [PATCH] =?UTF-8?q?il=20faut=20r=C3=A9parer=20la=20detection=20des?= =?UTF-8?q?=20devices?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/contentdirectory/handlers.rs | 11 +++- pmoupnp/src/ssdp/server.rs | 60 ++++++++++++++++--- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/pmomediaserver/src/contentdirectory/handlers.rs b/pmomediaserver/src/contentdirectory/handlers.rs index 413f09f6..b80d307a 100644 --- a/pmomediaserver/src/contentdirectory/handlers.rs +++ b/pmomediaserver/src/contentdirectory/handlers.rs @@ -26,7 +26,7 @@ use crate::content_handler::ContentHandler; use pmoupnp::actions::{ActionError, ActionHandler}; use pmoupnp::{action_handler, get, set}; -use tracing::{debug, error}; +use tracing::{debug, error, info}; /// Handler pour l'action Browse. /// @@ -61,6 +61,11 @@ pub fn browse_handler() -> ActionHandler { let _filter: String = get!(&data, "Filter", String); let _sort_criteria: String = get!(&data, "SortCriteria", String); + info!( + "πŸ“‚ Browse requested: object_id={} flag={} start={} count={}", + object_id, browse_flag, starting_index, requested_count + ); + // Appeler la logique mΓ©tier let (didl, returned, total, update_id) = handler .browse(&object_id, &browse_flag, starting_index, requested_count) @@ -80,6 +85,10 @@ pub fn browse_handler() -> ActionHandler { "βœ… Browse completed: returned={}, total={}", returned, total ); + info!( + "πŸ“‚ Browse completed: object_id={} returned={} total={}", + object_id, returned, total + ); Ok(data) }) } diff --git a/pmoupnp/src/ssdp/server.rs b/pmoupnp/src/ssdp/server.rs index 1b12a238..7df4bf43 100644 --- a/pmoupnp/src/ssdp/server.rs +++ b/pmoupnp/src/ssdp/server.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::net::{SocketAddr, UdpSocket}; use std::sync::{Arc, RwLock}; use std::time::Duration; -use tracing::{info, warn}; +use tracing::{debug, info, warn}; /// Serveur SSDP gΓ©rant les annonces et dΓ©couvertes pub struct SsdpServer { @@ -62,6 +62,17 @@ impl SsdpServer { devices.insert(uuid.clone(), device.clone()); drop(devices); + info!( + "πŸ†• SSDP device registered: {} ({} NTs)", + uuid, + device.get_notification_types().len() + ); + debug!( + "πŸ†• SSDP device notification types for {}: {:?}", + uuid, + device.get_notification_types() + ); + // Envoyer alive pour tous les NTs if let Some(ref socket) = self.socket { for nt in device.get_notification_types() { @@ -76,6 +87,12 @@ impl SsdpServer { if let Some(device) = devices.remove(uuid) { drop(devices); + info!( + "πŸ—‘οΈ SSDP device removed: {} ({} NTs)", + uuid, + device.get_notification_types().len() + ); + // Envoyer byebye pour tous les NTs if let Some(ref socket) = self.socket { for nt in device.get_notification_types() { @@ -111,7 +128,13 @@ impl SsdpServer { .unwrap(); match socket.send_to(msg.as_bytes(), addr) { - Ok(_) => info!("βœ… NOTIFY alive: {} (NT={})", usn, nt), + Ok(_) => { + info!("βœ… NOTIFY alive: {} (NT={})", usn, nt); + debug!( + "πŸ“£ NOTIFY alive payload\n
\n\n```\n{}\n```\n
\n", + msg + ); + } Err(e) => warn!("❌ Failed to send NOTIFY alive for {}: {}", usn, e), } } @@ -139,7 +162,13 @@ impl SsdpServer { .unwrap(); match socket.send_to(msg.as_bytes(), addr) { - Ok(_) => info!("πŸ‘‹ NOTIFY byebye: {} (NT={})", usn, nt), + Ok(_) => { + info!("πŸ‘‹ NOTIFY byebye: {} (NT={})", usn, nt); + debug!( + "πŸ“£ NOTIFY byebye payload\n
\n\n```\n{}\n```\n
\n", + msg + ); + } Err(e) => warn!("❌ Failed to send NOTIFY byebye for {}: {}", usn, e), } } @@ -151,6 +180,7 @@ impl SsdpServer { std::thread::spawn(move || { loop { + debug!("⏰ SSDP periodic announcement tick"); std::thread::sleep(period); let devices = devices.read().unwrap(); @@ -189,7 +219,13 @@ impl SsdpServer { .unwrap(); match socket.send_to(msg.as_bytes(), addr) { - Ok(_) => info!("βœ… NOTIFY alive (periodic): {} (NT={})", usn, nt), + Ok(_) => { + info!("βœ… NOTIFY alive (periodic): {} (NT={})", usn, nt); + debug!( + "πŸ“£ NOTIFY alive (periodic) payload\n
\n\n```\n{}\n```\n
\n", + msg + ); + } Err(e) => warn!("❌ Failed to send periodic NOTIFY alive for {}: {}", usn, e), } } @@ -205,6 +241,10 @@ impl SsdpServer { Ok((n, src)) => { let data = String::from_utf8_lossy(&buf[..n]); if data.starts_with("M-SEARCH") { + debug!( + "πŸ” M-SEARCH received from {}\n
\n\n```\n{}\n```\n
\n", + src, data + ); if let Some(st) = Self::parse_st(&data) { let devices = devices.read().unwrap(); for device in devices.values() { @@ -270,12 +310,14 @@ impl SsdpServer { \r\n", MAX_AGE, date, device.location, device.server, nt, usn ); - match socket.send_to(resp.as_bytes(), src) { - Ok(_) => info!( - "πŸ“‘ M-SEARCH response sent to {} with ST={}\n
\n\n```\n{}\n```\n
\n", - src, nt, resp - ), + Ok(_) => { + info!("πŸ“‘ M-SEARCH response sent to {} with ST={}", src, nt); + debug!( + "πŸ“‘ M-SEARCH response payload\n
\n\n```\n{}\n```\n
\n", + resp + ); + } Err(e) => warn!("❌ Failed to send M-SEARCH response to {}: {}", src, e), } }