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    parsers::{
10        iq::Iq,
11        stanza_error::{DefinedCondition, ErrorType, StanzaError},
12    },
13    Element, Jid,
14};
15
16use crate::{Agent, Event};
17
18pub async fn handle_iq_set<C: ServerConnector>(
19    agent: &mut Agent<C>,
20    _events: &mut Vec<Event>,
21    from: Jid,
22    _to: Option<Jid>,
23    id: String,
24    _payload: Element,
25) {
26    // We MUST answer unhandled set iqs with a service-unavailable error.
27    let error = StanzaError::new(
28        ErrorType::Cancel,
29        DefinedCondition::ServiceUnavailable,
30        "en",
31        "No handler defined for this kind of iq.",
32    );
33    let iq = Iq::from_error(id, error).with_to(from).into();
34    let _ = agent.client.send_stanza(iq).await;
35}