forked from lavina/lavina
apply uniform formatting
This commit is contained in:
parent
1d9937319e
commit
878ec33cbb
|
@ -12,7 +12,7 @@ jobs:
|
||||||
uses: https://github.com/actions-rs/cargo@v1
|
uses: https://github.com/actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
command: fmt
|
command: fmt
|
||||||
args: "--check -p mgmt-api -p lavina-core -p projection-irc -p projection-xmpp -p sasl"
|
args: "--check --all"
|
||||||
- name: cargo check
|
- name: cargo check
|
||||||
uses: https://github.com/actions-rs/cargo@v1
|
uses: https://github.com/actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -55,9 +55,7 @@ pub struct PlayerConnection {
|
||||||
}
|
}
|
||||||
impl PlayerConnection {
|
impl PlayerConnection {
|
||||||
pub async fn send_message(&mut self, room_id: RoomId, body: Str) -> Result<()> {
|
pub async fn send_message(&mut self, room_id: RoomId, body: Str) -> Result<()> {
|
||||||
self.player_handle
|
self.player_handle.send_message(room_id, self.connection_id.clone(), body).await
|
||||||
.send_message(room_id, self.connection_id.clone(), body)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn join_room(&mut self, room_id: RoomId) -> Result<JoinResult> {
|
pub async fn join_room(&mut self, room_id: RoomId) -> Result<JoinResult> {
|
||||||
|
@ -71,9 +69,7 @@ impl PlayerConnection {
|
||||||
new_topic,
|
new_topic,
|
||||||
promise,
|
promise,
|
||||||
};
|
};
|
||||||
self.player_handle
|
self.player_handle.send(PlayerCommand::Cmd(cmd, self.connection_id.clone())).await;
|
||||||
.send(PlayerCommand::Cmd(cmd, self.connection_id.clone()))
|
|
||||||
.await;
|
|
||||||
Ok(deferred.await?)
|
Ok(deferred.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,9 +85,7 @@ impl PlayerConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn terminate(self) {
|
pub async fn terminate(self) {
|
||||||
self.player_handle
|
self.player_handle.send(PlayerCommand::TerminateConnection(self.connection_id)).await;
|
||||||
.send(PlayerCommand::TerminateConnection(self.connection_id))
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_rooms(&self) -> Result<Vec<RoomInfo>> {
|
pub async fn get_rooms(&self) -> Result<Vec<RoomInfo>> {
|
||||||
|
|
|
@ -180,9 +180,7 @@ impl Room {
|
||||||
|
|
||||||
async fn send_message(&mut self, author_id: PlayerId, body: Str) -> Result<()> {
|
async fn send_message(&mut self, author_id: PlayerId, body: Str) -> Result<()> {
|
||||||
tracing::info!("Adding a message to room");
|
tracing::info!("Adding a message to room");
|
||||||
self.storage
|
self.storage.insert_message(self.storage_id, self.message_count, &body, &*author_id.as_inner()).await?;
|
||||||
.insert_message(self.storage_id, self.message_count, &body, &*author_id.as_inner())
|
|
||||||
.await?;
|
|
||||||
self.message_count += 1;
|
self.message_count += 1;
|
||||||
let update = Updates::NewMessage {
|
let update = Updates::NewMessage {
|
||||||
room_id: self.room_id.clone(),
|
room_id: self.room_id.clone(),
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
max_width = 120
|
|
||||||
chain_width = 120
|
|
|
@ -1,2 +0,0 @@
|
||||||
max_width = 120
|
|
||||||
chain_width = 120
|
|
|
@ -118,9 +118,7 @@ mod test {
|
||||||
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
||||||
|
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
sync_future(expected.write_async(&mut bytes))
|
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(bytes.as_slice(), input.as_bytes());
|
assert_eq!(bytes.as_slice(), input.as_bytes());
|
||||||
}
|
}
|
||||||
|
@ -134,9 +132,7 @@ mod test {
|
||||||
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
||||||
|
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
sync_future(expected.write_async(&mut bytes))
|
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(bytes.as_slice(), input.as_bytes());
|
assert_eq!(bytes.as_slice(), input.as_bytes());
|
||||||
}
|
}
|
||||||
|
@ -150,9 +146,7 @@ mod test {
|
||||||
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
assert_matches!(result, Ok((_, result)) => assert_eq!(expected, result));
|
||||||
|
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
sync_future(expected.write_async(&mut bytes))
|
sync_future(expected.write_async(&mut bytes)).unwrap().unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(bytes.as_slice(), input.as_bytes());
|
assert_eq!(bytes.as_slice(), input.as_bytes());
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ pub enum ServerMessageBody {
|
||||||
N904SaslFail {
|
N904SaslFail {
|
||||||
nick: Str,
|
nick: Str,
|
||||||
text: Str,
|
text: Str,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerMessageBody {
|
impl ServerMessageBody {
|
||||||
|
@ -273,11 +273,7 @@ impl ServerMessageBody {
|
||||||
writer.write_all(b" :").await?;
|
writer.write_all(b" :").await?;
|
||||||
writer.write_all(msg.as_bytes()).await?;
|
writer.write_all(msg.as_bytes()).await?;
|
||||||
}
|
}
|
||||||
ServerMessageBody::N332Topic {
|
ServerMessageBody::N332Topic { client, chat, topic } => {
|
||||||
client,
|
|
||||||
chat,
|
|
||||||
topic,
|
|
||||||
} => {
|
|
||||||
writer.write_all(b"332 ").await?;
|
writer.write_all(b"332 ").await?;
|
||||||
writer.write_all(client.as_bytes()).await?;
|
writer.write_all(client.as_bytes()).await?;
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
|
@ -315,20 +311,14 @@ impl ServerMessageBody {
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
writer.write_all(realname.as_bytes()).await?;
|
writer.write_all(realname.as_bytes()).await?;
|
||||||
}
|
}
|
||||||
ServerMessageBody::N353NamesReply {
|
ServerMessageBody::N353NamesReply { client, chan, members } => {
|
||||||
client,
|
|
||||||
chan,
|
|
||||||
members,
|
|
||||||
} => {
|
|
||||||
writer.write_all(b"353 ").await?;
|
writer.write_all(b"353 ").await?;
|
||||||
writer.write_all(client.as_bytes()).await?;
|
writer.write_all(client.as_bytes()).await?;
|
||||||
writer.write_all(b" = ").await?;
|
writer.write_all(b" = ").await?;
|
||||||
chan.write_async(writer).await?;
|
chan.write_async(writer).await?;
|
||||||
writer.write_all(b" :").await?;
|
writer.write_all(b" :").await?;
|
||||||
for member in members {
|
for member in members {
|
||||||
writer
|
writer.write_all(member.prefix.to_string().as_bytes()).await?;
|
||||||
.write_all(member.prefix.to_string().as_bytes())
|
|
||||||
.await?;
|
|
||||||
writer.write_all(member.nick.as_bytes()).await?;
|
writer.write_all(member.nick.as_bytes()).await?;
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
}
|
}
|
||||||
|
@ -340,11 +330,7 @@ impl ServerMessageBody {
|
||||||
chan.write_async(writer).await?;
|
chan.write_async(writer).await?;
|
||||||
writer.write_all(b" :End of /NAMES list").await?;
|
writer.write_all(b" :End of /NAMES list").await?;
|
||||||
}
|
}
|
||||||
ServerMessageBody::N474BannedFromChan {
|
ServerMessageBody::N474BannedFromChan { client, chan, message } => {
|
||||||
client,
|
|
||||||
chan,
|
|
||||||
message,
|
|
||||||
} => {
|
|
||||||
writer.write_all(b"474 ").await?;
|
writer.write_all(b"474 ").await?;
|
||||||
writer.write_all(client.as_bytes()).await?;
|
writer.write_all(client.as_bytes()).await?;
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
|
@ -359,7 +345,12 @@ impl ServerMessageBody {
|
||||||
writer.write_all(b" :").await?;
|
writer.write_all(b" :").await?;
|
||||||
writer.write_all(message.as_bytes()).await?;
|
writer.write_all(message.as_bytes()).await?;
|
||||||
}
|
}
|
||||||
ServerMessageBody::N900LoggedIn { nick, address, account, message } => {
|
ServerMessageBody::N900LoggedIn {
|
||||||
|
nick,
|
||||||
|
address,
|
||||||
|
account,
|
||||||
|
message,
|
||||||
|
} => {
|
||||||
writer.write_all(b"900 ").await?;
|
writer.write_all(b"900 ").await?;
|
||||||
writer.write_all(nick.as_bytes()).await?;
|
writer.write_all(nick.as_bytes()).await?;
|
||||||
writer.write_all(b" ").await?;
|
writer.write_all(b" ").await?;
|
||||||
|
@ -404,7 +395,7 @@ fn server_message_body(input: &str) -> IResult<&str, ServerMessageBody> {
|
||||||
server_message_body_notice,
|
server_message_body_notice,
|
||||||
server_message_body_ping,
|
server_message_body_ping,
|
||||||
server_message_body_pong,
|
server_message_body_pong,
|
||||||
server_message_body_cap
|
server_message_body_cap,
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,27 +42,19 @@ impl Display for Jid {
|
||||||
|
|
||||||
impl Jid {
|
impl Jid {
|
||||||
pub fn from_string(i: &str) -> Result<Jid> {
|
pub fn from_string(i: &str) -> Result<Jid> {
|
||||||
use regex::Regex;
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use regex::Regex;
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref RE: Regex = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
|
static ref RE: Regex = Regex::new(r"^(([a-zA-Z]+)@)?([a-zA-Z.]+)(/([a-zA-Z\-]+))?$").unwrap();
|
||||||
}
|
}
|
||||||
let m = RE
|
let m = RE.captures(i).ok_or(anyhow!("Incorrectly format jid: {i}"))?;
|
||||||
.captures(i)
|
|
||||||
.ok_or(anyhow!("Incorrectly format jid: {i}"))?;
|
|
||||||
|
|
||||||
let name = m.get(2).map(|name| Name(name.as_str().into()));
|
let name = m.get(2).map(|name| Name(name.as_str().into()));
|
||||||
let server = m.get(3).unwrap();
|
let server = m.get(3).unwrap();
|
||||||
let server = Server(server.as_str().into());
|
let server = Server(server.as_str().into());
|
||||||
let resource = m
|
let resource = m.get(5).map(|resource| Resource(resource.as_str().into()));
|
||||||
.get(5)
|
|
||||||
.map(|resource| Resource(resource.as_str().into()));
|
|
||||||
|
|
||||||
Ok(Jid {
|
Ok(Jid { name, server, resource })
|
||||||
name,
|
|
||||||
server,
|
|
||||||
resource,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +129,7 @@ pub struct BindResponse(pub Jid);
|
||||||
impl ToXml for BindResponse {
|
impl ToXml for BindResponse {
|
||||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
events.extend_from_slice(&[
|
events.extend_from_slice(&[
|
||||||
Event::Start(BytesStart::new(
|
Event::Start(BytesStart::new(r#"bind xmlns="urn:ietf:params:xml:ns:xmpp-bind""#)),
|
||||||
r#"bind xmlns="urn:ietf:params:xml:ns:xmpp-bind""#,
|
|
||||||
)),
|
|
||||||
Event::Start(BytesStart::new(r#"jid"#)),
|
Event::Start(BytesStart::new(r#"jid"#)),
|
||||||
Event::Text(BytesText::new(self.0.to_string().as_str()).into_owned()),
|
Event::Text(BytesText::new(self.0.to_string().as_str()).into_owned()),
|
||||||
Event::End(BytesEnd::new("jid")),
|
Event::End(BytesEnd::new("jid")),
|
||||||
|
@ -156,23 +146,16 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn parse_message() {
|
async fn parse_message() {
|
||||||
let input =
|
let input = r#"<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>mobile</resource></bind>"#;
|
||||||
r#"<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>mobile</resource></bind>"#;
|
|
||||||
let mut reader = NsReader::from_reader(input.as_bytes());
|
let mut reader = NsReader::from_reader(input.as_bytes());
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
let (ns, event) = reader
|
let (ns, event) = reader.read_resolved_event_into_async(&mut buf).await.unwrap();
|
||||||
.read_resolved_event_into_async(&mut buf)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let mut parser = BindRequest::parse().consume(ns, &event);
|
let mut parser = BindRequest::parse().consume(ns, &event);
|
||||||
let result = loop {
|
let result = loop {
|
||||||
match parser {
|
match parser {
|
||||||
Continuation::Final(res) => break res,
|
Continuation::Final(res) => break res,
|
||||||
Continuation::Continue(next) => {
|
Continuation::Continue(next) => {
|
||||||
let (ns, event) = reader
|
let (ns, event) = reader.read_resolved_event_into_async(&mut buf).await.unwrap();
|
||||||
.read_resolved_event_into_async(&mut buf)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
parser = next.consume(ns, &event);
|
parser = next.consume(ns, &event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ use quick_xml::events::attributes::Attribute;
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, Event};
|
use quick_xml::events::{BytesEnd, BytesStart, Event};
|
||||||
use quick_xml::name::{QName, ResolveResult};
|
use quick_xml::name::{QName, ResolveResult};
|
||||||
|
|
||||||
use anyhow::{Result, anyhow as ffail};
|
|
||||||
use crate::xml::*;
|
use crate::xml::*;
|
||||||
|
use anyhow::{anyhow as ffail, Result};
|
||||||
|
|
||||||
use super::bind::Jid;
|
use super::bind::Jid;
|
||||||
|
|
||||||
|
@ -174,11 +174,7 @@ impl FromXml for Identity {
|
||||||
let Some(r#type) = r#type else {
|
let Some(r#type) = r#type else {
|
||||||
return Err(ffail!("No type provided"));
|
return Err(ffail!("No type provided"));
|
||||||
};
|
};
|
||||||
let item = Identity {
|
let item = Identity { category, name, r#type };
|
||||||
category,
|
|
||||||
name,
|
|
||||||
r#type,
|
|
||||||
};
|
|
||||||
if end {
|
if end {
|
||||||
return Ok(item);
|
return Ok(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
#![feature(
|
#![feature(coroutines, coroutine_trait, type_alias_impl_trait, impl_trait_in_assoc_type)]
|
||||||
coroutines,
|
|
||||||
coroutine_trait,
|
|
||||||
type_alias_impl_trait,
|
|
||||||
impl_trait_in_assoc_type
|
|
||||||
)]
|
|
||||||
|
|
||||||
pub mod bind;
|
pub mod bind;
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod disco;
|
pub mod disco;
|
||||||
pub mod muc;
|
pub mod muc;
|
||||||
|
mod prelude;
|
||||||
pub mod roster;
|
pub mod roster;
|
||||||
pub mod sasl;
|
pub mod sasl;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
pub mod stanzaerror;
|
pub mod stanzaerror;
|
||||||
pub mod stream;
|
pub mod stream;
|
||||||
pub mod tls;
|
pub mod tls;
|
||||||
mod prelude;
|
|
||||||
pub mod xml;
|
pub mod xml;
|
||||||
|
|
||||||
// Implemented as a macro instead of a fn due to borrowck limitations
|
// Implemented as a macro instead of a fn due to borrowck limitations
|
||||||
|
|
|
@ -52,9 +52,6 @@ impl FromXmlTag for RosterQuery {
|
||||||
|
|
||||||
impl ToXml for RosterQuery {
|
impl ToXml for RosterQuery {
|
||||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
events.push(Event::Empty(BytesStart::new(format!(
|
events.push(Event::Empty(BytesStart::new(format!(r#"query xmlns="{}""#, XMLNS))));
|
||||||
r#"query xmlns="{}""#,
|
|
||||||
XMLNS
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,7 @@ impl Parser for SessionParser {
|
||||||
) -> Continuation<Self, Self::Output> {
|
) -> Continuation<Self, Self::Output> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
SessionParserInner::Initial => match event {
|
SessionParserInner::Initial => match event {
|
||||||
Event::Start(_) => {
|
Event::Start(_) => Continuation::Continue(SessionParser(SessionParserInner::InSession)),
|
||||||
Continuation::Continue(SessionParser(SessionParserInner::InSession))
|
|
||||||
}
|
|
||||||
Event::Empty(_) => Continuation::Final(Ok(Session)),
|
Event::Empty(_) => Continuation::Final(Ok(Session)),
|
||||||
_ => Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}"))),
|
_ => Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}"))),
|
||||||
},
|
},
|
||||||
|
@ -54,9 +52,6 @@ impl FromXmlTag for Session {
|
||||||
|
|
||||||
impl ToXml for Session {
|
impl ToXml for Session {
|
||||||
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
fn serialize(&self, events: &mut Vec<Event<'static>>) {
|
||||||
events.push(Event::Empty(BytesStart::new(format!(
|
events.push(Event::Empty(BytesStart::new(format!(r#"session xmlns="{}""#, XMLNS))));
|
||||||
r#"session xmlns="{}""#,
|
|
||||||
XMLNS
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||||
|
|
||||||
use super::skip_text;
|
use super::skip_text;
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
use crate::xml::ToXml;
|
use crate::xml::ToXml;
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub static XMLNS: &'static str = "http://etherx.jabber.org/streams";
|
pub static XMLNS: &'static str = "http://etherx.jabber.org/streams";
|
||||||
pub static PREFIX: &'static str = "stream";
|
pub static PREFIX: &'static str = "stream";
|
||||||
|
@ -44,10 +44,7 @@ impl ClientStreamStart {
|
||||||
let value = attr.unescape_value()?;
|
let value = attr.unescape_value()?;
|
||||||
to = Some(value.to_string());
|
to = Some(value.to_string());
|
||||||
}
|
}
|
||||||
(
|
(ResolveResult::Bound(Namespace(b"http://www.w3.org/XML/1998/namespace")), b"lang") => {
|
||||||
ResolveResult::Bound(Namespace(b"http://www.w3.org/XML/1998/namespace")),
|
|
||||||
b"lang",
|
|
||||||
) => {
|
|
||||||
let value = attr.unescape_value()?;
|
let value = attr.unescape_value()?;
|
||||||
lang = Some(value.to_string());
|
lang = Some(value.to_string());
|
||||||
}
|
}
|
||||||
|
@ -124,21 +121,15 @@ pub struct Features {
|
||||||
}
|
}
|
||||||
impl Features {
|
impl Features {
|
||||||
pub async fn write_xml(&self, writer: &mut Writer<impl AsyncWrite + Unpin>) -> Result<()> {
|
pub async fn write_xml(&self, writer: &mut Writer<impl AsyncWrite + Unpin>) -> Result<()> {
|
||||||
writer
|
writer.write_event_async(Event::Start(BytesStart::new("stream:features"))).await?;
|
||||||
.write_event_async(Event::Start(BytesStart::new("stream:features")))
|
|
||||||
.await?;
|
|
||||||
if self.start_tls {
|
if self.start_tls {
|
||||||
writer
|
writer
|
||||||
.write_event_async(Event::Start(BytesStart::new(
|
.write_event_async(Event::Start(BytesStart::new(
|
||||||
r#"starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls""#,
|
r#"starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls""#,
|
||||||
)))
|
)))
|
||||||
.await?;
|
.await?;
|
||||||
writer
|
writer.write_event_async(Event::Empty(BytesStart::new("required"))).await?;
|
||||||
.write_event_async(Event::Empty(BytesStart::new("required")))
|
writer.write_event_async(Event::End(BytesEnd::new("starttls"))).await?;
|
||||||
.await?;
|
|
||||||
writer
|
|
||||||
.write_event_async(Event::End(BytesEnd::new("starttls")))
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
if self.mechanisms {
|
if self.mechanisms {
|
||||||
writer
|
writer
|
||||||
|
@ -146,18 +137,10 @@ impl Features {
|
||||||
r#"mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl""#,
|
r#"mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl""#,
|
||||||
)))
|
)))
|
||||||
.await?;
|
.await?;
|
||||||
writer
|
writer.write_event_async(Event::Start(BytesStart::new(r#"mechanism"#))).await?;
|
||||||
.write_event_async(Event::Start(BytesStart::new(r#"mechanism"#)))
|
writer.write_event_async(Event::Text(BytesText::new("PLAIN"))).await?;
|
||||||
.await?;
|
writer.write_event_async(Event::End(BytesEnd::new("mechanism"))).await?;
|
||||||
writer
|
writer.write_event_async(Event::End(BytesEnd::new("mechanisms"))).await?;
|
||||||
.write_event_async(Event::Text(BytesText::new("PLAIN")))
|
|
||||||
.await?;
|
|
||||||
writer
|
|
||||||
.write_event_async(Event::End(BytesEnd::new("mechanism")))
|
|
||||||
.await?;
|
|
||||||
writer
|
|
||||||
.write_event_async(Event::End(BytesEnd::new("mechanisms")))
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
if self.bind {
|
if self.bind {
|
||||||
writer
|
writer
|
||||||
|
@ -166,9 +149,7 @@ impl Features {
|
||||||
)))
|
)))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
writer
|
writer.write_event_async(Event::End(BytesEnd::new("stream:features"))).await?;
|
||||||
.write_event_async(Event::End(BytesEnd::new("stream:features")))
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,9 +163,7 @@ mod test {
|
||||||
let input = r###"<stream:stream xmlns:stream="http://etherx.jabber.org/streams" to="vlnv.dev" version="1.0" xmlns="jabber:client" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">"###;
|
let input = r###"<stream:stream xmlns:stream="http://etherx.jabber.org/streams" to="vlnv.dev" version="1.0" xmlns="jabber:client" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">"###;
|
||||||
let mut reader = NsReader::from_reader(input.as_bytes());
|
let mut reader = NsReader::from_reader(input.as_bytes());
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
let res = ClientStreamStart::parse(&mut reader, &mut buf)
|
let res = ClientStreamStart::parse(&mut reader, &mut buf).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
ClientStreamStart {
|
ClientStreamStart {
|
||||||
|
|
|
@ -12,10 +12,7 @@ pub static XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls";
|
||||||
|
|
||||||
pub struct StartTLS;
|
pub struct StartTLS;
|
||||||
impl StartTLS {
|
impl StartTLS {
|
||||||
pub async fn parse(
|
pub async fn parse(reader: &mut NsReader<impl AsyncBufRead + Unpin>, buf: &mut Vec<u8>) -> Result<StartTLS> {
|
||||||
reader: &mut NsReader<impl AsyncBufRead + Unpin>,
|
|
||||||
buf: &mut Vec<u8>,
|
|
||||||
) -> Result<StartTLS> {
|
|
||||||
let incoming = skip_text!(reader, buf);
|
let incoming = skip_text!(reader, buf);
|
||||||
if let Event::Empty(ref e) = incoming {
|
if let Event::Empty(ref e) = incoming {
|
||||||
if e.name().0 == b"starttls" {
|
if e.name().0 == b"starttls" {
|
||||||
|
|
|
@ -15,11 +15,7 @@ enum IgnoreParserInner {
|
||||||
impl Parser for IgnoreParser {
|
impl Parser for IgnoreParser {
|
||||||
type Output = Result<Ignore>;
|
type Output = Result<Ignore>;
|
||||||
|
|
||||||
fn consume<'a>(
|
fn consume<'a>(self: Self, _: ResolveResult, event: &Event<'a>) -> Continuation<Self, Self::Output> {
|
||||||
self: Self,
|
|
||||||
_: ResolveResult,
|
|
||||||
event: &Event<'a>,
|
|
||||||
) -> Continuation<Self, Self::Output> {
|
|
||||||
match self.0 {
|
match self.0 {
|
||||||
IgnoreParserInner::Initial => match event {
|
IgnoreParserInner::Initial => match event {
|
||||||
Event::Start(bytes) => {
|
Event::Start(bytes) => {
|
||||||
|
@ -34,13 +30,7 @@ impl Parser for IgnoreParser {
|
||||||
if depth == 0 {
|
if depth == 0 {
|
||||||
Continuation::Final(Ok(Ignore))
|
Continuation::Final(Ok(Ignore))
|
||||||
} else {
|
} else {
|
||||||
Continuation::Continue(
|
Continuation::Continue(IgnoreParserInner::InTag { name, depth: depth - 1 }.into())
|
||||||
IgnoreParserInner::InTag {
|
|
||||||
name,
|
|
||||||
depth: depth - 1,
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Continuation::Continue(IgnoreParserInner::InTag { name, depth }.into()),
|
_ => Continuation::Continue(IgnoreParserInner::InTag { name, depth }.into()),
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use std::ops::Coroutine;
|
use std::ops::Coroutine;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use quick_xml::NsReader;
|
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use quick_xml::name::ResolveResult;
|
use quick_xml::name::ResolveResult;
|
||||||
|
use quick_xml::NsReader;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
|
@ -28,25 +28,16 @@ pub trait FromXmlTag: FromXml {
|
||||||
pub trait Parser: Sized {
|
pub trait Parser: Sized {
|
||||||
type Output;
|
type Output;
|
||||||
|
|
||||||
fn consume<'a>(
|
fn consume<'a>(self: Self, namespace: ResolveResult, event: &Event<'a>) -> Continuation<Self, Self::Output>;
|
||||||
self: Self,
|
|
||||||
namespace: ResolveResult,
|
|
||||||
event: &Event<'a>,
|
|
||||||
) -> Continuation<Self, Self::Output>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, Out> Parser for T
|
impl<T, Out> Parser for T
|
||||||
where
|
where
|
||||||
T: Coroutine<(ResolveResult<'static>, &'static Event<'static>), Yield = (), Return = Out>
|
T: Coroutine<(ResolveResult<'static>, &'static Event<'static>), Yield = (), Return = Out> + Unpin,
|
||||||
+ Unpin,
|
|
||||||
{
|
{
|
||||||
type Output = Out;
|
type Output = Out;
|
||||||
|
|
||||||
fn consume<'a>(
|
fn consume<'a>(mut self: Self, namespace: ResolveResult, event: &Event<'a>) -> Continuation<Self, Self::Output> {
|
||||||
mut self: Self,
|
|
||||||
namespace: ResolveResult,
|
|
||||||
event: &Event<'a>,
|
|
||||||
) -> Continuation<Self, Self::Output> {
|
|
||||||
let s = Pin::new(&mut self);
|
let s = Pin::new(&mut self);
|
||||||
// this is a very rude workaround fixing the fact that rust coroutines
|
// this is a very rude workaround fixing the fact that rust coroutines
|
||||||
// 1. don't support higher-kinded lifetimes (i.e. no `impl for <'a> Coroutine<Event<'a>>)
|
// 1. don't support higher-kinded lifetimes (i.e. no `impl for <'a> Coroutine<Event<'a>>)
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
max_width = 120
|
max_width = 120
|
||||||
|
chain_width = 120
|
||||||
|
|
|
@ -62,7 +62,14 @@ async fn main() -> Result<()> {
|
||||||
storage.clone(),
|
storage.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let xmpp = projection_xmpp::launch(xmpp_config, players.clone(), rooms.clone(), metrics.clone(), storage.clone()).await?;
|
let xmpp = projection_xmpp::launch(
|
||||||
|
xmpp_config,
|
||||||
|
players.clone(),
|
||||||
|
rooms.clone(),
|
||||||
|
metrics.clone(),
|
||||||
|
storage.clone(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
tracing::info!("Started");
|
tracing::info!("Started");
|
||||||
|
|
||||||
sleep.await;
|
sleep.await;
|
||||||
|
|
Loading…
Reference in New Issue