From 24d563ff18a7be28ba3cecdd317dfba9c6fa9d7f Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 22 Apr 2017 19:30:17 +0100 Subject: [PATCH] jingle: Carry the minidom Element for description, transport and security. --- src/jingle.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/jingle.rs b/src/jingle.rs index 80ad7b06..fbda090c 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -121,9 +121,9 @@ pub struct Content { pub disposition: String, pub name: String, pub senders: Senders, - pub description: String, - pub transport: String, - pub security: Option, + pub description: (String, Element), + pub transport: (String, Element), + pub security: Option<(String, Element)>, } #[derive(Debug, Clone, PartialEq)] @@ -246,17 +246,38 @@ pub fn parse_jingle(root: &Element) -> Result { if description.is_some() { return Err(Error::ParseError("Content must not have more than one description.")); } - description = Some(stuff.ns().ok_or(Error::ParseError("Description without a namespace."))?); + let namespace = stuff.ns() + .and_then(|ns| ns.parse().ok()) + // TODO: is this even reachable? + .ok_or(Error::ParseError("Invalid namespace on description element."))?; + description = Some(( + namespace, + stuff.clone(), + )); } else if stuff.name() == "transport" { if transport.is_some() { return Err(Error::ParseError("Content must not have more than one transport.")); } - transport = Some(stuff.ns().ok_or(Error::ParseError("Transport without a namespace."))?); + let namespace = stuff.ns() + .and_then(|ns| ns.parse().ok()) + // TODO: is this even reachable? + .ok_or(Error::ParseError("Invalid namespace on transport element."))?; + transport = Some(( + namespace, + stuff.clone(), + )); } else if stuff.name() == "security" { if security.is_some() { return Err(Error::ParseError("Content must not have more than one security.")); } - security = stuff.ns().and_then(|ns| ns.parse().ok()); + let namespace = stuff.ns() + .and_then(|ns| ns.parse().ok()) + // TODO: is this even reachable? + .ok_or(Error::ParseError("Invalid namespace on security element."))?; + security = Some(( + namespace, + stuff.clone(), + )); } } if description.is_none() { @@ -274,7 +295,7 @@ pub fn parse_jingle(root: &Element) -> Result { senders: senders, description: description, transport: transport, - security: security.to_owned(), + security: security, }); } else if child.is("reason", ns::JINGLE) { if reason_element.is_some() {