push-pqqsxyupswry #21

Merged
eric merged 76 commits from push-pqqsxyupswry into main 2025-12-06 12:49:47 +01:00
3 changed files with 25 additions and 0 deletions
Showing only changes of commit f2dcd55549 - Show all commits

1
Cargo.lock generated
View File

@@ -3433,6 +3433,7 @@ dependencies = [
"get_if_addrs",
"netstat2",
"os_info",
"quick-xml 0.38.4",
"sysinfo",
"users",
]

View File

@@ -9,3 +9,5 @@ os_info = "3.8"
netstat2 = "0.11"
sysinfo = "0.30"
users = "0.11"
quick-xml = "0.38.3"
xmltree = "0.10"

View File

@@ -20,6 +20,7 @@ pub mod ip_utils;
pub use ip_utils::guess_local_ip;
pub mod process;
pub use process::{ProcessPortInfo, TransportProtocol, find_process_using_port};
use xmltree::{Element, EmitterConfig};
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
///
@@ -52,3 +53,24 @@ pub fn get_os_string() -> String {
format!("{}/Unknown", os_type)
}
}
/// Trait générique pour obtenir un élément XML (xmltree::Element).
///
/// Aligné sur la signature utilisée dans pmoupnp (UpnpObject::to_xml_element),
/// afin de pouvoir factoriser la sérialisation XML entre crates.
pub trait ToXmlElement {
/// Convertit l'objet en élément XML.
fn to_xml_element(&self) -> Element;
/// Sérialise en chaîne XML formatée.
fn to_xml(&self) -> String {
let elem = self.to_xml_element();
let config = EmitterConfig::new()
.perform_indent(true)
.indent_string(" ");
let mut buf = Vec::new();
elem.write_with_config(&mut buf, config)
.expect("Failed to write XML");
String::from_utf8(buf).expect("Invalid UTF-8")
}
}