ok encore l'inconnu...
This commit is contained in:
@@ -576,7 +576,11 @@ impl Config {
|
||||
pub fn get_device_udn(&self, devtype: &str, name: &str) -> Result<String> {
|
||||
let path = &["devices", devtype, name, "udn"];
|
||||
match self.get_value(path) {
|
||||
Ok(Value::String(udn)) => Ok(udn),
|
||||
Ok(Value::String(udn)) => {
|
||||
let udn_str = udn.trim();
|
||||
let sanitized = udn_str.strip_prefix("uuid:").unwrap_or(udn_str).to_string();
|
||||
Ok(sanitized)
|
||||
}
|
||||
_ => {
|
||||
let new_udn = Uuid::new_v4().to_string();
|
||||
self.set_value(path, Value::String(new_udn.clone()))?;
|
||||
@@ -597,7 +601,9 @@ impl Config {
|
||||
///
|
||||
/// Returns a `Result` indicating success or failure
|
||||
pub fn set_device_udn(&self, devtype: &str, name: &str, udn: String) -> Result<()> {
|
||||
self.set_value(&["devices", devtype, name, "udn"], Value::String(udn))
|
||||
let udn_str = udn.trim();
|
||||
let sanitized = udn_str.strip_prefix("uuid:").unwrap_or(udn_str).to_string();
|
||||
self.set_value(&["devices", devtype, name, "udn"], Value::String(sanitized))
|
||||
}
|
||||
|
||||
impl_string_config!(
|
||||
|
||||
@@ -79,14 +79,14 @@ impl UpnpInstance for DeviceInstance {
|
||||
// Obtenir ou créer un UDN persistant via la configuration
|
||||
let device_name = model.get_name();
|
||||
let device_type = model.device_category();
|
||||
let udn = if let Ok(config_udn) =
|
||||
pmoconfig::get_config().get_device_udn(&device_type, device_name)
|
||||
{
|
||||
config_udn
|
||||
} else {
|
||||
// Fallback : générer un UDN
|
||||
tracing::warn!("Failed to get/save UDN from config, using generated UUID");
|
||||
format!("uuid:{}_{}", model.udn_prefix(), uuid::Uuid::new_v4())
|
||||
let udn = match pmoconfig::get_config().get_device_udn(&device_type, device_name) {
|
||||
Ok(config_udn) => Self::normalize_udn(config_udn),
|
||||
Err(err) => {
|
||||
tracing::warn!(
|
||||
"Failed to get/save UDN from config ({err:?}), using generated UUID"
|
||||
);
|
||||
Self::normalize_udn(uuid::Uuid::new_v4().to_string())
|
||||
}
|
||||
};
|
||||
|
||||
// Obtenir l'IP locale et le port depuis la configuration
|
||||
@@ -149,7 +149,8 @@ impl UpnpObject for DeviceInstance {
|
||||
|
||||
// UDN
|
||||
let mut udn = Element::new("UDN");
|
||||
udn.children.push(XMLNode::Text(self.udn.clone()));
|
||||
udn.children
|
||||
.push(XMLNode::Text(self.udn_with_prefix()));
|
||||
elem.children.push(XMLNode::Element(udn));
|
||||
|
||||
// serviceList
|
||||
@@ -200,6 +201,15 @@ impl DeviceInstance {
|
||||
&self.udn
|
||||
}
|
||||
|
||||
/// Retourne l'UDN avec le préfixe `uuid:` requis par la spécification.
|
||||
pub fn udn_with_prefix(&self) -> String {
|
||||
if self.udn.starts_with("uuid:") {
|
||||
self.udn.clone()
|
||||
} else {
|
||||
format!("uuid:{}", self.udn)
|
||||
}
|
||||
}
|
||||
|
||||
/// Retourne l'URL de base du serveur (protocole + host + port).
|
||||
pub fn base_url(&self) -> &str {
|
||||
&self.server_base_url
|
||||
@@ -403,4 +413,11 @@ impl DeviceInstance {
|
||||
|
||||
ssdp_device
|
||||
}
|
||||
|
||||
fn normalize_udn<S: Into<String>>(raw: S) -> String {
|
||||
let value: String = raw.into();
|
||||
let trimmed = value.trim();
|
||||
let sanitized = trimmed.strip_prefix("uuid:").unwrap_or(trimmed);
|
||||
sanitized.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ impl ServiceInstance {
|
||||
pub fn usn(&self) -> String {
|
||||
let device = self.device.read().unwrap();
|
||||
match device.as_ref() {
|
||||
Some(device) => format!("uuid:{}::urn:{}", device.udn(), self.service_type()),
|
||||
Some(device) => format!("{}::urn:{}", device.udn_with_prefix(), self.service_type()),
|
||||
None => format!("uuid::urn:{}", self.service_type()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user