forked from lavina/lavina
xmpp: send correct errors on unknown iqs
This commit is contained in:
parent
fd437df67e
commit
ab61e975bf
|
@ -4,7 +4,7 @@ use quick_xml::events::Event;
|
||||||
|
|
||||||
use lavina_core::room::RoomRegistry;
|
use lavina_core::room::RoomRegistry;
|
||||||
use proto_xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
|
use proto_xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
|
||||||
use proto_xmpp::client::{Iq, IqType};
|
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType};
|
||||||
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
||||||
use proto_xmpp::roster::RosterQuery;
|
use proto_xmpp::roster::RosterQuery;
|
||||||
use proto_xmpp::session::Session;
|
use proto_xmpp::session::Session;
|
||||||
|
@ -79,7 +79,9 @@ impl<'a> XmppConnection<'a> {
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: IqType::Error,
|
r#type: IqType::Error,
|
||||||
body: (),
|
body: IqError {
|
||||||
|
r#type: IqErrorType::Cancel,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,44 @@ impl MessageType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Error response to an IQ request.
|
||||||
|
///
|
||||||
|
/// https://xmpp.org/rfcs/rfc6120.html#stanzas-error
|
||||||
|
pub struct IqError {
|
||||||
|
pub r#type: IqErrorType,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IqErrorType {
|
||||||
|
/// Retry after providing credentials
|
||||||
|
Auth,
|
||||||
|
/// Do not retry (the error cannot be remedied)
|
||||||
|
Cancel,
|
||||||
|
/// Proceed (the condition was only a warning)
|
||||||
|
Continue,
|
||||||
|
/// Retry after changing the data sent
|
||||||
|
Modify,
|
||||||
|
/// Retry after waiting (the error is temporary)
|
||||||
|
Wait,
|
||||||
|
}
|
||||||
|
impl IqErrorType {
|
||||||
|
pub fn as_str(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
IqErrorType::Auth => "auth",
|
||||||
|
IqErrorType::Cancel => "cancel",
|
||||||
|
IqErrorType::Continue => "continue",
|
||||||
|
IqErrorType::Modify => "modify",
|
||||||
|
IqErrorType::Wait => "wait",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToXml for IqError {
|
||||||
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
|
let bytes = BytesStart::new(format!(r#"error xmlns="{}" type="{}""#, XMLNS, self.r#type.as_str()));
|
||||||
|
events.push(Event::Empty(bytes));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct Iq<T> {
|
pub struct Iq<T> {
|
||||||
pub from: Option<String>,
|
pub from: Option<String>,
|
||||||
|
|
Loading…
Reference in New Issue