2024-08-11 12:21:06 +02:00
|
|
|
//! Components in XMPP are services/gateways that are logged into an
|
|
|
|
|
//! XMPP server under a JID consisting of just a domain name. They are
|
|
|
|
|
//! allowed to use any user and resource identifiers in their stanzas.
|
|
|
|
|
use futures::{task::Poll, Sink, Stream};
|
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
use std::task::Context;
|
|
|
|
|
|
2024-08-10 15:05:42 +02:00
|
|
|
use crate::{
|
2024-09-02 17:27:23 +02:00
|
|
|
component::Component,
|
|
|
|
|
connect::ServerConnector,
|
|
|
|
|
xmlstream::{XmppStream, XmppStreamElement},
|
|
|
|
|
Error, Stanza,
|
2024-08-10 15:05:42 +02:00
|
|
|
};
|
2024-08-11 12:21:06 +02:00
|
|
|
|
|
|
|
|
impl<C: ServerConnector> Stream for Component<C> {
|
2024-08-10 15:05:42 +02:00
|
|
|
type Item = Stanza;
|
2024-08-11 12:21:06 +02:00
|
|
|
|
|
|
|
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
|
|
|
|
loop {
|
|
|
|
|
match Pin::new(&mut self.stream).poll_next(cx) {
|
2024-09-02 17:27:31 +02:00
|
|
|
Poll::Ready(Some(Ok(XmppStreamElement::Stanza(stanza)))) => {
|
|
|
|
|
return Poll::Ready(Some(stanza))
|
2024-08-11 12:21:06 +02:00
|
|
|
}
|
|
|
|
|
Poll::Ready(Some(Ok(_))) =>
|
|
|
|
|
// unexpected
|
|
|
|
|
{
|
|
|
|
|
return Poll::Ready(None)
|
|
|
|
|
}
|
|
|
|
|
Poll::Ready(Some(Err(_))) => return Poll::Ready(None),
|
|
|
|
|
Poll::Ready(None) => return Poll::Ready(None),
|
|
|
|
|
Poll::Pending => return Poll::Pending,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 15:05:42 +02:00
|
|
|
impl<C: ServerConnector> Sink<Stanza> for Component<C> {
|
2024-08-11 12:21:06 +02:00
|
|
|
type Error = Error;
|
|
|
|
|
|
2024-08-10 15:05:42 +02:00
|
|
|
fn start_send(mut self: Pin<&mut Self>, item: Stanza) -> Result<(), Self::Error> {
|
2024-08-11 12:21:06 +02:00
|
|
|
Pin::new(&mut self.stream)
|
2024-09-02 17:27:23 +02:00
|
|
|
.start_send(&item)
|
2024-08-11 12:21:06 +02:00
|
|
|
.map_err(|e| e.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_ready(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
2024-09-02 17:27:23 +02:00
|
|
|
<XmppStream<C::Stream> as Sink<&XmppStreamElement>>::poll_ready(
|
|
|
|
|
Pin::new(&mut self.stream),
|
|
|
|
|
cx,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.into())
|
2024-08-11 12:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
2024-09-02 17:27:23 +02:00
|
|
|
<XmppStream<C::Stream> as Sink<&XmppStreamElement>>::poll_flush(
|
|
|
|
|
Pin::new(&mut self.stream),
|
|
|
|
|
cx,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.into())
|
2024-08-11 12:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<(), Self::Error>> {
|
2024-09-02 17:27:23 +02:00
|
|
|
<XmppStream<C::Stream> as Sink<&XmppStreamElement>>::poll_close(
|
|
|
|
|
Pin::new(&mut self.stream),
|
|
|
|
|
cx,
|
|
|
|
|
)
|
|
|
|
|
.map_err(|e| e.into())
|
2024-08-11 12:21:06 +02:00
|
|
|
}
|
|
|
|
|
}
|