Move XmppCodec and XmppStream to proto module

This commit is contained in:
xmppftw xmppftw 2024-08-06 17:00:53 +02:00
commit fde4c2b640
17 changed files with 135 additions and 148 deletions

View file

@ -3,11 +3,10 @@ use tokio::io::{AsyncRead, AsyncWrite};
use xmpp_parsers::{component::Handshake, ns};
use crate::error::{AuthError, Error};
use crate::xmpp_codec::Packet;
use crate::xmpp_stream::XMPPStream;
use crate::proto::{Packet, XmppStream};
pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
stream: &mut XMPPStream<S>,
stream: &mut XmppStream<S>,
password: String,
) -> Result<(), Error> {
let nonza = Handshake::from_password_and_stream_id(&password, &stream.id);

View file

@ -1,16 +1,13 @@
use xmpp_parsers::{jid::Jid, ns};
use crate::connect::ServerConnector;
use crate::{xmpp_stream::XMPPStream, Error};
use super::auth::auth;
use crate::{component::auth::auth, connect::ServerConnector, proto::XmppStream, Error};
/// Log into an XMPP server as a client with a jid+pass
pub async fn component_login<C: ServerConnector>(
connector: C,
jid: Jid,
password: String,
) -> Result<XMPPStream<C::Stream>, Error> {
) -> Result<XmppStream<C::Stream>, Error> {
let password = password;
let mut xmpp_stream = connector.connect(&jid, ns::COMPONENT).await?;
auth(&mut xmpp_stream, password).await?;

View file

@ -10,11 +10,9 @@ use xmpp_parsers::{jid::Jid, ns};
use self::connect::component_login;
use super::xmpp_codec::Packet;
use super::Error;
use crate::connect::ServerConnector;
use crate::xmpp_stream::add_stanza_id;
use crate::xmpp_stream::XMPPStream;
use crate::proto::{add_stanza_id, Packet, XmppStream};
use crate::Error;
mod auth;
@ -22,12 +20,12 @@ pub(crate) mod connect;
/// Component connection to an XMPP server
///
/// This simplifies the `XMPPStream` to a `Stream`/`Sink` of `Element`
/// This simplifies the `XmppStream` to a `Stream`/`Sink` of `Element`
/// (stanzas). Connection handling however is up to the user.
pub struct Component<C: ServerConnector> {
/// The component's Jabber-Id
pub jid: Jid,
stream: XMPPStream<C::Stream>,
stream: XmppStream<C::Stream>,
}
impl<C: ServerConnector> Component<C> {