From 66bf10b941cd1f2601fcae85af6911fac18aa474 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 17:19:28 +0100 Subject: [PATCH 1/2] add a stanza_debug plugin, printing every stanza on stdout --- src/plugins/mod.rs | 1 + src/plugins/stanza_debug.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/plugins/stanza_debug.rs diff --git a/src/plugins/mod.rs b/src/plugins/mod.rs index 355942eb..c15ae512 100644 --- a/src/plugins/mod.rs +++ b/src/plugins/mod.rs @@ -2,3 +2,4 @@ pub mod messaging; pub mod presence; pub mod ping; pub mod stanza; +pub mod stanza_debug; diff --git a/src/plugins/stanza_debug.rs b/src/plugins/stanza_debug.rs new file mode 100644 index 00000000..c94679a5 --- /dev/null +++ b/src/plugins/stanza_debug.rs @@ -0,0 +1,29 @@ +use plugin::PluginProxy; +use event::{SendElement, ReceiveElement, Propagation, Priority}; + +pub struct StanzaDebugPlugin { + proxy: PluginProxy, +} + +impl StanzaDebugPlugin { + pub fn new() -> StanzaDebugPlugin { + StanzaDebugPlugin { + proxy: PluginProxy::new(), + } + } + + fn handle_send_element(&self, evt: &SendElement) -> Propagation { + println!("SEND: {:?}", evt.0); + Propagation::Continue + } + + fn handle_receive_element(&self, evt: &ReceiveElement) -> Propagation { + println!("RECV: {:?}", evt.0); + Propagation::Continue + } +} + +impl_plugin!(StanzaDebugPlugin, proxy, [ + (SendElement, Priority::Min) => handle_send_element, + (ReceiveElement, Priority::Max) => handle_receive_element, +]); From 967d3e321786805548bb12d798955a7dd099c6c7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 17:24:24 +0100 Subject: [PATCH 2/2] stop propagating when we are done with a stanza --- src/plugins/ping.rs | 2 +- src/plugins/stanza.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/ping.rs b/src/plugins/ping.rs index f409a1ee..e798bf0a 100644 --- a/src/plugins/ping.rs +++ b/src/plugins/ping.rs @@ -51,7 +51,7 @@ impl PingPlugin { }); } } - Propagation::Continue + Propagation::Stop } fn reply_ping(&self, ping: &PingEvent) -> Propagation { diff --git a/src/plugins/stanza.rs b/src/plugins/stanza.rs index 02ef1259..0924e5cf 100644 --- a/src/plugins/stanza.rs +++ b/src/plugins/stanza.rs @@ -40,7 +40,7 @@ impl StanzaPlugin { self.proxy.dispatch(iq); } - Propagation::Continue + Propagation::Stop } }