From 4927ecaa0d4776d9c99059dad863c5e801fe3ddc Mon Sep 17 00:00:00 2001 From: lumi Date: Fri, 24 Feb 2017 23:53:54 +0100 Subject: [PATCH] support binding to a resource --- examples/client.rs | 1 + src/client.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index 4debe80a..6333c0bc 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -18,6 +18,7 @@ fn main() { client.connect(&mut Plain::new(name, pass)).unwrap(); // Replace with this line if you want SCRAM-SHA-1 authentication: // client.connect(&mut Scram::::new(name, pass).unwrap()).unwrap(); + client.bind().unwrap(); client.plugin::().set_presence(Show::Available, None).unwrap(); loop { let event = client.next_event().unwrap(); diff --git a/src/client.rs b/src/client.rs index 674c6338..9709e385 100644 --- a/src/client.rs +++ b/src/client.rs @@ -169,7 +169,8 @@ impl Client { mechanism.success(&data).map_err(|x| Error::SaslError(Some(x)))?; self.transport.reset_stream(); C2S::init(&mut self.transport, &self.jid.domain, "after_sasl")?; - return self.bind(); + self.wait_for_features()?; + return Ok(()); } else if n.is("failure", ns::SASL) { let msg = n.text(); @@ -179,15 +180,21 @@ impl Client { } } - fn bind(&mut self) -> Result<(), Error> { - self.wait_for_features()?; + pub fn bind(&mut self) -> Result<(), Error> { let mut elem = Element::builder("iq") .attr("id", "bind") .attr("type", "set") .build(); - let bind = Element::builder("bind") - .ns(ns::BIND) - .build(); + let mut bind = Element::builder("bind") + .ns(ns::BIND) + .build(); + if let Some(ref resource) = self.jid.resource { + let res = Element::builder("resource") + .ns(ns::BIND) + .text(resource.to_owned()) + .build(); + bind.append_child(res); + } elem.append_child(bind); self.transport.write_element(&elem)?; loop {