switch from rustxml to minidom, doesn't work
This commit is contained in:
parent
fa08591162
commit
d4bd64370c
11 changed files with 241 additions and 205 deletions
|
|
@ -2,7 +2,7 @@ use std::mem::replace;
|
|||
use futures::*;
|
||||
use futures::sink;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use xml;
|
||||
use minidom::Element;
|
||||
use sasl::common::Credentials;
|
||||
use sasl::common::scram::*;
|
||||
use sasl::client::Mechanism;
|
||||
|
|
@ -37,12 +37,13 @@ impl<S: AsyncWrite> ClientAuth<S> {
|
|||
];
|
||||
|
||||
let mech_names: Vec<String> =
|
||||
match stream.stream_features.get_child("mechanisms", Some(NS_XMPP_SASL)) {
|
||||
match stream.stream_features.get_child("mechanisms", NS_XMPP_SASL) {
|
||||
None =>
|
||||
return Err("No auth mechanisms".to_owned()),
|
||||
Some(mechs) =>
|
||||
mechs.get_children("mechanism", Some(NS_XMPP_SASL))
|
||||
.map(|mech_el| mech_el.content_str())
|
||||
mechs.children()
|
||||
.filter(|child| child.is("mechanism", NS_XMPP_SASL))
|
||||
.map(|mech_el| mech_el.text())
|
||||
.collect(),
|
||||
};
|
||||
println!("SASL mechanisms offered: {:?}", mech_names);
|
||||
|
|
@ -58,7 +59,7 @@ impl<S: AsyncWrite> ClientAuth<S> {
|
|||
};
|
||||
this.send(
|
||||
stream,
|
||||
"auth", &[("mechanism".to_owned(), name)],
|
||||
"auth", &[("mechanism", &name)],
|
||||
&initial
|
||||
);
|
||||
return Ok(this);
|
||||
|
|
@ -68,15 +69,13 @@ impl<S: AsyncWrite> ClientAuth<S> {
|
|||
Err("No supported SASL mechanism available".to_owned())
|
||||
}
|
||||
|
||||
fn send(&mut self, stream: XMPPStream<S>, nonza_name: &str, attrs: &[(String, String)], content: &[u8]) {
|
||||
let mut nonza = xml::Element::new(
|
||||
nonza_name.to_owned(),
|
||||
Some(NS_XMPP_SASL.to_owned()),
|
||||
attrs.iter()
|
||||
.map(|&(ref name, ref value)| (name.clone(), None, value.clone()))
|
||||
.collect()
|
||||
);
|
||||
nonza.text(content.to_base64(base64::URL_SAFE));
|
||||
fn send(&mut self, stream: XMPPStream<S>, nonza_name: &str, attrs: &[(&str, &str)], content: &[u8]) {
|
||||
let nonza = Element::builder(nonza_name)
|
||||
.ns(NS_XMPP_SASL);
|
||||
let nonza = attrs.iter()
|
||||
.fold(nonza, |nonza, &(name, value)| nonza.attr(name, value))
|
||||
.append(content.to_base64(base64::URL_SAFE))
|
||||
.build();
|
||||
|
||||
let send = stream.send(Packet::Stanza(nonza));
|
||||
|
||||
|
|
@ -108,11 +107,11 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
|
|||
ClientAuthState::WaitRecv(mut stream) =>
|
||||
match stream.poll() {
|
||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
||||
if stanza.name == "challenge"
|
||||
&& stanza.ns == Some(NS_XMPP_SASL.to_owned()) =>
|
||||
if stanza.name() == "challenge"
|
||||
&& stanza.ns() == Some(NS_XMPP_SASL) =>
|
||||
{
|
||||
let content = try!(
|
||||
stanza.content_str()
|
||||
stanza.text()
|
||||
.from_base64()
|
||||
.map_err(|e| format!("{}", e))
|
||||
);
|
||||
|
|
@ -121,29 +120,24 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
|
|||
self.poll()
|
||||
},
|
||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
||||
if stanza.name == "success"
|
||||
&& stanza.ns == Some(NS_XMPP_SASL.to_owned()) =>
|
||||
if stanza.name() == "success"
|
||||
&& stanza.ns() == Some(NS_XMPP_SASL) =>
|
||||
{
|
||||
let start = stream.restart();
|
||||
self.state = ClientAuthState::Start(start);
|
||||
self.poll()
|
||||
},
|
||||
Ok(Async::Ready(Some(Packet::Stanza(ref stanza))))
|
||||
if stanza.name == "failure"
|
||||
&& stanza.ns == Some(NS_XMPP_SASL.to_owned()) =>
|
||||
if stanza.name() == "failure"
|
||||
&& stanza.ns() == Some(NS_XMPP_SASL) =>
|
||||
{
|
||||
let mut e = None;
|
||||
for child in &stanza.children {
|
||||
match child {
|
||||
&xml::Xml::ElementNode(ref child) => {
|
||||
e = Some(child.name.clone());
|
||||
break
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
for child in stanza.children() {
|
||||
e = Some(child.name().clone());
|
||||
break
|
||||
}
|
||||
let e = e.unwrap_or_else(|| "Authentication failure".to_owned());
|
||||
Err(e)
|
||||
let e = e.unwrap_or_else(|| "Authentication failure");
|
||||
Err(e.to_owned())
|
||||
},
|
||||
Ok(Async::Ready(event)) => {
|
||||
println!("ClientAuth ignore {:?}", event);
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ use std::str::FromStr;
|
|||
use futures::*;
|
||||
use futures::sink;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use xml;
|
||||
use jid::Jid;
|
||||
use minidom::Element;
|
||||
|
||||
use xmpp_codec::*;
|
||||
use xmpp_stream::*;
|
||||
|
|
@ -25,7 +25,7 @@ impl<S: AsyncWrite> ClientBind<S> {
|
|||
/// the stream for anything else until the resource binding
|
||||
/// req/resp are done.
|
||||
pub fn new(stream: XMPPStream<S>) -> Self {
|
||||
match stream.stream_features.get_child("bind", Some(NS_XMPP_BIND)) {
|
||||
match stream.stream_features.get_child("bind", NS_XMPP_BIND) {
|
||||
None =>
|
||||
// No resource binding available,
|
||||
// return the (probably // usable) stream immediately
|
||||
|
|
@ -39,31 +39,22 @@ impl<S: AsyncWrite> ClientBind<S> {
|
|||
}
|
||||
}
|
||||
|
||||
fn make_bind_request(resource: Option<&String>) -> xml::Element {
|
||||
let mut iq = xml::Element::new(
|
||||
"iq".to_owned(),
|
||||
None,
|
||||
vec![("type".to_owned(), None, "set".to_owned()),
|
||||
("id".to_owned(), None, BIND_REQ_ID.to_owned())]
|
||||
);
|
||||
{
|
||||
let bind_el = iq.tag(
|
||||
xml::Element::new(
|
||||
"bind".to_owned(),
|
||||
Some(NS_XMPP_BIND.to_owned()),
|
||||
vec![]
|
||||
));
|
||||
resource.map(|resource| {
|
||||
let resource_el = bind_el.tag(
|
||||
xml::Element::new(
|
||||
"resource".to_owned(),
|
||||
Some(NS_XMPP_BIND.to_owned()),
|
||||
vec![]
|
||||
));
|
||||
resource_el.text(resource.clone());
|
||||
});
|
||||
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);
|
||||
match resource {
|
||||
Some(resource) => {
|
||||
let resource_el = Element::builder("resource")
|
||||
.append(resource);
|
||||
bind_el = bind_el.append(resource_el.build());
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
iq
|
||||
iq.append(bind_el.build())
|
||||
.build()
|
||||
}
|
||||
|
||||
impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
|
||||
|
|
@ -93,9 +84,9 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
|
|||
ClientBind::WaitRecv(mut stream) => {
|
||||
match stream.poll() {
|
||||
Ok(Async::Ready(Some(Packet::Stanza(ref iq))))
|
||||
if iq.name == "iq"
|
||||
&& iq.get_attribute("id", None) == Some(BIND_REQ_ID) => {
|
||||
match iq.get_attribute("type", None) {
|
||||
if iq.name() == "iq"
|
||||
&& iq.attr("id") == Some(BIND_REQ_ID) => {
|
||||
match iq.attr("type") {
|
||||
Some("result") => {
|
||||
get_bind_response_jid(&iq)
|
||||
.map(|jid| stream.jid = jid);
|
||||
|
|
@ -123,13 +114,13 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_bind_response_jid(iq: &xml::Element) -> Option<Jid> {
|
||||
iq.get_child("bind", Some(NS_XMPP_BIND))
|
||||
fn get_bind_response_jid(iq: &Element) -> Option<Jid> {
|
||||
iq.get_child("bind", NS_XMPP_BIND)
|
||||
.and_then(|bind_el|
|
||||
bind_el.get_child("jid", Some(NS_XMPP_BIND))
|
||||
bind_el.get_child("jid", NS_XMPP_BIND)
|
||||
)
|
||||
.and_then(|jid_el|
|
||||
Jid::from_str(&jid_el.content_str())
|
||||
Jid::from_str(&jid_el.text())
|
||||
.ok()
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use xml;
|
||||
use minidom::Element;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
Online,
|
||||
Disconnected,
|
||||
Stanza(xml::Element),
|
||||
Stanza(Element),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
|
|
@ -17,12 +17,12 @@ impl Event {
|
|||
|
||||
pub fn is_stanza(&self, name: &str) -> bool {
|
||||
match self {
|
||||
&Event::Stanza(ref stanza) => stanza.name == name,
|
||||
&Event::Stanza(ref stanza) => stanza.name() == name,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_stanza(&self) -> Option<&xml::Element> {
|
||||
pub fn as_stanza(&self) -> Option<&Element> {
|
||||
match self {
|
||||
&Event::Stanza(ref stanza) => Some(stanza),
|
||||
_ => None,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ use tokio_core::net::TcpStream;
|
|||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
use tokio_tls::TlsStream;
|
||||
use futures::*;
|
||||
use minidom::Element;
|
||||
use jid::{Jid, JidParseError};
|
||||
use xml;
|
||||
use sasl::common::{Credentials, ChannelBinding};
|
||||
|
||||
use super::xmpp_codec::Packet;
|
||||
|
|
@ -76,7 +76,7 @@ impl Client {
|
|||
|
||||
fn can_starttls<S>(stream: &xmpp_stream::XMPPStream<S>) -> bool {
|
||||
stream.stream_features
|
||||
.get_child("starttls", Some(NS_XMPP_TLS))
|
||||
.get_child("starttls", NS_XMPP_TLS)
|
||||
.is_some()
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ impl Stream for Client {
|
|||
}
|
||||
|
||||
impl Sink for Client {
|
||||
type SinkItem = xml::Element;
|
||||
type SinkItem = Element;
|
||||
type SinkError = String;
|
||||
|
||||
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue