jingle: Add serialisation for <reason/>.

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-28 23:45:02 +01:00
parent de93c32cb5
commit c20d37a842

View file

@ -2,7 +2,8 @@ extern crate minidom;
use std::str::FromStr; use std::str::FromStr;
use minidom::Element; use minidom::{Element, IntoElements};
use minidom::convert::ElementEmitter;
use error::Error; use error::Error;
use ns; use ns;
@ -199,6 +200,31 @@ impl FromStr for Reason {
} }
} }
impl IntoElements for Reason {
fn into_elements(self, emitter: &mut ElementEmitter) {
let elem = Element::builder(match self {
Reason::AlternativeSession => "alternative-session",
Reason::Busy => "busy",
Reason::Cancel => "cancel",
Reason::ConnectivityError => "connectivity-error",
Reason::Decline => "decline",
Reason::Expired => "expired",
Reason::FailedApplication => "failed-application",
Reason::FailedTransport => "failed-transport",
Reason::GeneralError => "general-error",
Reason::Gone => "gone",
Reason::IncompatibleParameters => "incompatible-parameters",
Reason::MediaError => "media-error",
Reason::SecurityError => "security-error",
Reason::Success => "success",
Reason::Timeout => "timeout",
Reason::UnsupportedApplications => "unsupported-applications",
Reason::UnsupportedTransports => "unsupported-transports",
}).build();
emitter.append_child(elem);
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ReasonElement { pub struct ReasonElement {
pub reason: Reason, pub reason: Reason,
@ -376,6 +402,13 @@ pub fn serialise(jingle: &Jingle) -> Element {
let content_elem = serialise_content(&content); let content_elem = serialise_content(&content);
root.append_child(content_elem); root.append_child(content_elem);
} }
if let Some(ref reason) = jingle.reason {
let reason_elem = Element::builder("reason")
.append(reason.reason.clone())
.append(reason.text.clone())
.build();
root.append_child(reason_elem);
}
root root
} }