add a Component2S connection type

This commit is contained in:
Emmanuel Gil Peyrot 2017-04-01 17:14:46 +01:00
parent e2e6ae985a
commit 70f70b1c73
2 changed files with 24 additions and 0 deletions

View file

@ -36,3 +36,26 @@ impl Connection for C2S {
Ok(()) Ok(())
} }
} }
pub struct Component2S;
impl Connection for Component2S {
type InitError = Error;
type CloseError = Error;
fn namespace() -> &'static str { ns::COMPONENT_ACCEPT }
fn init<T: Transport>(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<T: Transport>(transport: &mut T) -> Result<(), Error> {
transport.write_event(WriterEvent::end_element())?;
Ok(())
}
}

View file

@ -1,6 +1,7 @@
//! Provides constants for namespaces. //! Provides constants for namespaces.
pub const CLIENT: &'static str = "jabber:client"; 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 STREAM: &'static str = "http://etherx.jabber.org/streams";
pub const TLS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls"; pub const TLS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls";
pub const SASL: &'static str = "urn:ietf:params:xml:ns:xmpp-sasl"; pub const SASL: &'static str = "urn:ietf:params:xml:ns:xmpp-sasl";