diff --git a/src/client/bind.rs b/src/client/bind.rs index 1541afd..d258f7b 100644 --- a/src/client/bind.rs +++ b/src/client/bind.rs @@ -5,6 +5,7 @@ use futures::{Future, Poll, Async, sink, Sink, Stream}; use tokio_io::{AsyncRead, AsyncWrite}; use jid::Jid; use minidom::Element; +use xmpp_parsers::bind::Bind; use xmpp_codec::Packet; use xmpp_stream::XMPPStream; @@ -30,7 +31,10 @@ impl ClientBind { // return the (probably // usable) stream immediately ClientBind::Unsupported(stream), 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)); ClientBind::WaitSend(send) }, @@ -38,21 +42,6 @@ impl ClientBind { } } -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 Future for ClientBind { type Item = XMPPStream; type Error = String;