ClientBind: replace with xmpp_parsers::bind::Bind

This commit is contained in:
Astro 2018-08-02 00:00:00 +02:00
parent 89a1d3e1cf
commit 06b97ea228

View file

@ -5,6 +5,7 @@ use futures::{Future, Poll, Async, sink, Sink, Stream};
use tokio_io::{AsyncRead, AsyncWrite}; use tokio_io::{AsyncRead, AsyncWrite};
use jid::Jid; use jid::Jid;
use minidom::Element; use minidom::Element;
use xmpp_parsers::bind::Bind;
use xmpp_codec::Packet; use xmpp_codec::Packet;
use xmpp_stream::XMPPStream; use xmpp_stream::XMPPStream;
@ -30,7 +31,10 @@ impl<S: AsyncWrite> ClientBind<S> {
// return the (probably // usable) stream immediately // return the (probably // usable) stream immediately
ClientBind::Unsupported(stream), ClientBind::Unsupported(stream),
Some(_) => { Some(_) => {
let iq = make_bind_request(stream.jid.resource.as_ref()); let resource = stream.jid.resource.clone();
let iq = Element::from(
Bind::new(resource)
);
let send = stream.send(Packet::Stanza(iq)); let send = stream.send(Packet::Stanza(iq));
ClientBind::WaitSend(send) ClientBind::WaitSend(send)
}, },
@ -38,21 +42,6 @@ impl<S: AsyncWrite> ClientBind<S> {
} }
} }
fn make_bind_request(resource: Option<&String>) -> Element {
let iq = Element::builder("iq")
.attr("type", "set")
.attr("id", BIND_REQ_ID);
let mut bind_el = Element::builder("bind")
.ns(NS_XMPP_BIND);
if let Some(resource) = resource {
let resource_el = Element::builder("resource")
.append(resource);
bind_el = bind_el.append(resource_el.build());
}
iq.append(bind_el.build())
.build()
}
impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> { impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
type Item = XMPPStream<S>; type Item = XMPPStream<S>;
type Error = String; type Error = String;