xmpp/iq/
mod.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::parsers::iq::{Iq, IqHeader, IqPayload};
8
9use crate::{Agent, Event};
10
11pub mod get;
12pub mod result;
13pub mod set;
14
15pub async fn handle_iq(agent: &mut Agent, iq: Iq) -> Vec<Event> {
16    let mut events = vec![];
17    let (IqHeader { from, to, id }, data) = iq.split();
18    let from = from.unwrap_or_else(|| agent.client.bound_jid().unwrap().to_bare().into());
19    if let IqPayload::Get(payload) = data {
20        get::handle_iq_get(agent, &mut events, from, to, id, payload).await;
21    } else if let IqPayload::Result(Some(payload)) = data {
22        result::handle_iq_result(agent, &mut events, from, to, id, payload).await;
23    } else if let IqPayload::Set(payload) = data {
24        set::handle_iq_set(agent, &mut events, from, to, id, payload).await;
25    }
26    events
27}