set.rs

 1// Copyright (c) 2023 xmpp-rs contributors.
 2//
 3// This Source Code Form is subject to the terms of the Mozilla Public
 4// License, v. 2.0. If a copy of the MPL was not distributed with this
 5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
 6
 7use tokio_xmpp::connect::ServerConnector;
 8use tokio_xmpp::{
 9    jid::Jid,
10    minidom::Element,
11    parsers::{
12        iq::Iq,
13        stanza_error::{DefinedCondition, ErrorType, StanzaError},
14    },
15};
16
17use crate::{Agent, Event};
18
19pub async fn handle_iq_set<C: ServerConnector>(
20    agent: &mut Agent<C>,
21    _events: &mut Vec<Event>,
22    from: Jid,
23    _to: Option<Jid>,
24    id: String,
25    _payload: Element,
26) {
27    // We MUST answer unhandled set iqs with a service-unavailable error.
28    let error = StanzaError::new(
29        ErrorType::Cancel,
30        DefinedCondition::ServiceUnavailable,
31        "en",
32        "No handler defined for this kind of iq.",
33    );
34    let iq = Iq::from_error(id, error).with_to(from).into();
35    let _ = agent.client.send_stanza(iq).await;
36}