diff --git a/Cargo.toml b/Cargo.toml index 47fc1f96..04aa98f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ gitlab = { repository = "lumi/xmpp-rs" } [dependencies] xml-rs = "0.4.1" -xmpp-parsers = "0.6.0" +xmpp-parsers = "0.7.0" openssl = "0.9.12" base64 = "0.6.0" minidom = "0.4.1" @@ -24,6 +24,7 @@ jid = "0.2.1" sasl = "0.4.0" sha-1 = "0.4" chrono = "0.4.0" +try_from = "0.2.2" [features] insecure = [] diff --git a/src/lib.rs b/src/lib.rs index b144d347..c022941d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(try_from)] - extern crate xml; extern crate xmpp_parsers; extern crate openssl; @@ -7,6 +5,7 @@ extern crate minidom; extern crate base64; extern crate sha_1; extern crate chrono; +extern crate try_from; pub extern crate jid; pub extern crate sasl; diff --git a/src/plugins/caps.rs b/src/plugins/caps.rs index 1f44881a..c61e35ae 100644 --- a/src/plugins/caps.rs +++ b/src/plugins/caps.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::convert::TryFrom; +use try_from::TryFrom; use std::sync::{Mutex, Arc}; use plugin::PluginProxy; @@ -11,7 +11,7 @@ use plugins::stanza::{Presence, Iq}; use plugins::disco::DiscoInfoResult; use xmpp_parsers::presence::Type as PresenceType; use xmpp_parsers::iq::IqType; -use xmpp_parsers::disco::Disco; +use xmpp_parsers::disco::{DiscoInfoQuery, DiscoInfoResult as DiscoInfoResult_}; use xmpp_parsers::caps::Caps; #[derive(Debug)] @@ -26,7 +26,7 @@ impl Event for DiscoInfoRequest {} pub struct CapsPlugin { proxy: PluginProxy, pending: Arc>>, - cache: Arc>>, + cache: Arc>>, } impl CapsPlugin { @@ -59,11 +59,8 @@ impl CapsPlugin { let mut pending = self.pending.lock().unwrap(); pending.insert(recipient.clone(), (id.clone(), node.clone())); } - let disco = Disco { + let disco = DiscoInfoQuery { node: Some(node), - identities: vec!(), - features: vec!(), - extensions: vec!(), }; self.proxy.send(Iq { to: Some(recipient), diff --git a/src/plugins/disco.rs b/src/plugins/disco.rs index 712d945e..20912592 100644 --- a/src/plugins/disco.rs +++ b/src/plugins/disco.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use try_from::TryFrom; use std::sync::{Mutex, Arc}; use plugin::PluginProxy; @@ -7,7 +7,7 @@ use jid::Jid; use plugins::stanza::Iq; use xmpp_parsers::iq::IqType; -use xmpp_parsers::disco::{Disco, Identity, Feature}; +use xmpp_parsers::disco::{DiscoInfoQuery, DiscoInfoResult as DiscoInfoResult_, Identity, Feature}; use xmpp_parsers::data_forms::DataForm; use xmpp_parsers::ns; @@ -22,7 +22,7 @@ pub struct DiscoInfoRequest { pub struct DiscoInfoResult { pub from: Jid, pub id: String, - pub disco: Disco, + pub disco: DiscoInfoResult_, } impl Event for DiscoInfoRequest {} @@ -30,14 +30,14 @@ impl Event for DiscoInfoResult {} pub struct DiscoPlugin { proxy: PluginProxy, - cached_disco: Arc>, + cached_disco: Arc>, } impl DiscoPlugin { pub fn new(category: &str, type_: &str, lang: &str, name: &str) -> DiscoPlugin { DiscoPlugin { proxy: PluginProxy::new(), - cached_disco: Arc::new(Mutex::new(Disco { + cached_disco: Arc::new(Mutex::new(DiscoInfoResult_ { node: None, identities: vec!(Identity { category: category.to_owned(), @@ -96,7 +96,7 @@ impl DiscoPlugin { fn handle_iq(&self, iq: &Iq) -> Propagation { let iq = iq.clone(); if let IqType::Get(payload) = iq.payload { - if let Ok(disco) = Disco::try_from(payload) { + if let Ok(disco) = DiscoInfoQuery::try_from(payload) { self.proxy.dispatch(DiscoInfoRequest { from: iq.from.unwrap(), id: iq.id.unwrap(), @@ -105,7 +105,7 @@ impl DiscoPlugin { return Propagation::Stop; } } else if let IqType::Result(Some(payload)) = iq.payload { - if let Ok(disco) = Disco::try_from(payload) { + if let Ok(disco) = DiscoInfoResult_::try_from(payload) { self.proxy.dispatch(DiscoInfoResult { from: iq.from.unwrap(), id: iq.id.unwrap(), diff --git a/src/plugins/ibb.rs b/src/plugins/ibb.rs index 27646a0f..a8738a27 100644 --- a/src/plugins/ibb.rs +++ b/src/plugins/ibb.rs @@ -1,6 +1,6 @@ use std::collections::{HashMap, BTreeMap}; use std::collections::hash_map::Entry; -use std::convert::TryFrom; +use try_from::TryFrom; use std::sync::{Mutex, Arc}; use plugin::PluginProxy; @@ -9,7 +9,7 @@ use jid::Jid; use plugins::stanza::Iq; use plugins::disco::DiscoPlugin; -use xmpp_parsers::iq::{IqType, IqPayload}; +use xmpp_parsers::iq::{IqType, IqSetPayload}; use xmpp_parsers::ibb::{IBB, Stanza}; use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition}; use xmpp_parsers::ns; @@ -163,8 +163,8 @@ impl IbbPlugin { let from = iq.from.unwrap(); let id = iq.id.unwrap(); // TODO: use an intermediate plugin to parse this payload. - let payload = match IqPayload::try_from(payload) { - Ok(IqPayload::IBB(ibb)) => { + let payload = match IqSetPayload::try_from(payload) { + Ok(IqSetPayload::IBB(ibb)) => { match self.handle_ibb(from.clone(), ibb) { Ok(_) => IqType::Result(None), Err(error) => IqType::Error(error), diff --git a/src/plugins/messaging.rs b/src/plugins/messaging.rs index c29adc34..9b0d1d43 100644 --- a/src/plugins/messaging.rs +++ b/src/plugins/messaging.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use try_from::TryFrom; use std::collections::BTreeMap; use plugin::PluginProxy; diff --git a/src/plugins/muc.rs b/src/plugins/muc.rs index 9d8d6519..c316ba34 100644 --- a/src/plugins/muc.rs +++ b/src/plugins/muc.rs @@ -1,5 +1,5 @@ use std::collections::BTreeMap; -use std::convert::TryFrom; +use try_from::TryFrom; use jid::Jid; use error::Error; diff --git a/src/plugins/ping.rs b/src/plugins/ping.rs index aeca7a21..def22ba3 100644 --- a/src/plugins/ping.rs +++ b/src/plugins/ping.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use try_from::TryFrom; use plugin::PluginProxy; use event::{Event, Priority, Propagation}; @@ -7,7 +7,7 @@ use jid::Jid; use plugins::stanza::Iq; use plugins::disco::DiscoPlugin; -use xmpp_parsers::iq::{IqType, IqPayload}; +use xmpp_parsers::iq::{IqType, IqGetPayload}; use xmpp_parsers::ping::Ping; use xmpp_parsers::ns; @@ -54,7 +54,7 @@ impl PingPlugin { from: None, to: Some(to), id: Some(self.proxy.gen_id()), - payload: IqType::Get(IqPayload::Ping(Ping).into()), + payload: IqType::Get(IqGetPayload::Ping(Ping).into()), }.into()); Ok(()) } @@ -63,7 +63,7 @@ impl PingPlugin { let iq = iq.clone(); if let IqType::Get(payload) = iq.payload { // TODO: use an intermediate plugin to parse this payload. - if let Ok(IqPayload::Ping(_)) = IqPayload::try_from(payload) { + if let Ok(IqGetPayload::Ping(_)) = IqGetPayload::try_from(payload) { self.proxy.dispatch(PingEvent { // TODO: safety!!! from: iq.from.unwrap(), id: iq.id.unwrap(), diff --git a/src/plugins/roster.rs b/src/plugins/roster.rs index 8bd8166c..487a90ff 100644 --- a/src/plugins/roster.rs +++ b/src/plugins/roster.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::convert::TryFrom; +use try_from::TryFrom; use std::sync::Mutex; use plugin::PluginProxy; @@ -8,7 +8,7 @@ use jid::Jid; use plugins::stanza::Iq; use plugins::disco::DiscoPlugin; -use xmpp_parsers::iq::{IqType, IqPayload}; +use xmpp_parsers::iq::{IqType, IqSetPayload, IqResultPayload}; use xmpp_parsers::roster::{Roster, Item, Subscription}; use xmpp_parsers::ns; @@ -140,8 +140,8 @@ impl RosterPlugin { let id = iq.id.unwrap(); match iq.payload { IqType::Result(Some(payload)) => { - match IqPayload::try_from(payload) { - Ok(IqPayload::Roster(roster)) => { + match IqResultPayload::try_from(payload) { + Ok(IqResultPayload::Roster(roster)) => { self.handle_roster_reply(roster); Propagation::Stop }, @@ -150,8 +150,8 @@ impl RosterPlugin { } }, IqType::Set(payload) => { - match IqPayload::try_from(payload) { - Ok(IqPayload::Roster(roster)) => { + match IqSetPayload::try_from(payload) { + Ok(IqSetPayload::Roster(roster)) => { let payload = match self.handle_roster_push(roster) { Ok(_) => IqType::Result(None), Err(string) => { diff --git a/src/plugins/stanza.rs b/src/plugins/stanza.rs index 7bc6abae..894bdc3d 100644 --- a/src/plugins/stanza.rs +++ b/src/plugins/stanza.rs @@ -1,4 +1,4 @@ -use std::convert::TryFrom; +use try_from::TryFrom; use plugin::PluginProxy; use event::{Event, ReceiveElement, Propagation, Priority};