update to xmpp-parsers 0.7.0

This commit is contained in:
Emmanuel Gil Peyrot 2017-07-23 18:59:41 +01:00
parent aeb0bc8ed7
commit ba8c86620a
10 changed files with 31 additions and 34 deletions

View file

@ -16,7 +16,7 @@ gitlab = { repository = "lumi/xmpp-rs" }
[dependencies] [dependencies]
xml-rs = "0.4.1" xml-rs = "0.4.1"
xmpp-parsers = "0.6.0" xmpp-parsers = "0.7.0"
openssl = "0.9.12" openssl = "0.9.12"
base64 = "0.6.0" base64 = "0.6.0"
minidom = "0.4.1" minidom = "0.4.1"
@ -24,6 +24,7 @@ jid = "0.2.1"
sasl = "0.4.0" sasl = "0.4.0"
sha-1 = "0.4" sha-1 = "0.4"
chrono = "0.4.0" chrono = "0.4.0"
try_from = "0.2.2"
[features] [features]
insecure = [] insecure = []

View file

@ -1,5 +1,3 @@
#![feature(try_from)]
extern crate xml; extern crate xml;
extern crate xmpp_parsers; extern crate xmpp_parsers;
extern crate openssl; extern crate openssl;
@ -7,6 +5,7 @@ extern crate minidom;
extern crate base64; extern crate base64;
extern crate sha_1; extern crate sha_1;
extern crate chrono; extern crate chrono;
extern crate try_from;
pub extern crate jid; pub extern crate jid;
pub extern crate sasl; pub extern crate sasl;

View file

@ -1,5 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use try_from::TryFrom;
use std::sync::{Mutex, Arc}; use std::sync::{Mutex, Arc};
use plugin::PluginProxy; use plugin::PluginProxy;
@ -11,7 +11,7 @@ use plugins::stanza::{Presence, Iq};
use plugins::disco::DiscoInfoResult; use plugins::disco::DiscoInfoResult;
use xmpp_parsers::presence::Type as PresenceType; use xmpp_parsers::presence::Type as PresenceType;
use xmpp_parsers::iq::IqType; use xmpp_parsers::iq::IqType;
use xmpp_parsers::disco::Disco; use xmpp_parsers::disco::{DiscoInfoQuery, DiscoInfoResult as DiscoInfoResult_};
use xmpp_parsers::caps::Caps; use xmpp_parsers::caps::Caps;
#[derive(Debug)] #[derive(Debug)]
@ -26,7 +26,7 @@ impl Event for DiscoInfoRequest {}
pub struct CapsPlugin { pub struct CapsPlugin {
proxy: PluginProxy, proxy: PluginProxy,
pending: Arc<Mutex<HashMap<Jid, (String, String)>>>, pending: Arc<Mutex<HashMap<Jid, (String, String)>>>,
cache: Arc<Mutex<HashMap<(Jid, String), Disco>>>, cache: Arc<Mutex<HashMap<(Jid, String), DiscoInfoResult_>>>,
} }
impl CapsPlugin { impl CapsPlugin {
@ -59,11 +59,8 @@ impl CapsPlugin {
let mut pending = self.pending.lock().unwrap(); let mut pending = self.pending.lock().unwrap();
pending.insert(recipient.clone(), (id.clone(), node.clone())); pending.insert(recipient.clone(), (id.clone(), node.clone()));
} }
let disco = Disco { let disco = DiscoInfoQuery {
node: Some(node), node: Some(node),
identities: vec!(),
features: vec!(),
extensions: vec!(),
}; };
self.proxy.send(Iq { self.proxy.send(Iq {
to: Some(recipient), to: Some(recipient),

View file

@ -1,4 +1,4 @@
use std::convert::TryFrom; use try_from::TryFrom;
use std::sync::{Mutex, Arc}; use std::sync::{Mutex, Arc};
use plugin::PluginProxy; use plugin::PluginProxy;
@ -7,7 +7,7 @@ use jid::Jid;
use plugins::stanza::Iq; use plugins::stanza::Iq;
use xmpp_parsers::iq::IqType; 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::data_forms::DataForm;
use xmpp_parsers::ns; use xmpp_parsers::ns;
@ -22,7 +22,7 @@ pub struct DiscoInfoRequest {
pub struct DiscoInfoResult { pub struct DiscoInfoResult {
pub from: Jid, pub from: Jid,
pub id: String, pub id: String,
pub disco: Disco, pub disco: DiscoInfoResult_,
} }
impl Event for DiscoInfoRequest {} impl Event for DiscoInfoRequest {}
@ -30,14 +30,14 @@ impl Event for DiscoInfoResult {}
pub struct DiscoPlugin { pub struct DiscoPlugin {
proxy: PluginProxy, proxy: PluginProxy,
cached_disco: Arc<Mutex<Disco>>, cached_disco: Arc<Mutex<DiscoInfoResult_>>,
} }
impl DiscoPlugin { impl DiscoPlugin {
pub fn new(category: &str, type_: &str, lang: &str, name: &str) -> DiscoPlugin { pub fn new(category: &str, type_: &str, lang: &str, name: &str) -> DiscoPlugin {
DiscoPlugin { DiscoPlugin {
proxy: PluginProxy::new(), proxy: PluginProxy::new(),
cached_disco: Arc::new(Mutex::new(Disco { cached_disco: Arc::new(Mutex::new(DiscoInfoResult_ {
node: None, node: None,
identities: vec!(Identity { identities: vec!(Identity {
category: category.to_owned(), category: category.to_owned(),
@ -96,7 +96,7 @@ impl DiscoPlugin {
fn handle_iq(&self, iq: &Iq) -> Propagation { fn handle_iq(&self, iq: &Iq) -> Propagation {
let iq = iq.clone(); let iq = iq.clone();
if let IqType::Get(payload) = iq.payload { 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 { self.proxy.dispatch(DiscoInfoRequest {
from: iq.from.unwrap(), from: iq.from.unwrap(),
id: iq.id.unwrap(), id: iq.id.unwrap(),
@ -105,7 +105,7 @@ impl DiscoPlugin {
return Propagation::Stop; return Propagation::Stop;
} }
} else if let IqType::Result(Some(payload)) = iq.payload { } 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 { self.proxy.dispatch(DiscoInfoResult {
from: iq.from.unwrap(), from: iq.from.unwrap(),
id: iq.id.unwrap(), id: iq.id.unwrap(),

View file

@ -1,6 +1,6 @@
use std::collections::{HashMap, BTreeMap}; use std::collections::{HashMap, BTreeMap};
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::convert::TryFrom; use try_from::TryFrom;
use std::sync::{Mutex, Arc}; use std::sync::{Mutex, Arc};
use plugin::PluginProxy; use plugin::PluginProxy;
@ -9,7 +9,7 @@ use jid::Jid;
use plugins::stanza::Iq; use plugins::stanza::Iq;
use plugins::disco::DiscoPlugin; 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::ibb::{IBB, Stanza};
use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition}; use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition};
use xmpp_parsers::ns; use xmpp_parsers::ns;
@ -163,8 +163,8 @@ impl IbbPlugin {
let from = iq.from.unwrap(); let from = iq.from.unwrap();
let id = iq.id.unwrap(); let id = iq.id.unwrap();
// TODO: use an intermediate plugin to parse this payload. // TODO: use an intermediate plugin to parse this payload.
let payload = match IqPayload::try_from(payload) { let payload = match IqSetPayload::try_from(payload) {
Ok(IqPayload::IBB(ibb)) => { Ok(IqSetPayload::IBB(ibb)) => {
match self.handle_ibb(from.clone(), ibb) { match self.handle_ibb(from.clone(), ibb) {
Ok(_) => IqType::Result(None), Ok(_) => IqType::Result(None),
Err(error) => IqType::Error(error), Err(error) => IqType::Error(error),

View file

@ -1,4 +1,4 @@
use std::convert::TryFrom; use try_from::TryFrom;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use plugin::PluginProxy; use plugin::PluginProxy;

View file

@ -1,5 +1,5 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::convert::TryFrom; use try_from::TryFrom;
use jid::Jid; use jid::Jid;
use error::Error; use error::Error;

View file

@ -1,4 +1,4 @@
use std::convert::TryFrom; use try_from::TryFrom;
use plugin::PluginProxy; use plugin::PluginProxy;
use event::{Event, Priority, Propagation}; use event::{Event, Priority, Propagation};
@ -7,7 +7,7 @@ use jid::Jid;
use plugins::stanza::Iq; use plugins::stanza::Iq;
use plugins::disco::DiscoPlugin; use plugins::disco::DiscoPlugin;
use xmpp_parsers::iq::{IqType, IqPayload}; use xmpp_parsers::iq::{IqType, IqGetPayload};
use xmpp_parsers::ping::Ping; use xmpp_parsers::ping::Ping;
use xmpp_parsers::ns; use xmpp_parsers::ns;
@ -54,7 +54,7 @@ impl PingPlugin {
from: None, from: None,
to: Some(to), to: Some(to),
id: Some(self.proxy.gen_id()), id: Some(self.proxy.gen_id()),
payload: IqType::Get(IqPayload::Ping(Ping).into()), payload: IqType::Get(IqGetPayload::Ping(Ping).into()),
}.into()); }.into());
Ok(()) Ok(())
} }
@ -63,7 +63,7 @@ impl PingPlugin {
let iq = iq.clone(); let iq = iq.clone();
if let IqType::Get(payload) = iq.payload { if let IqType::Get(payload) = iq.payload {
// TODO: use an intermediate plugin to parse this 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!!! self.proxy.dispatch(PingEvent { // TODO: safety!!!
from: iq.from.unwrap(), from: iq.from.unwrap(),
id: iq.id.unwrap(), id: iq.id.unwrap(),

View file

@ -1,5 +1,5 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryFrom; use try_from::TryFrom;
use std::sync::Mutex; use std::sync::Mutex;
use plugin::PluginProxy; use plugin::PluginProxy;
@ -8,7 +8,7 @@ use jid::Jid;
use plugins::stanza::Iq; use plugins::stanza::Iq;
use plugins::disco::DiscoPlugin; 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::roster::{Roster, Item, Subscription};
use xmpp_parsers::ns; use xmpp_parsers::ns;
@ -140,8 +140,8 @@ impl RosterPlugin {
let id = iq.id.unwrap(); let id = iq.id.unwrap();
match iq.payload { match iq.payload {
IqType::Result(Some(payload)) => { IqType::Result(Some(payload)) => {
match IqPayload::try_from(payload) { match IqResultPayload::try_from(payload) {
Ok(IqPayload::Roster(roster)) => { Ok(IqResultPayload::Roster(roster)) => {
self.handle_roster_reply(roster); self.handle_roster_reply(roster);
Propagation::Stop Propagation::Stop
}, },
@ -150,8 +150,8 @@ impl RosterPlugin {
} }
}, },
IqType::Set(payload) => { IqType::Set(payload) => {
match IqPayload::try_from(payload) { match IqSetPayload::try_from(payload) {
Ok(IqPayload::Roster(roster)) => { Ok(IqSetPayload::Roster(roster)) => {
let payload = match self.handle_roster_push(roster) { let payload = match self.handle_roster_push(roster) {
Ok(_) => IqType::Result(None), Ok(_) => IqType::Result(None),
Err(string) => { Err(string) => {

View file

@ -1,4 +1,4 @@
use std::convert::TryFrom; use try_from::TryFrom;
use plugin::PluginProxy; use plugin::PluginProxy;
use event::{Event, ReceiveElement, Propagation, Priority}; use event::{Event, ReceiveElement, Propagation, Priority};