support binding to a resource

This commit is contained in:
lumi 2017-02-24 23:53:54 +01:00
parent ff7387a92a
commit 4927ecaa0d
2 changed files with 14 additions and 6 deletions

View file

@ -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::<Sha1>::new(name, pass).unwrap()).unwrap();
client.bind().unwrap();
client.plugin::<PresencePlugin>().set_presence(Show::Available, None).unwrap();
loop {
let event = client.next_event().unwrap();

View file

@ -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")
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 {