mirror of https://gitlab.com/xmpp-rs/xmpp-rs.git
Merge branch 'feature/ignore-missing-disco-info' into 'main'
Ignore missing disco#info feature in disco#info responses See merge request xmpp-rs/xmpp-rs!302
This commit is contained in:
commit
8a7a03f7a7
|
@ -161,13 +161,6 @@ impl TryFrom<Element> for DiscoInfoResult {
|
|||
"There must be at least one feature in disco#info.",
|
||||
));
|
||||
}
|
||||
if !result.features.contains(&Feature {
|
||||
var: ns::DISCO_INFO.to_owned(),
|
||||
}) {
|
||||
return Err(Error::ParseError(
|
||||
"disco#info feature not present in disco#info.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
@ -400,14 +393,6 @@ mod tests {
|
|||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "There must be at least one feature in disco#info.");
|
||||
|
||||
let elem: Element = "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc'/><feature var='http://jabber.org/protocol/disco#items'/></query>".parse().unwrap();
|
||||
let error = DiscoInfoResult::try_from(elem).unwrap_err();
|
||||
let message = match error {
|
||||
Error::ParseError(string) => string,
|
||||
_ => panic!(),
|
||||
};
|
||||
assert_eq!(message, "disco#info feature not present in disco#info.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -8,58 +8,17 @@ use tokio_xmpp::connect::ServerConnector;
|
|||
use tokio_xmpp::{
|
||||
parsers::{
|
||||
bookmarks,
|
||||
disco::{DiscoInfoResult, Feature},
|
||||
disco::DiscoInfoResult,
|
||||
iq::Iq,
|
||||
ns,
|
||||
private::Query as PrivateXMLQuery,
|
||||
pubsub::pubsub::{Items, PubSub},
|
||||
Error as ParsersError,
|
||||
},
|
||||
Element, Jid,
|
||||
Jid,
|
||||
};
|
||||
|
||||
use crate::Agent;
|
||||
|
||||
// This method is a workaround due to prosody bug https://issues.prosody.im/1664
|
||||
// FIXME: To be removed in the future
|
||||
// The server doesn't return disco#info feature when querying the account
|
||||
// so we add it manually because we know it's true
|
||||
pub async fn handle_disco_info_result_payload<C: ServerConnector>(
|
||||
agent: &mut Agent<C>,
|
||||
payload: Element,
|
||||
from: Jid,
|
||||
) {
|
||||
match DiscoInfoResult::try_from(payload.clone()) {
|
||||
Ok(disco) => {
|
||||
handle_disco_info_result(agent, disco, from).await;
|
||||
}
|
||||
Err(e) => match e {
|
||||
ParsersError::ParseError(reason) => {
|
||||
if reason == "disco#info feature not present in disco#info." {
|
||||
let mut payload = payload.clone();
|
||||
let disco_feature =
|
||||
Feature::new("http://jabber.org/protocol/disco#info").into();
|
||||
payload.append_child(disco_feature);
|
||||
match DiscoInfoResult::try_from(payload) {
|
||||
Ok(disco) => {
|
||||
handle_disco_info_result(agent, disco, from).await;
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("Wrong disco#info format after workaround: {}", e)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
panic!(
|
||||
"Wrong disco#info format (reason cannot be worked around): {}",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => panic!("Wrong disco#info format: {}", e),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_disco_info_result<C: ServerConnector>(
|
||||
agent: &mut Agent<C>,
|
||||
disco: DiscoInfoResult,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use tokio_xmpp::connect::ServerConnector;
|
||||
use tokio_xmpp::{
|
||||
parsers::{ns, private::Query as PrivateXMLQuery, roster::Roster},
|
||||
parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster},
|
||||
Element, Jid,
|
||||
};
|
||||
|
||||
|
@ -46,6 +46,13 @@ pub async fn handle_iq_result<C: ServerConnector>(
|
|||
}
|
||||
}
|
||||
} else if payload.is("query", ns::DISCO_INFO) {
|
||||
disco::handle_disco_info_result_payload(agent, payload, from).await;
|
||||
match DiscoInfoResult::try_from(payload.clone()) {
|
||||
Ok(disco) => {
|
||||
disco::handle_disco_info_result(agent, disco, from).await;
|
||||
}
|
||||
Err(e) => match e {
|
||||
_ => panic!("Wrong disco#info format: {}", e),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue