mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
support binding to a resource
This commit is contained in:
parent
ff7387a92a
commit
4927ecaa0d
2 changed files with 14 additions and 6 deletions
|
@ -18,6 +18,7 @@ fn main() {
|
||||||
client.connect(&mut Plain::new(name, pass)).unwrap();
|
client.connect(&mut Plain::new(name, pass)).unwrap();
|
||||||
// Replace with this line if you want SCRAM-SHA-1 authentication:
|
// Replace with this line if you want SCRAM-SHA-1 authentication:
|
||||||
// client.connect(&mut Scram::<Sha1>::new(name, pass).unwrap()).unwrap();
|
// client.connect(&mut Scram::<Sha1>::new(name, pass).unwrap()).unwrap();
|
||||||
|
client.bind().unwrap();
|
||||||
client.plugin::<PresencePlugin>().set_presence(Show::Available, None).unwrap();
|
client.plugin::<PresencePlugin>().set_presence(Show::Available, None).unwrap();
|
||||||
loop {
|
loop {
|
||||||
let event = client.next_event().unwrap();
|
let event = client.next_event().unwrap();
|
||||||
|
|
|
@ -169,7 +169,8 @@ impl Client {
|
||||||
mechanism.success(&data).map_err(|x| Error::SaslError(Some(x)))?;
|
mechanism.success(&data).map_err(|x| Error::SaslError(Some(x)))?;
|
||||||
self.transport.reset_stream();
|
self.transport.reset_stream();
|
||||||
C2S::init(&mut self.transport, &self.jid.domain, "after_sasl")?;
|
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) {
|
else if n.is("failure", ns::SASL) {
|
||||||
let msg = n.text();
|
let msg = n.text();
|
||||||
|
@ -179,15 +180,21 @@ impl Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bind(&mut self) -> Result<(), Error> {
|
pub fn bind(&mut self) -> Result<(), Error> {
|
||||||
self.wait_for_features()?;
|
|
||||||
let mut elem = Element::builder("iq")
|
let mut elem = Element::builder("iq")
|
||||||
.attr("id", "bind")
|
.attr("id", "bind")
|
||||||
.attr("type", "set")
|
.attr("type", "set")
|
||||||
.build();
|
.build();
|
||||||
let bind = Element::builder("bind")
|
let mut bind = Element::builder("bind")
|
||||||
.ns(ns::BIND)
|
.ns(ns::BIND)
|
||||||
.build();
|
.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);
|
elem.append_child(bind);
|
||||||
self.transport.write_element(&elem)?;
|
self.transport.write_element(&elem)?;
|
||||||
loop {
|
loop {
|
||||||
|
|
Loading…
Reference in a new issue