mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-06-01 22:09:20 +02:00
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.",
|
"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)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
@ -400,14 +393,6 @@ mod tests {
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
assert_eq!(message, "There must be at least one feature in disco#info.");
|
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]
|
#[test]
|
||||||
|
|
|
@ -8,58 +8,17 @@ use tokio_xmpp::connect::ServerConnector;
|
||||||
use tokio_xmpp::{
|
use tokio_xmpp::{
|
||||||
parsers::{
|
parsers::{
|
||||||
bookmarks,
|
bookmarks,
|
||||||
disco::{DiscoInfoResult, Feature},
|
disco::DiscoInfoResult,
|
||||||
iq::Iq,
|
iq::Iq,
|
||||||
ns,
|
ns,
|
||||||
private::Query as PrivateXMLQuery,
|
private::Query as PrivateXMLQuery,
|
||||||
pubsub::pubsub::{Items, PubSub},
|
pubsub::pubsub::{Items, PubSub},
|
||||||
Error as ParsersError,
|
|
||||||
},
|
},
|
||||||
Element, Jid,
|
Jid,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Agent;
|
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>(
|
pub async fn handle_disco_info_result<C: ServerConnector>(
|
||||||
agent: &mut Agent<C>,
|
agent: &mut Agent<C>,
|
||||||
disco: DiscoInfoResult,
|
disco: DiscoInfoResult,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
use tokio_xmpp::connect::ServerConnector;
|
use tokio_xmpp::connect::ServerConnector;
|
||||||
use tokio_xmpp::{
|
use tokio_xmpp::{
|
||||||
parsers::{ns, private::Query as PrivateXMLQuery, roster::Roster},
|
parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster},
|
||||||
Element, Jid,
|
Element, Jid,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,6 +46,13 @@ pub async fn handle_iq_result<C: ServerConnector>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if payload.is("query", ns::DISCO_INFO) {
|
} 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
Block a user