delint (clippy)
This commit is contained in:
parent
00e2daaecd
commit
7cd31bd425
8 changed files with 55 additions and 64 deletions
|
|
@ -54,18 +54,17 @@ fn main() {
|
|||
|
||||
let presence = make_presence();
|
||||
send(presence);
|
||||
} else if let Some(stanza) = event.into_stanza() {
|
||||
if let Ok(message) = Message::try_from(stanza) {
|
||||
if message.type_ != MessageType::Error {
|
||||
// This is a message we'll echo
|
||||
match (message.from, message.bodies.get("")) {
|
||||
(Some(from), Some(body)) => {
|
||||
let reply = make_reply(from, body);
|
||||
send(reply);
|
||||
},
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
} else if let Some(message) = event.into_stanza()
|
||||
.and_then(|stanza| Message::try_from(stanza).ok())
|
||||
{
|
||||
// This is a message we'll echo
|
||||
match (message.from, message.bodies.get("")) {
|
||||
(Some(from), Some(body)) =>
|
||||
if message.type_ != MessageType::Error {
|
||||
let reply = make_reply(from, body);
|
||||
send(reply);
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -130,12 +130,9 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientAuth<S> {
|
|||
if stanza.name() == "failure"
|
||||
&& stanza.ns() == Some(NS_XMPP_SASL) =>
|
||||
{
|
||||
let mut e = None;
|
||||
for child in stanza.children() {
|
||||
e = Some(child.name().clone());
|
||||
break
|
||||
}
|
||||
let e = e.unwrap_or_else(|| "Authentication failure");
|
||||
let e = stanza.children().next()
|
||||
.map(|child| child.name())
|
||||
.unwrap_or("Authentication failure");
|
||||
Err(e.to_owned())
|
||||
},
|
||||
Ok(Async::Ready(event)) => {
|
||||
|
|
|
|||
|
|
@ -44,13 +44,10 @@ fn make_bind_request(resource: Option<&String>) -> Element {
|
|||
.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 => (),
|
||||
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()
|
||||
|
|
@ -87,7 +84,7 @@ impl<S: AsyncRead + AsyncWrite> Future for ClientBind<S> {
|
|||
&& iq.attr("id") == Some(BIND_REQ_ID) => {
|
||||
match iq.attr("type") {
|
||||
Some("result") => {
|
||||
get_bind_response_jid(&iq)
|
||||
get_bind_response_jid(iq)
|
||||
.map(|jid| stream.jid = jid);
|
||||
Ok(Async::Ready(stream))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -9,22 +9,22 @@ pub enum Event {
|
|||
|
||||
impl Event {
|
||||
pub fn is_online(&self) -> bool {
|
||||
match self {
|
||||
&Event::Online => true,
|
||||
match *self {
|
||||
Event::Online => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_stanza(&self, name: &str) -> bool {
|
||||
match self {
|
||||
&Event::Stanza(ref stanza) => stanza.name() == name,
|
||||
match *self {
|
||||
Event::Stanza(ref stanza) => stanza.name() == name,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_stanza(&self) -> Option<&Element> {
|
||||
match self {
|
||||
&Event::Stanza(ref stanza) => Some(stanza),
|
||||
match *self {
|
||||
Event::Stanza(ref stanza) => Some(stanza),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -130,10 +130,6 @@ impl Stream for Client {
|
|||
},
|
||||
ClientState::Connected(mut stream) => {
|
||||
match stream.poll() {
|
||||
Ok(Async::NotReady) => {
|
||||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::NotReady)
|
||||
},
|
||||
Ok(Async::Ready(None)) => {
|
||||
// EOF
|
||||
self.state = ClientState::Disconnected;
|
||||
|
|
@ -143,6 +139,7 @@ impl Stream for Client {
|
|||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::Ready(Some(ClientEvent::Stanza(stanza))))
|
||||
},
|
||||
Ok(Async::NotReady) |
|
||||
Ok(Async::Ready(_)) => {
|
||||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::NotReady)
|
||||
|
|
@ -179,8 +176,8 @@ impl Sink for Client {
|
|||
}
|
||||
|
||||
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
|
||||
match &mut self.state {
|
||||
&mut ClientState::Connected(ref mut stream) =>
|
||||
match self.state {
|
||||
ClientState::Connected(ref mut stream) =>
|
||||
stream.poll_complete()
|
||||
.map_err(|e| e.description().to_owned()),
|
||||
_ =>
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ impl Future for Connecter {
|
|||
|
||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||
match self.lookup.as_mut().map(|mut lookup| lookup.poll()) {
|
||||
None => (),
|
||||
Some(Ok(Async::NotReady)) => (),
|
||||
None | Some(Ok(Async::NotReady)) => (),
|
||||
Some(Ok(Async::Ready(found_srvs))) => {
|
||||
self.lookup = None;
|
||||
match found_srvs {
|
||||
|
|
@ -62,8 +61,7 @@ impl Future for Connecter {
|
|||
}
|
||||
|
||||
match self.srvs.as_mut().map(|mut srv| srv.poll()) {
|
||||
None => (),
|
||||
Some(Ok(Async::NotReady)) => (),
|
||||
None | Some(Ok(Async::NotReady)) => (),
|
||||
Some(Ok(Async::Ready(None))) =>
|
||||
self.srvs = None,
|
||||
Some(Ok(Async::Ready(Some(srv_item)))) => {
|
||||
|
|
@ -99,10 +97,8 @@ impl Future for Connecter {
|
|||
},
|
||||
}
|
||||
});
|
||||
match connected_stream {
|
||||
Some(tcp_stream) =>
|
||||
return Ok(Async::Ready(tcp_stream)),
|
||||
None => (),
|
||||
if let Some(tcp_stream) = connected_stream {
|
||||
return Ok(Async::Ready(tcp_stream));
|
||||
}
|
||||
|
||||
if self.lookup.is_none() &&
|
||||
|
|
|
|||
|
|
@ -89,9 +89,7 @@ impl<S: AsyncRead + AsyncWrite> Future for StreamStart<S> {
|
|||
} else {
|
||||
(StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady))
|
||||
},
|
||||
Ok(Async::Ready(_)) =>
|
||||
(StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)),
|
||||
Ok(Async::NotReady) =>
|
||||
Ok(Async::Ready(_)) | Ok(Async::NotReady) =>
|
||||
(StreamStartState::RecvFeatures(stream, stream_ns), Ok(Async::NotReady)),
|
||||
Err(e) =>
|
||||
return Err(e),
|
||||
|
|
|
|||
|
|
@ -48,9 +48,8 @@ impl ParserSink {
|
|||
|
||||
fn lookup_ns(&self, prefix: &Option<String>) -> Option<&str> {
|
||||
for nss in self.ns_stack.iter().rev() {
|
||||
match nss.get(prefix) {
|
||||
Some(ns) => return Some(ns),
|
||||
None => (),
|
||||
if let Some(ns) = nss.get(prefix) {
|
||||
return Some(ns);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,9 +76,11 @@ impl ParserSink {
|
|||
|
||||
let el = {
|
||||
let mut el_builder = Element::builder(tag.name.local.as_ref());
|
||||
match self.lookup_ns(&tag.name.prefix.map(|prefix| prefix.as_ref().to_owned())) {
|
||||
Some(el_ns) => el_builder = el_builder.ns(el_ns),
|
||||
None => (),
|
||||
if let Some(el_ns) = self.lookup_ns(
|
||||
&tag.name.prefix.map(|prefix|
|
||||
prefix.as_ref().to_owned())
|
||||
) {
|
||||
el_builder = el_builder.ns(el_ns);
|
||||
}
|
||||
for attr in &tag.attrs {
|
||||
match attr.name.local.as_ref() {
|
||||
|
|
@ -178,7 +179,7 @@ pub struct XMPPCodec {
|
|||
|
||||
impl XMPPCodec {
|
||||
pub fn new() -> Self {
|
||||
let queue = Rc::new(RefCell::new((VecDeque::new())));
|
||||
let queue = Rc::new(RefCell::new(VecDeque::new()));
|
||||
let sink = ParserSink::new(queue.clone());
|
||||
// TODO: configure parser?
|
||||
let parser = XmlTokenizer::new(sink, Default::default());
|
||||
|
|
@ -191,13 +192,19 @@ impl XMPPCodec {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for XMPPCodec {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decoder for XMPPCodec {
|
||||
type Item = Packet;
|
||||
type Error = Error;
|
||||
|
||||
fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
let buf1: Box<AsRef<[u8]>> =
|
||||
if self.buf.len() > 0 && buf.len() > 0 {
|
||||
if ! self.buf.is_empty() && ! buf.is_empty() {
|
||||
let mut prefix = std::mem::replace(&mut self.buf, vec![]);
|
||||
prefix.extend_from_slice(buf.take().as_ref());
|
||||
Box::new(prefix)
|
||||
|
|
@ -207,7 +214,7 @@ impl Decoder for XMPPCodec {
|
|||
let buf1 = buf1.as_ref().as_ref();
|
||||
match from_utf8(buf1) {
|
||||
Ok(s) => {
|
||||
if s.len() > 0 {
|
||||
if ! s.is_empty() {
|
||||
println!("<< {}", s);
|
||||
let tendril = FromIterator::from_iter(s.chars());
|
||||
self.parser.feed(tendril);
|
||||
|
|
@ -257,7 +264,7 @@ impl Encoder for XMPPCodec {
|
|||
Packet::StreamStart(start_attrs) => {
|
||||
let mut buf = String::new();
|
||||
write!(buf, "<stream:stream").unwrap();
|
||||
for (name, value) in start_attrs.into_iter() {
|
||||
for (name, value) in start_attrs {
|
||||
write!(buf, " {}=\"{}\"", escape(&name), escape(&value))
|
||||
.unwrap();
|
||||
if name == "xmlns" {
|
||||
|
|
@ -302,7 +309,7 @@ pub fn write_element<W: Write>(el: &Element, writer: &mut W, parent_ns: Option<&
|
|||
write!(writer, "<")?;
|
||||
write!(writer, "{}", el.name())?;
|
||||
|
||||
if let Some(ref ns) = el.ns() {
|
||||
if let Some(ns) = el.ns() {
|
||||
if parent_ns.map(|s| s.as_ref()) != el.ns() {
|
||||
write!(writer, " xmlns=\"{}\"", ns)?;
|
||||
}
|
||||
|
|
@ -320,10 +327,10 @@ pub fn write_element<W: Write>(el: &Element, writer: &mut W, parent_ns: Option<&
|
|||
write!(writer, ">")?;
|
||||
|
||||
for node in el.nodes() {
|
||||
match node {
|
||||
&Node::Element(ref child) =>
|
||||
match *node {
|
||||
Node::Element(ref child) =>
|
||||
write_element(child, writer, el.ns())?,
|
||||
&Node::Text(ref text) =>
|
||||
Node::Text(ref text) =>
|
||||
write_text(text, writer)?,
|
||||
}
|
||||
}
|
||||
|
|
@ -332,7 +339,7 @@ pub fn write_element<W: Write>(el: &Element, writer: &mut W, parent_ns: Option<&
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Copied from RustyXML for now
|
||||
/// Copied from `RustyXML` for now
|
||||
pub fn escape(input: &str) -> String {
|
||||
let mut result = String::with_capacity(input.len());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue