2023-12-29 18:18:38 +01:00
|
|
|
// Copyright (c) 2023 xmpp-rs contributors.
|
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
|
|
use tokio_xmpp::parsers::{
|
|
|
|
|
iq::{Iq, IqType},
|
|
|
|
|
stanza_error::{DefinedCondition, ErrorType, StanzaError},
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-31 13:55:15 +01:00
|
|
|
use crate::{Agent, Event};
|
2023-12-29 18:18:38 +01:00
|
|
|
|
2023-12-30 01:08:52 +01:00
|
|
|
pub mod get;
|
2023-12-31 13:55:15 +01:00
|
|
|
pub mod result;
|
2023-12-30 01:08:52 +01:00
|
|
|
|
2023-12-29 18:18:38 +01:00
|
|
|
pub async fn handle_iq(agent: &mut Agent, iq: Iq) -> Vec<Event> {
|
|
|
|
|
let mut events = vec![];
|
|
|
|
|
let from = iq
|
|
|
|
|
.from
|
|
|
|
|
.clone()
|
|
|
|
|
.unwrap_or_else(|| agent.client.bound_jid().unwrap().clone());
|
|
|
|
|
if let IqType::Get(payload) = iq.payload {
|
2023-12-30 01:08:52 +01:00
|
|
|
get::handle_iq_get(agent, &mut events, from, iq.to, iq.id, payload).await;
|
2023-12-29 18:18:38 +01:00
|
|
|
} else if let IqType::Result(Some(payload)) = iq.payload {
|
2023-12-31 13:55:15 +01:00
|
|
|
result::handle_iq_result(agent, &mut events, from, iq.to, iq.id, payload).await;
|
|
|
|
|
} else if let IqType::Set(_payload) = iq.payload {
|
2023-12-29 18:18:38 +01:00
|
|
|
let error = StanzaError::new(
|
|
|
|
|
ErrorType::Cancel,
|
|
|
|
|
DefinedCondition::ServiceUnavailable,
|
|
|
|
|
"en",
|
|
|
|
|
"No handler defined for this kind of iq.",
|
|
|
|
|
);
|
2023-12-31 13:55:15 +01:00
|
|
|
let iq = Iq::from_error(iq.id, error).with_to(from).into();
|
2023-12-29 18:18:38 +01:00
|
|
|
let _ = agent.client.send_stanza(iq).await;
|
|
|
|
|
}
|
|
|
|
|
events
|
|
|
|
|
}
|