mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Changed name to XmppCodec
This commit is contained in:
parent
56dc1c6e60
commit
eb0bc1b82f
5 changed files with 22 additions and 22 deletions
|
@ -2,7 +2,7 @@ use futures::{SinkExt, StreamExt};
|
||||||
use tokio::{self, io, net::TcpSocket};
|
use tokio::{self, io, net::TcpSocket};
|
||||||
use tokio_util::codec::Framed;
|
use tokio_util::codec::Framed;
|
||||||
|
|
||||||
use tokio_xmpp::XMPPCodec;
|
use tokio_xmpp::XmppCodec;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), io::Error> {
|
async fn main() -> Result<(), io::Error> {
|
||||||
|
@ -18,7 +18,7 @@ async fn main() -> Result<(), io::Error> {
|
||||||
let (stream, _addr) = listener.accept().await?;
|
let (stream, _addr) = listener.accept().await?;
|
||||||
|
|
||||||
// Use the `XMPPCodec` to encode and decode frames
|
// Use the `XMPPCodec` to encode and decode frames
|
||||||
let mut framed = Framed::new(stream, XMPPCodec::new());
|
let mut framed = Framed::new(stream, XmppCodec::new());
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(packet) = framed.next().await {
|
while let Some(packet) = framed.next().await {
|
||||||
|
|
|
@ -25,7 +25,7 @@ mod stream_start;
|
||||||
#[cfg(feature = "insecure-tcp")]
|
#[cfg(feature = "insecure-tcp")]
|
||||||
pub mod tcp;
|
pub mod tcp;
|
||||||
mod xmpp_codec;
|
mod xmpp_codec;
|
||||||
pub use crate::xmpp_codec::{Packet, XMPPCodec};
|
pub use crate::xmpp_codec::{Packet, XmppCodec};
|
||||||
mod event;
|
mod event;
|
||||||
pub use event::Event;
|
pub use event::Event;
|
||||||
mod client;
|
mod client;
|
||||||
|
|
|
@ -3,14 +3,14 @@ use tokio::io::{AsyncRead, AsyncWrite};
|
||||||
use tokio_util::codec::Framed;
|
use tokio_util::codec::Framed;
|
||||||
use xmpp_parsers::{ns, Element, Jid};
|
use xmpp_parsers::{ns, Element, Jid};
|
||||||
|
|
||||||
use crate::xmpp_codec::{Packet, XMPPCodec};
|
use crate::xmpp_codec::{Packet, XmppCodec};
|
||||||
use crate::xmpp_stream::XMPPStream;
|
use crate::xmpp_stream::XMPPStream;
|
||||||
use crate::{Error, ProtocolError};
|
use crate::{Error, ProtocolError};
|
||||||
|
|
||||||
/// Sends a `<stream:stream>`, then wait for one from the server, and
|
/// Sends a `<stream:stream>`, then wait for one from the server, and
|
||||||
/// construct an XMPPStream.
|
/// construct an XMPPStream.
|
||||||
pub async fn start<S: AsyncRead + AsyncWrite + Unpin>(
|
pub async fn start<S: AsyncRead + AsyncWrite + Unpin>(
|
||||||
mut stream: Framed<S, XMPPCodec>,
|
mut stream: Framed<S, XmppCodec>,
|
||||||
jid: Jid,
|
jid: Jid,
|
||||||
ns: String,
|
ns: String,
|
||||||
) -> Result<XMPPStream<S>, Error> {
|
) -> Result<XMPPStream<S>, Error> {
|
||||||
|
|
|
@ -59,7 +59,7 @@ pub enum Packet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stateful encoder/decoder for a bytestream from/to XMPP `Packet`
|
/// Stateful encoder/decoder for a bytestream from/to XMPP `Packet`
|
||||||
pub struct XMPPCodec {
|
pub struct XmppCodec {
|
||||||
/// Outgoing
|
/// Outgoing
|
||||||
ns: Option<String>,
|
ns: Option<String>,
|
||||||
/// Incoming
|
/// Incoming
|
||||||
|
@ -67,7 +67,7 @@ pub struct XMPPCodec {
|
||||||
stanza_builder: TreeBuilder,
|
stanza_builder: TreeBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XMPPCodec {
|
impl XmppCodec {
|
||||||
/// Constructor
|
/// Constructor
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let stanza_builder = TreeBuilder::new();
|
let stanza_builder = TreeBuilder::new();
|
||||||
|
@ -76,7 +76,7 @@ impl XMPPCodec {
|
||||||
if log::log_enabled!(log::Level::Debug) && PS.get().is_none() {
|
if log::log_enabled!(log::Level::Debug) && PS.get().is_none() {
|
||||||
init_syntect();
|
init_syntect();
|
||||||
}
|
}
|
||||||
XMPPCodec {
|
XmppCodec {
|
||||||
ns: None,
|
ns: None,
|
||||||
driver,
|
driver,
|
||||||
stanza_builder,
|
stanza_builder,
|
||||||
|
@ -84,13 +84,13 @@ impl XMPPCodec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for XMPPCodec {
|
impl Default for XmppCodec {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Decoder for XMPPCodec {
|
impl Decoder for XmppCodec {
|
||||||
type Item = Packet;
|
type Item = Packet;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ impl Decoder for XMPPCodec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Encoder<Packet> for XMPPCodec {
|
impl Encoder<Packet> for XmppCodec {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn encode(&mut self, item: Packet, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
fn encode(&mut self, item: Packet, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
||||||
|
@ -253,7 +253,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stream_start() {
|
fn test_stream_start() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
@ -265,7 +265,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stream_end() {
|
fn test_stream_end() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
@ -283,7 +283,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_truncated_stanza() {
|
fn test_truncated_stanza() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
@ -309,7 +309,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_truncated_utf8() {
|
fn test_truncated_utf8() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
@ -336,7 +336,7 @@ mod tests {
|
||||||
/// test case for https://gitlab.com/xmpp-rs/tokio-xmpp/issues/3
|
/// test case for https://gitlab.com/xmpp-rs/tokio-xmpp/issues/3
|
||||||
#[test]
|
#[test]
|
||||||
fn test_atrribute_prefix() {
|
fn test_atrribute_prefix() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
@ -363,7 +363,7 @@ mod tests {
|
||||||
use futures::{executor::block_on, sink::SinkExt};
|
use futures::{executor::block_on, sink::SinkExt};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use tokio_util::codec::FramedWrite;
|
use tokio_util::codec::FramedWrite;
|
||||||
let mut framed = FramedWrite::new(Cursor::new(vec![]), XMPPCodec::new());
|
let mut framed = FramedWrite::new(Cursor::new(vec![]), XmppCodec::new());
|
||||||
let mut text = "".to_owned();
|
let mut text = "".to_owned();
|
||||||
for _ in 0..2usize.pow(15) {
|
for _ in 0..2usize.pow(15) {
|
||||||
text = text + "A";
|
text = text + "A";
|
||||||
|
@ -388,7 +388,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cut_out_stanza() {
|
fn test_cut_out_stanza() {
|
||||||
let mut c = XMPPCodec::new();
|
let mut c = XmppCodec::new();
|
||||||
let mut b = BytesMut::with_capacity(1024);
|
let mut b = BytesMut::with_capacity(1024);
|
||||||
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
b.put_slice(b"<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xmlns='jabber:client'>");
|
||||||
let r = c.decode(&mut b);
|
let r = c.decode(&mut b);
|
||||||
|
|
|
@ -11,7 +11,7 @@ use xmpp_parsers::{Element, Jid};
|
||||||
|
|
||||||
use crate::stream_features::StreamFeatures;
|
use crate::stream_features::StreamFeatures;
|
||||||
use crate::stream_start;
|
use crate::stream_start;
|
||||||
use crate::xmpp_codec::{Packet, XMPPCodec};
|
use crate::xmpp_codec::{Packet, XmppCodec};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
fn make_id() -> String {
|
fn make_id() -> String {
|
||||||
|
@ -40,7 +40,7 @@ pub struct XMPPStream<S: AsyncRead + AsyncWrite + Unpin> {
|
||||||
/// The local Jabber-Id
|
/// The local Jabber-Id
|
||||||
pub jid: Jid,
|
pub jid: Jid,
|
||||||
/// Codec instance
|
/// Codec instance
|
||||||
pub stream: Framed<S, XMPPCodec>,
|
pub stream: Framed<S, XmppCodec>,
|
||||||
/// `<stream:features/>` for XMPP version 1.0
|
/// `<stream:features/>` for XMPP version 1.0
|
||||||
pub stream_features: StreamFeatures,
|
pub stream_features: StreamFeatures,
|
||||||
/// Root namespace
|
/// Root namespace
|
||||||
|
@ -56,7 +56,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> XMPPStream<S> {
|
||||||
/// Constructor
|
/// Constructor
|
||||||
pub fn new(
|
pub fn new(
|
||||||
jid: Jid,
|
jid: Jid,
|
||||||
stream: Framed<S, XMPPCodec>,
|
stream: Framed<S, XmppCodec>,
|
||||||
ns: String,
|
ns: String,
|
||||||
id: String,
|
id: String,
|
||||||
stream_features: Element,
|
stream_features: Element,
|
||||||
|
@ -72,7 +72,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> XMPPStream<S> {
|
||||||
|
|
||||||
/// Send a `<stream:stream>` start tag
|
/// Send a `<stream:stream>` start tag
|
||||||
pub async fn start(stream: S, jid: Jid, ns: String) -> Result<Self, Error> {
|
pub async fn start(stream: S, jid: Jid, ns: String) -> Result<Self, Error> {
|
||||||
let xmpp_stream = Framed::new(stream, XMPPCodec::new());
|
let xmpp_stream = Framed::new(stream, XmppCodec::new());
|
||||||
stream_start::start(xmpp_stream, jid, ns).await
|
stream_start::start(xmpp_stream, jid, ns).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue