add an unhandled iq plugin
This commit is contained in:
parent
6efc77b423
commit
32380fe5a3
3 changed files with 51 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ extern crate xmpp;
|
|||
use xmpp::jid::Jid;
|
||||
use xmpp::client::ClientBuilder;
|
||||
use xmpp::plugins::stanza::StanzaPlugin;
|
||||
use xmpp::plugins::unhandled_iq::UnhandledIqPlugin;
|
||||
use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent};
|
||||
use xmpp::plugins::presence::{PresencePlugin, Type};
|
||||
use xmpp::plugins::ping::{PingPlugin, PingEvent};
|
||||
|
|
@ -18,6 +19,7 @@ fn main() {
|
|||
.connect()
|
||||
.unwrap();
|
||||
client.register_plugin(StanzaPlugin::new());
|
||||
client.register_plugin(UnhandledIqPlugin::new());
|
||||
client.register_plugin(MessagingPlugin::new());
|
||||
client.register_plugin(PresencePlugin::new());
|
||||
client.register_plugin(PingPlugin::new());
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ pub mod presence;
|
|||
pub mod ping;
|
||||
pub mod stanza;
|
||||
pub mod stanza_debug;
|
||||
pub mod unhandled_iq;
|
||||
|
|
|
|||
48
src/plugins/unhandled_iq.rs
Normal file
48
src/plugins/unhandled_iq.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use plugin::PluginProxy;
|
||||
use event::{Priority, Propagation};
|
||||
|
||||
use plugins::stanza::Iq;
|
||||
use xmpp_parsers::iq::IqType;
|
||||
use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition};
|
||||
|
||||
pub struct UnhandledIqPlugin {
|
||||
proxy: PluginProxy,
|
||||
}
|
||||
|
||||
impl UnhandledIqPlugin {
|
||||
pub fn new() -> UnhandledIqPlugin {
|
||||
UnhandledIqPlugin {
|
||||
proxy: PluginProxy::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn reply_unhandled_iq(&self, iq: &Iq) -> Propagation {
|
||||
let iq = iq.clone();
|
||||
match iq.payload {
|
||||
IqType::Get(_)
|
||||
| IqType::Set(_) => {
|
||||
self.proxy.send(Iq {
|
||||
from: None,
|
||||
to: Some(iq.from.unwrap()),
|
||||
id: Some(iq.id.unwrap()),
|
||||
payload: IqType::Error(StanzaError {
|
||||
type_: ErrorType::Cancel,
|
||||
defined_condition: DefinedCondition::ServiceUnavailable,
|
||||
texts: BTreeMap::new(),
|
||||
by: None,
|
||||
other: None,
|
||||
}),
|
||||
}.into());
|
||||
Propagation::Stop
|
||||
},
|
||||
IqType::Result(_)
|
||||
| IqType::Error(_) => Propagation::Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_plugin!(UnhandledIqPlugin, proxy, [
|
||||
(Iq, Priority::Min) => reply_unhandled_iq,
|
||||
]);
|
||||
Loading…
Reference in a new issue