forked from lavina/lavina
1
0
Fork 0

xmpp: add item-not-found error condition to room disco#info iq

This commit is contained in:
Nikita Vilunov 2024-05-13 16:42:52 +02:00
parent 26720a2a08
commit 89918d9de1
2 changed files with 27 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use quick_xml::events::Event;
use lavina_core::room::RoomId; use lavina_core::room::RoomId;
use lavina_core::LavinaCore; use lavina_core::LavinaCore;
use proto_xmpp::bind::{BindRequest, BindResponse, Jid, Name, Server}; use proto_xmpp::bind::{BindRequest, BindResponse, Jid, Name, Server};
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType}; use proto_xmpp::client::{Iq, IqError, IqErrorCondition, IqErrorType, IqType};
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery}; use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
use proto_xmpp::mam::{Fin, Set}; use proto_xmpp::mam::{Fin, Set};
use proto_xmpp::roster::RosterQuery; use proto_xmpp::roster::RosterQuery;
@ -104,6 +104,7 @@ impl<'a> XmppConnection<'a> {
r#type: IqType::Error, r#type: IqType::Error,
body: IqError { body: IqError {
r#type: IqErrorType::Cancel, r#type: IqErrorType::Cancel,
condition: None,
}, },
}; };
req.serialize(output); req.serialize(output);
@ -172,6 +173,7 @@ impl<'a> XmppConnection<'a> {
// </error> // </error>
return Err(IqError { return Err(IqError {
r#type: IqErrorType::Cancel, r#type: IqErrorType::Cancel,
condition: Some(IqErrorCondition::ItemNotFound),
}); });
}; };
identity = vec![Identity { identity = vec![Identity {

View File

@ -260,6 +260,18 @@ impl MessageType {
/// https://xmpp.org/rfcs/rfc6120.html#stanzas-error /// https://xmpp.org/rfcs/rfc6120.html#stanzas-error
pub struct IqError { pub struct IqError {
pub r#type: IqErrorType, pub r#type: IqErrorType,
pub condition: Option<IqErrorCondition>,
}
pub enum IqErrorCondition {
ItemNotFound,
}
impl IqErrorCondition {
pub fn as_str(&self) -> &'static str {
match self {
IqErrorCondition::ItemNotFound => "item-not-found",
}
}
} }
pub enum IqErrorType { pub enum IqErrorType {
@ -289,8 +301,19 @@ impl IqErrorType {
impl ToXml for IqError { impl ToXml for IqError {
fn serialize(&self, events: &mut Vec<Event<'static>>) { fn serialize(&self, events: &mut Vec<Event<'static>>) {
let bytes = BytesStart::new(format!(r#"error xmlns="{}" type="{}""#, XMLNS, self.r#type.as_str())); let bytes = BytesStart::new(format!(r#"error xmlns="{}" type="{}""#, XMLNS, self.r#type.as_str()));
match self.condition {
None => {
events.push(Event::Empty(bytes)); events.push(Event::Empty(bytes));
} }
Some(IqErrorCondition::ItemNotFound) => {
events.push(Event::Start(bytes));
let bytes2 = BytesStart::new(r#"item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas""#);
events.push(Event::Empty(bytes2));
let bytes = BytesEnd::new("error");
events.push(Event::End(bytes));
}
}
}
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]