From c20d37a842f4824a5bb5a41760a0011b289f945e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 28 Apr 2017 23:45:02 +0100 Subject: [PATCH] jingle: Add serialisation for . --- src/jingle.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/jingle.rs b/src/jingle.rs index 9e2549cf..800cb7ae 100644 --- a/src/jingle.rs +++ b/src/jingle.rs @@ -2,7 +2,8 @@ extern crate minidom; use std::str::FromStr; -use minidom::Element; +use minidom::{Element, IntoElements}; +use minidom::convert::ElementEmitter; use error::Error; 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)] pub struct ReasonElement { pub reason: Reason, @@ -376,6 +402,13 @@ pub fn serialise(jingle: &Jingle) -> Element { let content_elem = serialise_content(&content); 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 }