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