forked from lavina/lavina
split proto xmpp defs into its own crate
This commit is contained in:
parent
ad49703714
commit
4c9ab1676e
|
@ -759,11 +759,10 @@ dependencies = [
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper 1.0.0-rc.3",
|
"hyper 1.0.0-rc.3",
|
||||||
"lazy_static",
|
|
||||||
"nom",
|
|
||||||
"nonempty",
|
"nonempty",
|
||||||
"prometheus",
|
"prometheus",
|
||||||
"proto-irc",
|
"proto-irc",
|
||||||
|
"proto-xmpp",
|
||||||
"quick-xml",
|
"quick-xml",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
@ -1164,6 +1163,18 @@ dependencies = [
|
||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proto-xmpp"
|
||||||
|
version = "0.0.1-dev"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"derive_more",
|
||||||
|
"lazy_static",
|
||||||
|
"quick-xml",
|
||||||
|
"regex",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quick-xml"
|
name = "quick-xml"
|
||||||
version = "0.30.0"
|
version = "0.30.0"
|
||||||
|
|
15
Cargo.toml
15
Cargo.toml
|
@ -1,7 +1,8 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
".",
|
".",
|
||||||
"crates/proto-irc"
|
"crates/proto-irc",
|
||||||
|
"crates/proto-xmpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
@ -14,6 +15,10 @@ tokio = { version = "1.24.1", features = ["full"] } # async runtime
|
||||||
futures-util = "0.3.25"
|
futures-util = "0.3.25"
|
||||||
anyhow = "1.0.68" # error utils
|
anyhow = "1.0.68" # error utils
|
||||||
nonempty = "0.8.1"
|
nonempty = "0.8.1"
|
||||||
|
quick-xml = { version = "0.30.0", features = ["async-tokio"] }
|
||||||
|
lazy_static = "1.4.0"
|
||||||
|
regex = "1.7.1"
|
||||||
|
derive_more = "0.99.17"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "lavina"
|
name = "lavina"
|
||||||
|
@ -33,17 +38,15 @@ tracing = "0.1.37" # logging & tracing api
|
||||||
tracing-subscriber = "0.3.16"
|
tracing-subscriber = "0.3.16"
|
||||||
futures-util.workspace = true
|
futures-util.workspace = true
|
||||||
prometheus = { version = "0.13.3", default-features = false }
|
prometheus = { version = "0.13.3", default-features = false }
|
||||||
regex = "1.7.1"
|
|
||||||
lazy_static = "1.4.0"
|
|
||||||
nom.workspace = true
|
|
||||||
nonempty.workspace = true
|
nonempty.workspace = true
|
||||||
tokio-rustls = "0.24.1"
|
tokio-rustls = "0.24.1"
|
||||||
rustls-pemfile = "1.0.2"
|
rustls-pemfile = "1.0.2"
|
||||||
quick-xml = { version = "0.30.0", features = ["async-tokio"] }
|
quick-xml.workspace = true
|
||||||
derive_more = "0.99.17"
|
derive_more.workspace = true
|
||||||
uuid = { version = "1.3.0", features = ["v4"] }
|
uuid = { version = "1.3.0", features = ["v4"] }
|
||||||
sqlx = { version = "0.7.0-alpha.2", features = ["sqlite", "migrate"] }
|
sqlx = { version = "0.7.0-alpha.2", features = ["sqlite", "migrate"] }
|
||||||
proto-irc = { path = "crates/proto-irc" }
|
proto-irc = { path = "crates/proto-irc" }
|
||||||
|
proto-xmpp = { path = "crates/proto-xmpp" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
assert_matches.workspace = true
|
assert_matches.workspace = true
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "proto-xmpp"
|
||||||
|
edition = "2021"
|
||||||
|
version.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
quick-xml.workspace = true
|
||||||
|
lazy_static.workspace = true
|
||||||
|
regex.workspace = true
|
||||||
|
anyhow.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
derive_more.workspace = true
|
|
@ -1,11 +1,11 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use nom::AsBytes;
|
use anyhow::{anyhow, Result};
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||||
use quick_xml::name::{Namespace, ResolveResult};
|
use quick_xml::name::{Namespace, ResolveResult};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::util::xml::*;
|
use crate::xml::*;
|
||||||
|
|
||||||
pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-bind";
|
pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-bind";
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ impl Jid {
|
||||||
}
|
}
|
||||||
let m = RE
|
let m = RE
|
||||||
.captures(i)
|
.captures(i)
|
||||||
.ok_or(ffail!("Incorrectly format jid: {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();
|
||||||
|
@ -117,19 +117,19 @@ impl Parser for BindRequestParser {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
Initial => {
|
Initial => {
|
||||||
let Event::Start(bytes) = event else {
|
let Event::Start(bytes) = event else {
|
||||||
return Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}")));
|
return Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}")));
|
||||||
};
|
};
|
||||||
if bytes.name().0 != BindRequest::NAME.as_bytes() {
|
if bytes.name().0 != BindRequest::NAME.as_bytes() {
|
||||||
return Continuation::Final(Err(ffail!(
|
return Continuation::Final(Err(anyhow!(
|
||||||
"Unexpected XML tag: {:?}",
|
"Unexpected XML tag: {:?}",
|
||||||
bytes.name()
|
bytes.name()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let ResolveResult::Bound(Namespace(ns)) = namespace else {
|
let ResolveResult::Bound(Namespace(ns)) = namespace else {
|
||||||
return Continuation::Final(Err(ffail!("No namespace provided")));
|
return Continuation::Final(Err(anyhow!("No namespace provided")));
|
||||||
};
|
};
|
||||||
if ns != XMLNS.as_bytes() {
|
if ns != XMLNS.as_bytes() {
|
||||||
return Continuation::Final(Err(ffail!("Incorrect namespace")));
|
return Continuation::Final(Err(anyhow!("Incorrect namespace")));
|
||||||
}
|
}
|
||||||
Continuation::Continue(BindRequestParser(InBind(None)))
|
Continuation::Continue(BindRequestParser(InBind(None)))
|
||||||
}
|
}
|
||||||
|
@ -139,17 +139,17 @@ impl Parser for BindRequestParser {
|
||||||
}
|
}
|
||||||
Event::End(bytes) => {
|
Event::End(bytes) => {
|
||||||
let Some(resource) = resource else {
|
let Some(resource) = resource else {
|
||||||
return Continuation::Final(Err(ffail!("No resource was provided")));
|
return Continuation::Final(Err(anyhow!("No resource was provided")));
|
||||||
};
|
};
|
||||||
Continuation::Final(Ok(BindRequest(Resource(resource.into()))))
|
Continuation::Final(Ok(BindRequest(Resource(resource.into()))))
|
||||||
}
|
}
|
||||||
_ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))),
|
_ => Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}"))),
|
||||||
},
|
},
|
||||||
InBindResourceInitial => {
|
InBindResourceInitial => {
|
||||||
let Event::Text(text) = event else {
|
let Event::Text(text) = event else {
|
||||||
return Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}")));
|
return Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}")));
|
||||||
};
|
};
|
||||||
let resource = match std::str::from_utf8(text.as_bytes()) {
|
let resource = match std::str::from_utf8(&*text) {
|
||||||
Ok(e) => e.to_string(),
|
Ok(e) => e.to_string(),
|
||||||
Err(err) => return Continuation::Final(Err(err.into())),
|
Err(err) => return Continuation::Final(Err(err.into())),
|
||||||
};
|
};
|
||||||
|
@ -157,7 +157,7 @@ impl Parser for BindRequestParser {
|
||||||
}
|
}
|
||||||
InBindResourceEnd(resource) => {
|
InBindResourceEnd(resource) => {
|
||||||
let Event::End(bytes) = event else {
|
let Event::End(bytes) = event else {
|
||||||
return Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}")));
|
return Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}")));
|
||||||
};
|
};
|
||||||
Continuation::Continue(BindRequestParser(InBind(Some(resource))))
|
Continuation::Continue(BindRequestParser(InBind(Some(resource))))
|
||||||
}
|
}
|
|
@ -3,8 +3,11 @@ use quick_xml::events::attributes::Attribute;
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||||
use quick_xml::name::{QName, ResolveResult};
|
use quick_xml::name::{QName, ResolveResult};
|
||||||
|
|
||||||
|
use anyhow::{Result, anyhow as ffail};
|
||||||
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::util::xml::*;
|
use crate::xml::*;
|
||||||
|
|
||||||
use super::bind::Jid;
|
use super::bind::Jid;
|
||||||
|
|
||||||
|
@ -308,9 +311,9 @@ impl<T: FromXml> Parser for IqParser<T> {
|
||||||
}
|
}
|
||||||
IqParserInner::Final(state) => {
|
IqParserInner::Final(state) => {
|
||||||
if let Event::End(ref bytes) = event {
|
if let Event::End(ref bytes) = event {
|
||||||
let id = fail_fast!(state.id.ok_or_else(|| fail("No id provided")));
|
let id = fail_fast!(state.id.ok_or_else(|| ffail!("No id provided")));
|
||||||
let r#type = fail_fast!(state.r#type.ok_or_else(|| fail("No type provided")));
|
let r#type = fail_fast!(state.r#type.ok_or_else(|| ffail!("No type provided")));
|
||||||
let body = fail_fast!(state.body.ok_or_else(|| fail("No body provided")));
|
let body = fail_fast!(state.body.ok_or_else(|| ffail!("No body provided")));
|
||||||
Continuation::Final(Ok(Iq {
|
Continuation::Final(Ok(Iq {
|
||||||
from: state.from,
|
from: state.from,
|
||||||
id,
|
id,
|
||||||
|
@ -579,7 +582,7 @@ impl<T: ToXml> ToXml for Presence<T> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::protos::xmpp::bind::{BindRequest, Name, Resource, Server};
|
use crate::bind::{BindRequest, Name, Resource, Server};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use quick_xml::NsReader;
|
use quick_xml::NsReader;
|
|
@ -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 crate::prelude::*;
|
use anyhow::{Result, anyhow as ffail};
|
||||||
use crate::util::xml::*;
|
use crate::xml::*;
|
||||||
|
|
||||||
use super::bind::Jid;
|
use super::bind::Jid;
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
#![feature(
|
||||||
|
generators,
|
||||||
|
generator_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;
|
||||||
|
@ -8,6 +15,8 @@ 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;
|
||||||
|
|
||||||
// Implemented as a macro instead of a fn due to borrowck limitations
|
// Implemented as a macro instead of a fn due to borrowck limitations
|
||||||
macro_rules! skip_text {
|
macro_rules! skip_text {
|
||||||
|
@ -25,4 +34,4 @@ macro_rules! skip_text {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) use skip_text;
|
pub(crate) use skip_text;
|
|
@ -1,8 +1,8 @@
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use quick_xml::name::ResolveResult;
|
use quick_xml::name::ResolveResult;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use anyhow::{anyhow, Result};
|
||||||
use crate::util::xml::*;
|
use crate::xml::*;
|
||||||
|
|
||||||
pub const XMLNS: &'static str = "http://jabber.org/protocol/muc";
|
pub const XMLNS: &'static str = "http://jabber.org/protocol/muc";
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl FromXml for History {
|
||||||
let (bytes, end) = match event {
|
let (bytes, end) = match event {
|
||||||
Event::Start(bytes) => (bytes, false),
|
Event::Start(bytes) => (bytes, false),
|
||||||
Event::Empty(bytes) => (bytes, true),
|
Event::Empty(bytes) => (bytes, true),
|
||||||
_ => return Err(ffail!("Unexpected XML event: {event:?}")),
|
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
|
||||||
};
|
};
|
||||||
for attr in bytes.attributes() {
|
for attr in bytes.attributes() {
|
||||||
let attr = attr?;
|
let attr = attr?;
|
||||||
|
@ -51,7 +51,7 @@ impl FromXml for History {
|
||||||
|
|
||||||
let (namespace, event) = yield;
|
let (namespace, event) = yield;
|
||||||
let Event::End(bytes) = event else {
|
let Event::End(bytes) = event else {
|
||||||
return Err(ffail!("Unexpected XML event: {event:?}"));
|
return Err(anyhow!("Unexpected XML event: {event:?}"));
|
||||||
};
|
};
|
||||||
Ok(history)
|
Ok(history)
|
||||||
}
|
}
|
||||||
|
@ -73,15 +73,15 @@ impl FromXml for Password {
|
||||||
fn parse() -> Self::P {
|
fn parse() -> Self::P {
|
||||||
|(namespace, event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
|
|(namespace, event): (ResolveResult<'static>, &'static Event<'static>)| -> Result<Self> {
|
||||||
let Event::Start(bytes) = event else {
|
let Event::Start(bytes) = event else {
|
||||||
return Err(ffail!("Unexpected XML event: {event:?}"));
|
return Err(anyhow!("Unexpected XML event: {event:?}"));
|
||||||
};
|
};
|
||||||
let (namespace, event) = yield;
|
let (namespace, event) = yield;
|
||||||
let Event::Text(bytes) = event else {
|
let Event::Text(bytes) = event else {
|
||||||
return Err(ffail!("Unexpected XML event: {event:?}"));
|
return Err(anyhow!("Unexpected XML event: {event:?}"));
|
||||||
};
|
};
|
||||||
let s = std::str::from_utf8(bytes)?.to_string();
|
let s = std::str::from_utf8(bytes)?.to_string();
|
||||||
let Event::End(bytes) = event else {
|
let Event::End(bytes) = event else {
|
||||||
return Err(ffail!("Unexpected XML event: {event:?}"));
|
return Err(anyhow!("Unexpected XML event: {event:?}"));
|
||||||
};
|
};
|
||||||
Ok(Password(s))
|
Ok(Password(s))
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ impl FromXml for X {
|
||||||
let (bytes, end) = match event {
|
let (bytes, end) = match event {
|
||||||
Event::Start(bytes) => (bytes, false),
|
Event::Start(bytes) => (bytes, false),
|
||||||
Event::Empty(bytes) => (bytes, true),
|
Event::Empty(bytes) => (bytes, true),
|
||||||
_ => return Err(ffail!("Unexpected XML event: {event:?}")),
|
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
|
||||||
};
|
};
|
||||||
if end {
|
if end {
|
||||||
return Ok(res);
|
return Ok(res);
|
||||||
|
@ -121,7 +121,7 @@ impl FromXml for X {
|
||||||
Event::Start(bytes) => bytes,
|
Event::Start(bytes) => bytes,
|
||||||
Event::Empty(bytes) => bytes,
|
Event::Empty(bytes) => bytes,
|
||||||
Event::End(_) => break,
|
Event::End(_) => break,
|
||||||
_ => return Err(ffail!("Unexpected XML event: {event:?}")),
|
_ => return Err(anyhow!("Unexpected XML event: {event:?}")),
|
||||||
};
|
};
|
||||||
if bytes.name().0 == Password::NAME.as_bytes() {
|
if bytes.name().0 == Password::NAME.as_bytes() {
|
||||||
let password = delegate_parsing!(Password, namespace, event)?;
|
let password = delegate_parsing!(Password, namespace, event)?;
|
||||||
|
@ -130,7 +130,7 @@ impl FromXml for X {
|
||||||
let history = delegate_parsing!(History, namespace, event)?;
|
let history = delegate_parsing!(History, namespace, event)?;
|
||||||
res.history = Some(history);
|
res.history = Some(history);
|
||||||
} else {
|
} else {
|
||||||
return Err(ffail!("Unexpected XML event: {event:?}"));
|
return Err(anyhow!("Unexpected XML event: {event:?}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
pub type Str = Arc<str>;
|
|
@ -1,7 +1,7 @@
|
||||||
use quick_xml::events::{BytesStart, Event};
|
use quick_xml::events::{BytesStart, Event};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::xml::*;
|
||||||
use crate::util::xml::*;
|
use anyhow::{anyhow as ffail, Result};
|
||||||
|
|
||||||
pub const XMLNS: &'static str = "jabber:iq:roster";
|
pub const XMLNS: &'static str = "jabber:iq:roster";
|
||||||
|
|
|
@ -7,7 +7,7 @@ use quick_xml::{
|
||||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||||
|
|
||||||
use super::skip_text;
|
use super::skip_text;
|
||||||
use crate::prelude::*;
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub enum Mechanism {
|
pub enum Mechanism {
|
||||||
Plain,
|
Plain,
|
||||||
|
@ -22,7 +22,7 @@ impl Mechanism {
|
||||||
pub fn from_str(input: &[u8]) -> Result<Mechanism> {
|
pub fn from_str(input: &[u8]) -> Result<Mechanism> {
|
||||||
match input {
|
match input {
|
||||||
b"PLAIN" => Ok(Mechanism::Plain),
|
b"PLAIN" => Ok(Mechanism::Plain),
|
||||||
_ => Err(fail(format!("unknown auth mechanism: {input:?}").as_str())),
|
_ => Err(anyhow!("unknown auth mechanism: {input:?}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,20 +48,20 @@ impl Auth {
|
||||||
if let Some(mechanism) = mechanism {
|
if let Some(mechanism) = mechanism {
|
||||||
Mechanism::from_str(mechanism.borrow())?
|
Mechanism::from_str(mechanism.borrow())?
|
||||||
} else {
|
} else {
|
||||||
return Err(fail("expected mechanism attribute in <auth>"));
|
return Err(anyhow!("expected mechanism attribute in <auth>"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(fail("expected start of <auth>"));
|
return Err(anyhow!("expected start of <auth>"));
|
||||||
};
|
};
|
||||||
let body = if let Event::Text(text) = reader.read_event_into_async(buf).await? {
|
let body = if let Event::Text(text) = reader.read_event_into_async(buf).await? {
|
||||||
text.into_inner().into_owned()
|
text.into_inner().into_owned()
|
||||||
} else {
|
} else {
|
||||||
return Err(fail("expected text body in <auth>"));
|
return Err(anyhow!("expected text body in <auth>"));
|
||||||
};
|
};
|
||||||
if let Event::End(_) = reader.read_event_into_async(buf).await? {
|
if let Event::End(_) = reader.read_event_into_async(buf).await? {
|
||||||
//TODO
|
//TODO
|
||||||
} else {
|
} else {
|
||||||
return Err(fail("expected end of <auth>"));
|
return Err(anyhow!("expected end of <auth>"));
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Auth { mechanism, body })
|
Ok(Auth { mechanism, body })
|
|
@ -1,7 +1,7 @@
|
||||||
use quick_xml::events::{BytesStart, Event};
|
use quick_xml::events::{BytesStart, Event};
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::xml::*;
|
||||||
use crate::util::xml::*;
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-session";
|
pub const XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-session";
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ impl Parser for SessionParser {
|
||||||
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(ffail!("Unexpected XML event: {event:?}"))),
|
_ => Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}"))),
|
||||||
},
|
},
|
||||||
SessionParserInner::InSession => match event {
|
SessionParserInner::InSession => match event {
|
||||||
Event::End(_) => Continuation::Final(Ok(Session)),
|
Event::End(_) => Continuation::Final(Ok(Session)),
|
||||||
_ => Continuation::Final(Err(ffail!("Unexpected XML event: {event:?}"))),
|
_ => Continuation::Final(Err(anyhow!("Unexpected XML event: {event:?}"))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,8 +5,9 @@ use quick_xml::{NsReader, Writer};
|
||||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||||
|
|
||||||
use super::skip_text;
|
use super::skip_text;
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::util::xml::ToXml;
|
use anyhow::{anyhow, Result};
|
||||||
|
use crate::xml::ToXml;
|
||||||
|
|
||||||
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";
|
||||||
|
@ -63,7 +64,6 @@ impl ClientStreamStart {
|
||||||
version: version.unwrap(),
|
version: version.unwrap(),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
log::error!("WAT: {incoming:?}");
|
|
||||||
Err(panic!())
|
Err(panic!())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,8 @@ use quick_xml::{NsReader, Writer};
|
||||||
use tokio::io::{AsyncBufRead, AsyncWrite};
|
use tokio::io::{AsyncBufRead, AsyncWrite};
|
||||||
|
|
||||||
use super::skip_text;
|
use super::skip_text;
|
||||||
use crate::prelude::*;
|
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
pub static XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls";
|
pub static XMLNS: &'static str = "urn:ietf:params:xml:ns:xmpp-tls";
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ impl StartTLS {
|
||||||
return Ok(StartTLS);
|
return Ok(StartTLS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ffail!("XML tag starttls expected, received: {incoming:?}"))
|
Err(anyhow!("XML tag starttls expected, received: {incoming:?}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::pin::Pin;
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use quick_xml::name::ResolveResult;
|
use quick_xml::name::ResolveResult;
|
||||||
|
|
||||||
use crate::prelude::Result;
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
mod ignore;
|
mod ignore;
|
||||||
pub use ignore::Ignore;
|
pub use ignore::Ignore;
|
||||||
|
@ -72,6 +72,7 @@ macro_rules! fail_fast {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! delegate_parsing {
|
macro_rules! delegate_parsing {
|
||||||
($parser: ty, $namespace: expr, $event: expr) => {{
|
($parser: ty, $namespace: expr, $event: expr) => {{
|
||||||
let mut parser = <$parser as FromXml>::parse().consume($namespace, $event);
|
let mut parser = <$parser as FromXml>::parse().consume($namespace, $event);
|
||||||
|
@ -88,6 +89,7 @@ macro_rules! delegate_parsing {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
macro_rules! match_parser {
|
macro_rules! match_parser {
|
||||||
($name: expr, $ns: expr, $event: expr; $subtype: ty, $fin: block) => {
|
($name: expr, $ns: expr, $event: expr; $subtype: ty, $fin: block) => {
|
||||||
if $name.0 == <$subtype as FromXmlTag>::NAME.as_bytes() && $ns == ResolveResult::Bound(Namespace(<$subtype as FromXmlTag>::NS.as_bytes())) {
|
if $name.0 == <$subtype as FromXmlTag>::NAME.as_bytes() && $ns == ResolveResult::Bound(Namespace(<$subtype as FromXmlTag>::NS.as_bytes())) {
|
||||||
|
@ -105,6 +107,6 @@ macro_rules! match_parser {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) use delegate_parsing;
|
pub use delegate_parsing;
|
||||||
pub(crate) use fail_fast;
|
pub(crate) use fail_fast;
|
||||||
pub(crate) use match_parser;
|
pub use match_parser;
|
|
@ -8,7 +8,6 @@
|
||||||
mod core;
|
mod core;
|
||||||
mod prelude;
|
mod prelude;
|
||||||
mod projections;
|
mod projections;
|
||||||
mod protos;
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
|
@ -22,14 +22,13 @@ use tokio_rustls::TlsAcceptor;
|
||||||
use crate::core::player::{PlayerConnection, PlayerId, PlayerRegistry};
|
use crate::core::player::{PlayerConnection, PlayerId, PlayerRegistry};
|
||||||
use crate::core::room::{RoomId, RoomRegistry};
|
use crate::core::room::{RoomId, RoomRegistry};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use crate::protos::xmpp;
|
use proto_xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
|
||||||
use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
|
use proto_xmpp::client::{Iq, Message, MessageType, Presence};
|
||||||
use crate::protos::xmpp::client::{Iq, Message, MessageType, Presence};
|
use proto_xmpp::disco::*;
|
||||||
use crate::protos::xmpp::disco::*;
|
use proto_xmpp::roster::RosterQuery;
|
||||||
use crate::protos::xmpp::roster::RosterQuery;
|
use proto_xmpp::session::Session;
|
||||||
use crate::protos::xmpp::session::Session;
|
use proto_xmpp::stream::*;
|
||||||
use crate::protos::xmpp::stream::*;
|
use proto_xmpp::xml::{Continuation, FromXml, Parser, ToXml};
|
||||||
use crate::util::xml::{Continuation, FromXml, Parser, ToXml};
|
|
||||||
use crate::util::Terminator;
|
use crate::util::Terminator;
|
||||||
|
|
||||||
use self::proto::{ClientPacket, IqClientBody};
|
use self::proto::{ClientPacket, IqClientBody};
|
||||||
|
@ -196,7 +195,7 @@ async fn socket_force_tls(
|
||||||
writer: &mut (impl AsyncWrite + Unpin),
|
writer: &mut (impl AsyncWrite + Unpin),
|
||||||
reader_buf: &mut Vec<u8>,
|
reader_buf: &mut Vec<u8>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
use crate::protos::xmpp::tls::*;
|
use proto_xmpp::tls::*;
|
||||||
let xml_reader = &mut NsReader::from_reader(reader);
|
let xml_reader = &mut NsReader::from_reader(reader);
|
||||||
let xml_writer = &mut Writer::new(writer);
|
let xml_writer = &mut Writer::new(writer);
|
||||||
read_xml_header(xml_reader, reader_buf).await?;
|
read_xml_header(xml_reader, reader_buf).await?;
|
||||||
|
@ -253,8 +252,8 @@ async fn socket_auth(
|
||||||
.await?;
|
.await?;
|
||||||
xml_writer.get_mut().flush().await?;
|
xml_writer.get_mut().flush().await?;
|
||||||
|
|
||||||
let _ = xmpp::sasl::Auth::parse(xml_reader, reader_buf).await?;
|
let _ = proto_xmpp::sasl::Auth::parse(xml_reader, reader_buf).await?;
|
||||||
xmpp::sasl::Success.write_xml(xml_writer).await?;
|
proto_xmpp::sasl::Success.write_xml(xml_writer).await?;
|
||||||
|
|
||||||
let name: Str = "darova".into();
|
let name: Str = "darova".into();
|
||||||
Ok(Authenticated {
|
Ok(Authenticated {
|
||||||
|
@ -346,7 +345,7 @@ async fn socket_final(
|
||||||
resource: Some(Resource(author_id.into_inner().into())),
|
resource: Some(Resource(author_id.into_inner().into())),
|
||||||
}),
|
}),
|
||||||
id: None,
|
id: None,
|
||||||
r#type: xmpp::client::MessageType::Groupchat,
|
r#type: proto_xmpp::client::MessageType::Groupchat,
|
||||||
lang: None,
|
lang: None,
|
||||||
subject: None,
|
subject: None,
|
||||||
body: body.into(),
|
body: body.into(),
|
||||||
|
@ -414,7 +413,7 @@ async fn handle_packet(
|
||||||
resource: Some(user.xmpp_muc_name.clone()),
|
resource: Some(user.xmpp_muc_name.clone()),
|
||||||
}),
|
}),
|
||||||
id: m.id,
|
id: m.id,
|
||||||
r#type: xmpp::client::MessageType::Groupchat,
|
r#type: proto_xmpp::client::MessageType::Groupchat,
|
||||||
lang: None,
|
lang: None,
|
||||||
subject: None,
|
subject: None,
|
||||||
body: m.body.clone(),
|
body: m.body.clone(),
|
||||||
|
@ -485,7 +484,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: None,
|
from: None,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Result,
|
r#type: proto_xmpp::client::IqType::Result,
|
||||||
body: BindResponse(Jid {
|
body: BindResponse(Jid {
|
||||||
name: Some(Name("darova".into())),
|
name: Some(Name("darova".into())),
|
||||||
server: Server("localhost".into()),
|
server: Server("localhost".into()),
|
||||||
|
@ -499,7 +498,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: None,
|
from: None,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Result,
|
r#type: proto_xmpp::client::IqType::Result,
|
||||||
body: Session,
|
body: Session,
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
@ -509,7 +508,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: None,
|
from: None,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Result,
|
r#type: proto_xmpp::client::IqType::Result,
|
||||||
body: RosterQuery,
|
body: RosterQuery,
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
@ -520,7 +519,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: iq.to,
|
from: iq.to,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Result,
|
r#type: proto_xmpp::client::IqType::Result,
|
||||||
body: response,
|
body: response,
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
@ -531,7 +530,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: iq.to,
|
from: iq.to,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Result,
|
r#type: proto_xmpp::client::IqType::Result,
|
||||||
body: response,
|
body: response,
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
@ -541,7 +540,7 @@ async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms
|
||||||
from: None,
|
from: None,
|
||||||
id: iq.id,
|
id: iq.id,
|
||||||
to: None,
|
to: None,
|
||||||
r#type: xmpp::client::IqType::Error,
|
r#type: proto_xmpp::client::IqType::Error,
|
||||||
body: (),
|
body: (),
|
||||||
};
|
};
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
|
|
|
@ -2,12 +2,12 @@ use derive_more::From;
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
use quick_xml::name::{Namespace, ResolveResult};
|
use quick_xml::name::{Namespace, ResolveResult};
|
||||||
|
|
||||||
use crate::protos::xmpp::bind::BindRequest;
|
use proto_xmpp::bind::BindRequest;
|
||||||
use crate::protos::xmpp::client::{Iq, Message, Presence};
|
use proto_xmpp::client::{Iq, Message, Presence};
|
||||||
use crate::protos::xmpp::disco::{InfoQuery, ItemQuery};
|
use proto_xmpp::disco::{InfoQuery, ItemQuery};
|
||||||
use crate::protos::xmpp::roster::RosterQuery;
|
use proto_xmpp::roster::RosterQuery;
|
||||||
use crate::protos::xmpp::session::Session;
|
use proto_xmpp::session::Session;
|
||||||
use crate::util::xml::*;
|
use proto_xmpp::xml::*;
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
//! Definitions of wire protocols to be used in implementations of projections.
|
|
||||||
pub mod xmpp;
|
|
|
@ -5,7 +5,6 @@ pub mod table;
|
||||||
pub mod telemetry;
|
pub mod telemetry;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod testkit;
|
pub mod testkit;
|
||||||
pub mod xml;
|
|
||||||
|
|
||||||
pub struct Terminator {
|
pub struct Terminator {
|
||||||
signal: Promise<()>,
|
signal: Promise<()>,
|
||||||
|
|
Loading…
Reference in New Issue