forked from lavina/lavina
xmpp: make xml-headers optional in the c2s stream
This commit is contained in:
parent
d436631450
commit
1e2a6d5656
|
@ -229,7 +229,6 @@ async fn socket_force_tls(
|
||||||
use proto_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?;
|
|
||||||
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
||||||
|
|
||||||
let event = Event::Decl(BytesDecl::new("1.0", None, None));
|
let event = Event::Decl(BytesDecl::new("1.0", None, None));
|
||||||
|
@ -261,7 +260,6 @@ async fn socket_auth(
|
||||||
reader_buf: &mut Vec<u8>,
|
reader_buf: &mut Vec<u8>,
|
||||||
storage: &mut Storage,
|
storage: &mut Storage,
|
||||||
) -> Result<Authenticated> {
|
) -> Result<Authenticated> {
|
||||||
read_xml_header(xml_reader, reader_buf).await?;
|
|
||||||
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
||||||
|
|
||||||
xml_writer.write_event_async(Event::Decl(BytesDecl::new("1.0", None, None))).await?;
|
xml_writer.write_event_async(Event::Decl(BytesDecl::new("1.0", None, None))).await?;
|
||||||
|
@ -327,7 +325,6 @@ async fn socket_final(
|
||||||
user_handle: &mut PlayerConnection,
|
user_handle: &mut PlayerConnection,
|
||||||
rooms: &RoomRegistry,
|
rooms: &RoomRegistry,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
read_xml_header(xml_reader, reader_buf).await?;
|
|
||||||
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
||||||
|
|
||||||
xml_writer.write_event_async(Event::Decl(BytesDecl::new("1.0", None, None))).await?;
|
xml_writer.write_event_async(Event::Decl(BytesDecl::new("1.0", None, None))).await?;
|
||||||
|
@ -419,7 +416,7 @@ struct XmppConnection<'a> {
|
||||||
impl<'a> XmppConnection<'a> {
|
impl<'a> XmppConnection<'a> {
|
||||||
async fn handle_packet(&mut self, output: &mut Vec<Event<'static>>, packet: ClientPacket) -> Result<bool> {
|
async fn handle_packet(&mut self, output: &mut Vec<Event<'static>>, packet: ClientPacket) -> Result<bool> {
|
||||||
let res = match packet {
|
let res = match packet {
|
||||||
proto::ClientPacket::Iq(iq) => {
|
ClientPacket::Iq(iq) => {
|
||||||
self.handle_iq(output, iq).await;
|
self.handle_iq(output, iq).await;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -427,11 +424,11 @@ impl<'a> XmppConnection<'a> {
|
||||||
self.handle_message(output, m).await?;
|
self.handle_message(output, m).await?;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
proto::ClientPacket::Presence(p) => {
|
ClientPacket::Presence(p) => {
|
||||||
self.handle_presence(output, p).await?;
|
self.handle_presence(output, p).await?;
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
proto::ClientPacket::StreamEnd => {
|
ClientPacket::StreamEnd => {
|
||||||
ServerStreamEnd.serialize(output);
|
ServerStreamEnd.serialize(output);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
@ -439,25 +436,3 @@ impl<'a> XmppConnection<'a> {
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_xml_header(
|
|
||||||
xml_reader: &mut NsReader<(impl AsyncBufRead + Unpin)>,
|
|
||||||
reader_buf: &mut Vec<u8>,
|
|
||||||
) -> Result<()> {
|
|
||||||
if let Event::Decl(bytes) = xml_reader.read_event_into_async(reader_buf).await? {
|
|
||||||
// this is <?xml ...> header
|
|
||||||
if let Some(encoding) = bytes.encoding() {
|
|
||||||
let encoding = encoding?;
|
|
||||||
if &*encoding == b"UTF-8" {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(anyhow!("Unsupported encoding: {encoding:?}"))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Err(fail("No XML encoding provided"))
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(anyhow!("Expected XML header"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,7 +24,17 @@ impl ClientStreamStart {
|
||||||
reader: &mut NsReader<impl AsyncBufRead + Unpin>,
|
reader: &mut NsReader<impl AsyncBufRead + Unpin>,
|
||||||
buf: &mut Vec<u8>,
|
buf: &mut Vec<u8>,
|
||||||
) -> Result<ClientStreamStart> {
|
) -> Result<ClientStreamStart> {
|
||||||
let incoming = skip_text!(reader, buf);
|
let mut incoming = skip_text!(reader, buf);
|
||||||
|
if let Event::Decl(bytes) = incoming {
|
||||||
|
// this is <?xml ...> header
|
||||||
|
if let Some(encoding) = bytes.encoding() {
|
||||||
|
let encoding = encoding?;
|
||||||
|
if &*encoding != b"UTF-8" {
|
||||||
|
return Err(anyhow!("Unsupported encoding: {encoding:?}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
incoming = skip_text!(reader, buf);
|
||||||
|
}
|
||||||
if let Event::Start(e) = incoming {
|
if let Event::Start(e) = incoming {
|
||||||
let (ns, local) = reader.resolve_element(e.name());
|
let (ns, local) = reader.resolve_element(e.name());
|
||||||
if ns != ResolveResult::Bound(Namespace(XMLNS.as_bytes())) {
|
if ns != ResolveResult::Bound(Namespace(XMLNS.as_bytes())) {
|
||||||
|
|
Loading…
Reference in New Issue