Merge branch 'xmpp-parsers' into 'master'
Add an xmpp-parsers dependency See merge request !7
This commit is contained in:
commit
d0fa23f19a
3 changed files with 21 additions and 64 deletions
|
@ -16,12 +16,13 @@ gitlab = { repository = "lumi/xmpp-rs" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
xml-rs = "0.4.1"
|
xml-rs = "0.4.1"
|
||||||
openssl = "0.9.7"
|
xmpp-parsers = "0.3.0"
|
||||||
|
openssl = "0.9.12"
|
||||||
base64 = "0.5.2"
|
base64 = "0.5.2"
|
||||||
minidom = "0.3.0"
|
minidom = "0.4.1"
|
||||||
jid = "0.2.0"
|
jid = "0.2.0"
|
||||||
sasl = "0.4.0"
|
sasl = "0.4.0"
|
||||||
sha-1 = "0.3.2"
|
sha-1 = "0.3.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
insecure = []
|
insecure = []
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#![feature(raw)]
|
#![feature(raw)]
|
||||||
|
#![feature(try_from)]
|
||||||
|
|
||||||
extern crate xml;
|
extern crate xml;
|
||||||
|
extern crate xmpp_parsers;
|
||||||
extern crate openssl;
|
extern crate openssl;
|
||||||
extern crate minidom;
|
extern crate minidom;
|
||||||
extern crate base64;
|
extern crate base64;
|
||||||
|
|
|
@ -1,44 +1,16 @@
|
||||||
use std::fmt::Debug;
|
use std::convert::TryFrom;
|
||||||
use std::any::Any;
|
|
||||||
|
|
||||||
use plugin::PluginProxy;
|
use plugin::PluginProxy;
|
||||||
use event::{Event, EventHandler, ReceiveElement, Propagation, Priority};
|
use event::{Event, EventHandler, ReceiveElement, Propagation, Priority};
|
||||||
use minidom::Element;
|
|
||||||
use jid::Jid;
|
|
||||||
use ns;
|
use ns;
|
||||||
|
|
||||||
pub trait Stanza: Any + Debug {}
|
pub use xmpp_parsers::message::Message;
|
||||||
|
pub use xmpp_parsers::presence::Presence;
|
||||||
|
pub use xmpp_parsers::iq::Iq;
|
||||||
|
|
||||||
#[derive(Debug)]
|
impl Event for Message {}
|
||||||
pub struct MessageEvent {
|
impl Event for Presence {}
|
||||||
pub from: Option<Jid>,
|
impl Event for Iq {}
|
||||||
pub to: Option<Jid>,
|
|
||||||
pub id: Option<String>,
|
|
||||||
pub type_: Option<String>,
|
|
||||||
pub payloads: Vec<Element>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct IqEvent {
|
|
||||||
pub from: Option<Jid>,
|
|
||||||
pub to: Option<Jid>,
|
|
||||||
pub id: Option<String>,
|
|
||||||
pub type_: Option<String>,
|
|
||||||
pub payloads: Vec<Element>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PresenceEvent {
|
|
||||||
pub from: Option<Jid>,
|
|
||||||
pub to: Option<Jid>,
|
|
||||||
pub id: Option<String>,
|
|
||||||
pub type_: Option<String>,
|
|
||||||
pub payloads: Vec<Element>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Event for MessageEvent {}
|
|
||||||
impl Event for IqEvent {}
|
|
||||||
impl Event for PresenceEvent {}
|
|
||||||
|
|
||||||
pub struct StanzaPlugin {
|
pub struct StanzaPlugin {
|
||||||
proxy: PluginProxy,
|
proxy: PluginProxy,
|
||||||
|
@ -60,36 +32,18 @@ impl EventHandler<ReceiveElement> for StanzaPlugin {
|
||||||
fn handle(&self, evt: &ReceiveElement) -> Propagation {
|
fn handle(&self, evt: &ReceiveElement) -> Propagation {
|
||||||
let elem = &evt.0;
|
let elem = &evt.0;
|
||||||
|
|
||||||
let from = match elem.attr("from") { Some(from) => Some(from.parse().unwrap()), None => None };
|
// TODO: make the handle take an Element instead of a reference.
|
||||||
let to = match elem.attr("to") { Some(to) => Some(to.parse().unwrap()), None => None };
|
let elem = elem.clone();
|
||||||
let id = match elem.attr("id") { Some(id) => Some(id.parse().unwrap()), None => None };
|
|
||||||
let type_ = match elem.attr("type") { Some(type_) => Some(type_.parse().unwrap()), None => None };
|
|
||||||
let payloads = elem.children().cloned().collect::<Vec<_>>();
|
|
||||||
|
|
||||||
if elem.is("message", ns::CLIENT) {
|
if elem.is("message", ns::CLIENT) {
|
||||||
self.proxy.dispatch(MessageEvent {
|
let message = Message::try_from(elem).unwrap();
|
||||||
from: from,
|
self.proxy.dispatch(message);
|
||||||
to: to,
|
|
||||||
id: id,
|
|
||||||
type_: type_,
|
|
||||||
payloads: payloads,
|
|
||||||
});
|
|
||||||
} else if elem.is("presence", ns::CLIENT) {
|
} else if elem.is("presence", ns::CLIENT) {
|
||||||
self.proxy.dispatch(PresenceEvent {
|
let presence = Presence::try_from(elem).unwrap();
|
||||||
from: from,
|
self.proxy.dispatch(presence);
|
||||||
to: to,
|
|
||||||
id: id,
|
|
||||||
type_: type_,
|
|
||||||
payloads: payloads,
|
|
||||||
});
|
|
||||||
} else if elem.is("iq", ns::CLIENT) {
|
} else if elem.is("iq", ns::CLIENT) {
|
||||||
self.proxy.dispatch(IqEvent {
|
let iq = Iq::try_from(elem).unwrap();
|
||||||
from: from,
|
self.proxy.dispatch(iq);
|
||||||
to: to,
|
|
||||||
id: id,
|
|
||||||
type_: type_,
|
|
||||||
payloads: payloads,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Propagation::Continue
|
Propagation::Continue
|
||||||
|
|
Loading…
Reference in a new issue