From 70f70b1c73054698b181a1751ab839ae92804c83 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 1 Apr 2017 17:14:46 +0100 Subject: [PATCH] add a Component2S connection type --- src/connection.rs | 23 +++++++++++++++++++++++ src/ns.rs | 1 + 2 files changed, 24 insertions(+) diff --git a/src/connection.rs b/src/connection.rs index 76bef64..4d639b4 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -36,3 +36,26 @@ impl Connection for C2S { Ok(()) } } + +pub struct Component2S; + +impl Connection for Component2S { + type InitError = Error; + type CloseError = Error; + + 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(()) + } + + fn close(transport: &mut T) -> Result<(), Error> { + transport.write_event(WriterEvent::end_element())?; + Ok(()) + } +} diff --git a/src/ns.rs b/src/ns.rs index 4dce8aa..6f11daa 100644 --- a/src/ns.rs +++ b/src/ns.rs @@ -1,6 +1,7 @@ //! Provides constants for namespaces. pub const CLIENT: &'static str = "jabber:client"; +pub const COMPONENT_ACCEPT: &'static str = "jabber:component:accept"; pub const STREAM: &'static str = "http://etherx.jabber.org/streams"; pub const TLS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls"; pub const SASL: &'static str = "urn:ietf:params:xml:ns:xmpp-sasl";