diff --git a/src/connection.rs b/src/connection.rs index 76bef64e..4d639b4e 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 4dce8aaa..6f11daa1 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";