xmpp: update to edition 2024
Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
4a054ae802
commit
e503f016a3
19 changed files with 40 additions and 29 deletions
|
|
@ -11,7 +11,7 @@ repository = "https://gitlab.com/xmpp-rs/xmpp-rs"
|
||||||
keywords = ["xmpp", "jabber", "chat", "messaging", "bot"]
|
keywords = ["xmpp", "jabber", "chat", "messaging", "bot"]
|
||||||
categories = ["network-programming"]
|
categories = ["network-programming"]
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2021"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ XXXX-YY-ZZ [ RELEASER <admin@localhost> ]
|
||||||
is meant to stay behind a feature. Also allows directly receiving
|
is meant to stay behind a feature. Also allows directly receiving
|
||||||
stanzas.
|
stanzas.
|
||||||
- Added documentation on `Event` enum.
|
- Added documentation on `Event` enum.
|
||||||
|
- Update to edition 2024
|
||||||
* Fixes:
|
* Fixes:
|
||||||
- Use tokio::sync::RwLock not std::sync::RwLock (!432)
|
- Use tokio::sync::RwLock not std::sync::RwLock (!432)
|
||||||
- The default caps node has been shortened to https://xmpp.rs since we
|
- The default caps node has been shortened to https://xmpp.rs since we
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#[cfg(feature = "rustls-any-backend")]
|
#[cfg(feature = "rustls-any-backend")]
|
||||||
use xmpp::tokio_xmpp::rustls;
|
use xmpp::tokio_xmpp::rustls;
|
||||||
use xmpp::{
|
use xmpp::{
|
||||||
|
Agent, ClientBuilder, ClientFeature, ClientType, Event, RoomNick,
|
||||||
jid::BareJid,
|
jid::BareJid,
|
||||||
muc::room::{JoinRoomSettings, RoomMessageSettings},
|
muc::room::{JoinRoomSettings, RoomMessageSettings},
|
||||||
Agent, ClientBuilder, ClientFeature, ClientType, Event, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::signal::ctrl_c;
|
use tokio::signal::ctrl_c;
|
||||||
|
|
@ -21,7 +21,9 @@ use std::str::FromStr;
|
||||||
feature = "rustls-any-backend",
|
feature = "rustls-any-backend",
|
||||||
not(any(feature = "aws_lc_rs", feature = "ring"))
|
not(any(feature = "aws_lc_rs", feature = "ring"))
|
||||||
))]
|
))]
|
||||||
compile_error!("using rustls (e.g. via the ktls feature) needs an enabled rustls backend feature (either aws_lc_rs or ring).");
|
compile_error!(
|
||||||
|
"using rustls (e.g. via the ktls feature) needs an enabled rustls backend feature (either aws_lc_rs or ring)."
|
||||||
|
);
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Option<()>> {
|
async fn main() -> Result<(), Option<()>> {
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,15 @@ use tokio::io;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event_loop,
|
Error, Event, RoomNick, event_loop,
|
||||||
jid::{BareJid, Jid},
|
jid::{BareJid, Jid},
|
||||||
message, muc,
|
message, muc,
|
||||||
parsers::disco::DiscoInfoResult,
|
parsers::disco::DiscoInfoResult,
|
||||||
upload, Error, Event, RoomNick,
|
upload,
|
||||||
};
|
};
|
||||||
use tokio_xmpp::Client as TokioXmppClient;
|
use tokio_xmpp::Client as TokioXmppClient;
|
||||||
#[cfg(feature = "escape-hatch")]
|
#[cfg(feature = "escape-hatch")]
|
||||||
use tokio_xmpp::{stanzastream::StanzaToken, Stanza};
|
use tokio_xmpp::{Stanza, stanzastream::StanzaToken};
|
||||||
|
|
||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
pub(crate) client: TokioXmppClient,
|
pub(crate) client: TokioXmppClient,
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,13 @@ use crate::tokio_xmpp::connect::{DnsConfig, StartTlsServerConnector};
|
||||||
use core::str::FromStr;
|
use core::str::FromStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Agent, ClientFeature, RoomNick,
|
||||||
jid::{BareJid, Jid, ResourceRef},
|
jid::{BareJid, Jid, ResourceRef},
|
||||||
parsers::{
|
parsers::{
|
||||||
disco::{DiscoInfoResult, Feature, Identity},
|
disco::{DiscoInfoResult, Feature, Identity},
|
||||||
ns,
|
ns,
|
||||||
},
|
},
|
||||||
tokio_xmpp::{connect::ServerConnector, xmlstream::Timeouts, Client as TokioXmppClient},
|
tokio_xmpp::{Client as TokioXmppClient, connect::ServerConnector, xmlstream::Timeouts},
|
||||||
Agent, ClientFeature, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
||||||
|
|
@ -49,10 +49,10 @@ pub fn message_time_info(message: &Message) -> StanzaTimeInfo {
|
||||||
match Delay::try_from(payload.clone()) {
|
match Delay::try_from(payload.clone()) {
|
||||||
Ok(delay) => delays.push(delay),
|
Ok(delay) => delays.push(delay),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Wrong <delay> format in payload from {}:{}\n{:?}\nUsing received time only.",
|
error!(
|
||||||
message.from.as_ref().unwrap().to_owned(),
|
"Wrong <delay> format in payload from {}:{e}\n{payload:?}\nUsing received time only.",
|
||||||
e,
|
message.from.as_ref().unwrap().to_owned()
|
||||||
payload);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use tokio_xmpp::parsers::roster::Item as RosterItem;
|
||||||
use tokio_xmpp::parsers::{iq::Iq, message::Message, presence::Presence};
|
use tokio_xmpp::parsers::{iq::Iq, message::Message, presence::Presence};
|
||||||
|
|
||||||
use crate::parsers::confirm::Confirm;
|
use crate::parsers::confirm::Confirm;
|
||||||
use crate::{delay::StanzaTimeInfo, Error, MessageId, RoomNick};
|
use crate::{Error, MessageId, RoomNick, delay::StanzaTimeInfo};
|
||||||
|
|
||||||
/// An Event notifying the client something has happened that may require attention.
|
/// An Event notifying the client something has happened that may require attention.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
|
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use tokio_xmpp::{
|
use tokio_xmpp::{
|
||||||
parsers::{disco::DiscoInfoQuery, iq::Iq, roster::Roster},
|
|
||||||
Event as TokioXmppEvent, Stanza,
|
Event as TokioXmppEvent, Stanza,
|
||||||
|
parsers::{disco::DiscoInfoQuery, iq::Iq, roster::Roster},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{iq, message, presence, Agent, Event};
|
use crate::{Agent, Event, iq, message, presence};
|
||||||
|
|
||||||
/// Wait for new events, or Error::Disconnected when stream is closed and will not reconnect.
|
/// Wait for new events, or Error::Disconnected when stream is closed and will not reconnect.
|
||||||
pub async fn wait_for_events(agent: &mut Agent) -> Vec<Event> {
|
pub async fn wait_for_events(agent: &mut Agent) -> Vec<Event> {
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
disco,
|
Agent, Event, RoomNick, disco,
|
||||||
jid::Jid,
|
jid::Jid,
|
||||||
minidom::Element,
|
minidom::Element,
|
||||||
muc::room::JoinRoomSettings,
|
muc::room::JoinRoomSettings,
|
||||||
parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster},
|
parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster},
|
||||||
pubsub, upload, Agent, Event, RoomNick,
|
pubsub, upload,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn handle_iq_result(
|
pub async fn handle_iq_result(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use tokio_xmpp::{
|
||||||
parsers::{confirm::Confirm, message::Message, message_correct::Replace, muc::user::MucUser},
|
parsers::{confirm::Confirm, message::Message, message_correct::Replace, muc::user::MucUser},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{delay::StanzaTimeInfo, Agent, Event, RoomNick};
|
use crate::{Agent, Event, RoomNick, delay::StanzaTimeInfo};
|
||||||
|
|
||||||
pub async fn handle_message_chat(
|
pub async fn handle_message_chat(
|
||||||
agent: &mut Agent,
|
agent: &mut Agent,
|
||||||
|
|
@ -43,7 +43,9 @@ pub async fn handle_message_chat(
|
||||||
|
|
||||||
if is_muc_pm {
|
if is_muc_pm {
|
||||||
if from.resource().is_none() {
|
if from.resource().is_none() {
|
||||||
warn!("Received malformed MessageType::Chat in muc#user namespace from a bare JID:\n{:#?}", message);
|
warn!(
|
||||||
|
"Received malformed MessageType::Chat in muc#user namespace from a bare JID:\n{message:#?}"
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
let full_from = from.clone().try_into_full().unwrap();
|
let full_from = from.clone().try_into_full().unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Agent, Event, RoomNick,
|
||||||
delay::StanzaTimeInfo,
|
delay::StanzaTimeInfo,
|
||||||
jid::Jid,
|
jid::Jid,
|
||||||
parsers::{message::Message, message_correct::Replace},
|
parsers::{message::Message, message_correct::Replace},
|
||||||
Agent, Event, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn handle_message_group_chat(
|
pub async fn handle_message_group_chat(
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ use tokio_xmpp::parsers::{
|
||||||
ns,
|
ns,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{delay::message_time_info, pubsub, Agent, Event};
|
use crate::{Agent, Event, delay::message_time_info, pubsub};
|
||||||
|
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
pub mod group_chat;
|
pub mod group_chat;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Agent, RoomNick,
|
||||||
jid::{BareJid, Jid},
|
jid::{BareJid, Jid},
|
||||||
message::send::RawMessageSettings,
|
message::send::RawMessageSettings,
|
||||||
parsers::{message::MessageType, muc::user::MucUser},
|
parsers::{message::MessageType, muc::user::MucUser},
|
||||||
Agent, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Agent, RoomNick,
|
||||||
jid::{BareJid, ResourceRef},
|
jid::{BareJid, ResourceRef},
|
||||||
message::send::RawMessageSettings,
|
message::send::RawMessageSettings,
|
||||||
parsers::{
|
parsers::{
|
||||||
|
|
@ -12,7 +13,6 @@ use crate::{
|
||||||
muc::Muc,
|
muc::Muc,
|
||||||
presence::{Presence, Type as PresenceType},
|
presence::{Presence, Type as PresenceType},
|
||||||
},
|
},
|
||||||
Agent, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,10 @@ pub async fn handle_presence(agent: &mut Agent, presence: Presence) -> Vec<Event
|
||||||
agent.rooms_joined.insert(from.clone(), nick.clone());
|
agent.rooms_joined.insert(from.clone(), nick.clone());
|
||||||
agent.rooms_joining.remove(&from);
|
agent.rooms_joining.remove(&from);
|
||||||
} else {
|
} else {
|
||||||
warn!("Received self-presence from {} while the room was not marked as joining.", presence.from.unwrap());
|
warn!(
|
||||||
|
"Received self-presence from {} while the room was not marked as joining.",
|
||||||
|
presence.from.unwrap()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
events.push(Event::RoomJoined(from.clone()));
|
events.push(Event::RoomJoined(from.clone()));
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +51,10 @@ pub async fn handle_presence(agent: &mut Agent, presence: Presence) -> Vec<Event
|
||||||
agent.rooms_joined.remove(&from);
|
agent.rooms_joined.remove(&from);
|
||||||
agent.rooms_leaving.remove(&from);
|
agent.rooms_leaving.remove(&from);
|
||||||
} else {
|
} else {
|
||||||
warn!("Received self-presence unavailable from {} while the room was not marked as leaving.", presence.from.unwrap());
|
warn!(
|
||||||
|
"Received self-presence unavailable from {} while the room was not marked as leaving.",
|
||||||
|
presence.from.unwrap()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
events.push(Event::RoomLeft(from.clone()));
|
events.push(Event::RoomLeft(from.clone()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use tokio_xmpp::parsers::{
|
use tokio_xmpp::parsers::{
|
||||||
caps::{compute_disco, hash_caps, Caps},
|
caps::{Caps, compute_disco, hash_caps},
|
||||||
disco::DiscoInfoResult,
|
disco::DiscoInfoResult,
|
||||||
hashes::Algo,
|
hashes::Algo,
|
||||||
presence::{Presence, Type as PresenceType},
|
presence::{Presence, Type as PresenceType},
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,9 @@ use tokio_xmpp::parsers::{
|
||||||
jid::Jid,
|
jid::Jid,
|
||||||
ns,
|
ns,
|
||||||
pubsub::{
|
pubsub::{
|
||||||
|
NodeName,
|
||||||
event::Item,
|
event::Item,
|
||||||
pubsub::{Items, PubSub},
|
pubsub::{Items, PubSub},
|
||||||
NodeName,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
Agent, Event, RoomNick,
|
||||||
jid::{BareJid, Jid},
|
jid::{BareJid, Jid},
|
||||||
minidom::Element,
|
minidom::Element,
|
||||||
muc::room::{JoinRoomSettings, LeaveRoomSettings},
|
muc::room::{JoinRoomSettings, LeaveRoomSettings},
|
||||||
|
|
@ -12,7 +13,6 @@ use crate::{
|
||||||
bookmarks2, ns,
|
bookmarks2, ns,
|
||||||
pubsub::{self, pubsub::PubSub},
|
pubsub::{self, pubsub::PubSub},
|
||||||
},
|
},
|
||||||
Agent, Event, RoomNick,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
header::HeaderMap as ReqwestHeaderMap, Body as ReqwestBody, Client as ReqwestClient,
|
Body as ReqwestBody, Client as ReqwestClient, header::HeaderMap as ReqwestHeaderMap,
|
||||||
};
|
};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tokio::fs::File;
|
use tokio::fs::File;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue