Je ne sais pas trop

This commit is contained in:
2025-10-26 23:49:20 +01:00
parent aae941b7cb
commit dea7062038
15 changed files with 66 additions and 24 deletions

View File

@@ -979,8 +979,7 @@ impl ServiceInstance {
// Essayer de downcaster vers des types primitifs courants
if let Some(v) = value.as_any().downcast_ref::<String>() {
// Échapper les caractères XML spéciaux
return escape(v).to_string();
return v.clone();
} else if let Some(v) = value.as_any().downcast_ref::<u8>() {
return v.to_string();
} else if let Some(v) = value.as_any().downcast_ref::<u16>() {
@@ -1000,7 +999,7 @@ impl ServiceInstance {
} else if let Some(v) = value.as_any().downcast_ref::<bool>() {
return if *v { "1" } else { "0" }.to_string();
} else if let Some(v) = value.as_any().downcast_ref::<char>() {
return escape(&v.to_string()).to_string();
return v.to_string();
}
// Pour les structures complexes, essayer de sérialiser avec bevy_reflect
@@ -1345,7 +1344,7 @@ async fn control_handler(State(instance): State<Arc<ServiceInstance>>, body: Str
match action_instance_for_run.run(soap_values).await {
Ok(output_data) => {
// Convertir ActionData (Reflect) → HashMap<String, String> pour SOAP
let mut soap_values = HashMap::new();
let mut soap_values: Vec<(String, String)> = Vec::new();
for arg_inst in action_instance.arguments_set().all() {
let arg_model = arg_inst.as_ref().get_model();
@@ -1353,7 +1352,7 @@ async fn control_handler(State(instance): State<Arc<ServiceInstance>>, body: Str
if let Some(reflect_value) = output_data.get(arg_inst.get_name()) {
let soap_string =
ServiceInstance::reflect_to_string(reflect_value.as_ref());
soap_values.insert(arg_inst.get_name().to_string(), soap_string);
soap_values.push((arg_inst.get_name().to_string(), soap_string));
}
}
}

View File

@@ -1,6 +1,5 @@
//! Construction de réponses SOAP
use std::collections::HashMap;
use xmltree::{Element, XMLNode};
/// Construit une réponse SOAP UPnP
@@ -17,13 +16,12 @@ use xmltree::{Element, XMLNode};
pub fn build_soap_response(
service_urn: &str,
action: &str,
values: HashMap<String, String>,
values: Vec<(String, String)>,
) -> Result<String, xmltree::Error> {
// Construire l'élément de réponse
// Format: <u:ActionResponse xmlns:u="service-urn">
let response_name = format!("{}Response", action);
let response_name = format!("u:{}Response", action);
let mut response_elem = Element::new(&response_name);
response_elem.namespace = Some(service_urn.to_string());
response_elem
.attributes
.insert("xmlns:u".to_string(), service_urn.to_string());
@@ -54,6 +52,7 @@ pub fn build_soap_response(
// Sérialiser en XML
let mut buf = Vec::new();
let config = xmltree::EmitterConfig::new()
.write_document_declaration(true)
.perform_indent(true)
.indent_string(" ");
envelope.write_with_config(&mut buf, config)?;
@@ -67,9 +66,9 @@ mod tests {
#[test]
fn test_build_response() {
let mut values = HashMap::new();
values.insert("Track".to_string(), "5".to_string());
values.insert("TrackDuration".to_string(), "00:03:45".to_string());
let mut values = Vec::new();
values.push(("Track".to_string(), "5".to_string()));
values.push(("TrackDuration".to_string(), "00:03:45".to_string()));
let xml = build_soap_response(
"urn:schemas-upnp-org:service:AVTransport:1",
@@ -86,7 +85,7 @@ mod tests {
#[test]
fn test_build_empty_response() {
let values = HashMap::new();
let values = Vec::new();
let xml = build_soap_response("urn:schemas-upnp-org:service:AVTransport:1", "Stop", values)
.unwrap();

View File

@@ -129,6 +129,7 @@ pub fn build_soap_fault(
// Sérialiser
let mut buf = Vec::new();
let config = xmltree::EmitterConfig::new()
.write_document_declaration(true)
.perform_indent(true)
.indent_string(" ");
envelope.write_with_config(&mut buf, config)?;

View File

@@ -39,8 +39,8 @@
//! assert_eq!(action.args.get("InstanceID"), Some(&"0".to_string()));
//!
//! // Construire une réponse
//! let mut values = std::collections::HashMap::new();
//! values.insert("CurrentTrack".to_string(), "5".to_string());
//! let mut values = Vec::new();
//! values.push(("CurrentTrack".to_string(), "5".to_string()));
//! let response = build_soap_response(
//! "urn:schemas-upnp-org:service:AVTransport:1",
//! "GetPositionInfo",