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]
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 = []

View file

@ -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;

View file

@ -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<Mutex<HashMap<Jid, (String, String)>>>,
cache: Arc<Mutex<HashMap<(Jid, String), Disco>>>,
cache: Arc<Mutex<HashMap<(Jid, String), DiscoInfoResult_>>>,
}
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),

View file

@ -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<Mutex<Disco>>,
cached_disco: Arc<Mutex<DiscoInfoResult_>>,
}
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(),

View file

@ -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),

View file

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

View file

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

View file

@ -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(),

View file

@ -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) => {

View file

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