1use std::collections::BTreeMap;
2
3use plugin::PluginProxy;
4use event::{Priority, Propagation};
5
6use plugins::stanza::Iq;
7use xmpp_parsers::iq::IqType;
8use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition};
9
10pub struct UnhandledIqPlugin {
11 proxy: PluginProxy,
12}
13
14impl UnhandledIqPlugin {
15 pub fn new() -> UnhandledIqPlugin {
16 UnhandledIqPlugin {
17 proxy: PluginProxy::new(),
18 }
19 }
20
21 fn reply_unhandled_iq(&self, iq: &Iq) -> Propagation {
22 let iq = iq.clone();
23 match iq.payload {
24 IqType::Get(_)
25 | IqType::Set(_) => {
26 self.proxy.send(Iq {
27 from: None,
28 to: Some(iq.from.unwrap()),
29 id: Some(iq.id.unwrap()),
30 payload: IqType::Error(StanzaError {
31 type_: ErrorType::Cancel,
32 defined_condition: DefinedCondition::ServiceUnavailable,
33 texts: BTreeMap::new(),
34 by: None,
35 other: None,
36 }),
37 }.into());
38 Propagation::Stop
39 },
40 IqType::Result(_)
41 | IqType::Error(_) => Propagation::Continue
42 }
43 }
44}
45
46impl_plugin!(UnhandledIqPlugin, proxy, [
47 (Iq, Priority::Min) => reply_unhandled_iq,
48]);