From 4b322cc62b3655cac4fa0d44b8b8c5968c019a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 28 Dec 2017 04:31:40 +0100 Subject: [PATCH] connection: Adapt C2S and Component2S impl for quickxml; Thanks eijebong --- src/connection.rs | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index 4d639b4..fcb33c0 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -2,7 +2,7 @@ use transport::Transport; use error::Error; use ns; -use xml::writer::XmlEvent as WriterEvent; +use quick_xml::events::{Event as WriterEvent, BytesStart, BytesEnd}; pub trait Connection { type InitError; @@ -23,17 +23,19 @@ impl Connection for C2S { fn namespace() -> &'static str { ns::CLIENT } fn init(transport: &mut T, domain: &str, id: &str) -> Result<(), Error> { - transport.write_event(WriterEvent::start_element("stream:stream") - .attr("to", domain) - .attr("id", id) - .default_ns(ns::CLIENT) - .ns("stream", ns::STREAM))?; - Ok(()) + let name = "stream:stream"; + let mut elem = BytesStart::borrowed(name.as_bytes(), name.len()); + elem.push_attribute(("to", domain)); + elem.push_attribute(("id", id)); + elem.push_attribute(("xmlns", ns::CLIENT)); + elem.push_attribute(("xmlns:stream", ns::STREAM)); + transport.write_event(WriterEvent::Start(elem)) } fn close(transport: &mut T) -> Result<(), Error> { - transport.write_event(WriterEvent::end_element())?; - Ok(()) + let name = "stream:stream"; + let elem = BytesEnd::borrowed(name.as_bytes()); + transport.write_event(WriterEvent::End(elem)) } } @@ -46,16 +48,18 @@ impl Connection for Component2S { fn namespace() -> &'static str { ns::COMPONENT_ACCEPT } fn init(transport: &mut T, domain: &str, id: &str) -> Result<(), Error> { - transport.write_event(WriterEvent::start_element("stream:stream") - .attr("to", domain) - .attr("id", id) - .default_ns(ns::COMPONENT_ACCEPT) - .ns("stream", ns::STREAM))?; - Ok(()) + let name = "stream:stream"; + let mut elem = BytesStart::borrowed(name.as_bytes(), name.len()); + elem.push_attribute(("to", domain)); + elem.push_attribute(("id", id)); + elem.push_attribute(("xmlns", ns::COMPONENT_ACCEPT)); + elem.push_attribute(("xmlns:stream", ns::STREAM)); + transport.write_event(WriterEvent::Start(elem)) } fn close(transport: &mut T) -> Result<(), Error> { - transport.write_event(WriterEvent::end_element())?; - Ok(()) + let name = "stream:stream"; + let elem = BytesEnd::borrowed(name.as_bytes()); + transport.write_event(WriterEvent::End(elem)) } }