Reorganize component modules
This commit is contained in:
parent
e6863bd9dd
commit
cc3400bac7
4 changed files with 102 additions and 91 deletions
|
|
@ -1,31 +0,0 @@
|
|||
use futures::stream::StreamExt;
|
||||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use xmpp_parsers::{component::Handshake, ns};
|
||||
|
||||
use crate::error::{AuthError, Error};
|
||||
use crate::proto::{Packet, XmppStream};
|
||||
|
||||
pub async fn auth<S: AsyncRead + AsyncWrite + Unpin>(
|
||||
stream: &mut XmppStream<S>,
|
||||
password: String,
|
||||
) -> Result<(), Error> {
|
||||
let nonza = Handshake::from_password_and_stream_id(&password, &stream.id);
|
||||
stream.send_stanza(nonza).await?;
|
||||
|
||||
loop {
|
||||
match stream.next().await {
|
||||
Some(Ok(Packet::Stanza(ref stanza)))
|
||||
if stanza.is("handshake", ns::COMPONENT_ACCEPT) =>
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
Some(Ok(Packet::Stanza(ref stanza)))
|
||||
if stanza.is("error", "http://etherx.jabber.org/streams") =>
|
||||
{
|
||||
return Err(AuthError::ComponentFail.into());
|
||||
}
|
||||
Some(_) => {}
|
||||
None => return Err(Error::Disconnected),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue