xmpp-parsers/jingle: Use XEP-0338.

This commit is contained in:
Emmanuel Gil Peyrot 2020-11-27 20:58:20 +01:00
parent 27ddad683a
commit c10d0094e9

View file

@ -5,6 +5,7 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::iq::IqSetPayload; use crate::iq::IqSetPayload;
use crate::jingle_grouping::Group;
use crate::jingle_ibb::Transport as IbbTransport; use crate::jingle_ibb::Transport as IbbTransport;
use crate::jingle_ice_udp::Transport as IceUdpTransport; use crate::jingle_ice_udp::Transport as IceUdpTransport;
use crate::jingle_rtp::Description as RtpDescription; use crate::jingle_rtp::Description as RtpDescription;
@ -560,6 +561,9 @@ pub struct Jingle {
/// An optional reason. /// An optional reason.
pub reason: Option<ReasonElement>, pub reason: Option<ReasonElement>,
/// An optional grouping.
pub group: Option<Group>,
/// Payloads to be included. /// Payloads to be included.
pub other: Vec<Element>, pub other: Vec<Element>,
} }
@ -576,6 +580,7 @@ impl Jingle {
responder: None, responder: None,
contents: Vec::new(), contents: Vec::new(),
reason: None, reason: None,
group: None,
other: Vec::new(), other: Vec::new(),
} }
} }
@ -603,6 +608,12 @@ impl Jingle {
self.reason = Some(reason); self.reason = Some(reason);
self self
} }
/// Set the grouping in this Jingle container.
pub fn set_group(mut self, group: Group) -> Jingle {
self.group = Some(group);
self
}
} }
impl TryFrom<Element> for Jingle { impl TryFrom<Element> for Jingle {
@ -619,6 +630,7 @@ impl TryFrom<Element> for Jingle {
sid: get_attr!(root, "sid", Required), sid: get_attr!(root, "sid", Required),
contents: vec![], contents: vec![],
reason: None, reason: None,
group: None,
other: vec![], other: vec![],
}; };
@ -634,6 +646,14 @@ impl TryFrom<Element> for Jingle {
} }
let reason = ReasonElement::try_from(child)?; let reason = ReasonElement::try_from(child)?;
jingle.reason = Some(reason); jingle.reason = Some(reason);
} else if child.is("group", ns::JINGLE_GROUPING) {
if jingle.group.is_some() {
return Err(Error::ParseError(
"Jingle must not have more than one grouping.",
));
}
let group = Group::try_from(child)?;
jingle.group = Some(group);
} else { } else {
jingle.other.push(child); jingle.other.push(child);
} }
@ -652,6 +672,7 @@ impl From<Jingle> for Element {
.attr("sid", jingle.sid) .attr("sid", jingle.sid)
.append_all(jingle.contents) .append_all(jingle.contents)
.append_all(jingle.reason.map(Element::from)) .append_all(jingle.reason.map(Element::from))
.append_all(jingle.group.map(Element::from))
.build() .build()
} }
} }
@ -672,7 +693,7 @@ mod tests {
assert_size!(Reason, 1); assert_size!(Reason, 1);
assert_size!(ReasonElement, 16); assert_size!(ReasonElement, 16);
assert_size!(SessionId, 12); assert_size!(SessionId, 12);
assert_size!(Jingle, 136); assert_size!(Jingle, 152);
} }
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
@ -687,7 +708,7 @@ mod tests {
assert_size!(Reason, 1); assert_size!(Reason, 1);
assert_size!(ReasonElement, 32); assert_size!(ReasonElement, 32);
assert_size!(SessionId, 24); assert_size!(SessionId, 24);
assert_size!(Jingle, 272); assert_size!(Jingle, 304);
} }
#[test] #[test]
@ -876,6 +897,7 @@ mod tests {
security: None, security: None,
}], }],
reason: None, reason: None,
group: None,
other: vec![], other: vec![],
}; };
let serialized: Element = jingle.into(); let serialized: Element = jingle.into();