From bbc64fde3bd5f16e65cb86ff2f8ba70310d1a131 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Mon, 9 Aug 2021 18:02:26 -0500 Subject: [PATCH] more shifting --- Cargo.lock | 3 ++- imap/Cargo.toml | 1 - imap/src/client/codec.rs | 3 +-- imap/src/proto/mod.rs | 5 ----- imap/src/proto/response.rs | 2 +- imap/src/proto/test_rfc3501.rs | 8 ++++---- proto-common/Cargo.toml | 4 +++- {imap/src/proto => proto-common/src}/convert_error.rs | 0 proto-common/src/lib.rs | 5 +++++ imap/src/proto/macros.rs => proto-common/src/rule.rs | 4 ++++ smtp/src/proto/rfc5321.rs | 3 ++- 11 files changed, 22 insertions(+), 16 deletions(-) rename {imap/src/proto => proto-common/src}/convert_error.rs (100%) rename imap/src/proto/macros.rs => proto-common/src/rule.rs (67%) diff --git a/Cargo.lock b/Cargo.lock index 8d1443a..f611eb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,7 +664,6 @@ dependencies = [ "anyhow", "async-trait", "bitflags", - "bstr", "bytes", "chrono", "derive_builder", @@ -685,8 +684,10 @@ name = "panorama-proto-common" version = "0.0.1" dependencies = [ "anyhow", + "bstr", "bytes", "format-bytes", + "log", "nom", ] diff --git a/imap/Cargo.toml b/imap/Cargo.toml index d28f258..9ff29d1 100644 --- a/imap/Cargo.toml +++ b/imap/Cargo.toml @@ -23,7 +23,6 @@ rfc6154 = [] # list anyhow = "1.0.42" async-trait = "0.1.51" bitflags = "1.2.1" -bstr = "0.2.15" bytes = "1.0.1" chrono = "0.4.19" derive_builder = "0.10.2" diff --git a/imap/src/client/codec.rs b/imap/src/client/codec.rs index ff5a877..ffbda59 100644 --- a/imap/src/client/codec.rs +++ b/imap/src/client/codec.rs @@ -2,12 +2,11 @@ use std::io::{self}; use bytes::{BufMut, BytesMut}; use nom::Needed; -use panorama_proto_common::Bytes; +use panorama_proto_common::{convert_error, Bytes}; use tokio_util::codec::{Decoder, Encoder}; use crate::proto::{ command::Command, - convert_error::convert_error, response::{Response, Tag}, rfc3501::response as parse_response, }; diff --git a/imap/src/proto/mod.rs b/imap/src/proto/mod.rs index 490ba2e..042a842 100644 --- a/imap/src/proto/mod.rs +++ b/imap/src/proto/mod.rs @@ -2,11 +2,6 @@ #![allow(non_snake_case, dead_code)] -// utils -#[macro_use] -mod macros; -pub mod convert_error; - // data types pub mod command; pub mod response; diff --git a/imap/src/proto/response.rs b/imap/src/proto/response.rs index 202ac8f..2b60221 100644 --- a/imap/src/proto/response.rs +++ b/imap/src/proto/response.rs @@ -166,4 +166,4 @@ pub enum MailboxListFlag { Marked, Unmarked, Extension(Atom), -} \ No newline at end of file +} diff --git a/imap/src/proto/test_rfc3501.rs b/imap/src/proto/test_rfc3501.rs index 2b96388..17531a5 100644 --- a/imap/src/proto/test_rfc3501.rs +++ b/imap/src/proto/test_rfc3501.rs @@ -26,10 +26,10 @@ fn test_list() { flags, delimiter: Some(b'.'), mailbox: Mailbox::Name(mailbox), - }) ) if flags.len() == 3 && - flags.contains(&MailboxListFlag::Extension(Atom::from(b"HasChildren"))) && - flags.contains(&MailboxListFlag::Extension(Atom::from(b"UnMarked"))) && - flags.contains(&MailboxListFlag::Extension(Atom::from(b"Trash"))) && + }) ) if flags.len() == 3 && + flags.contains(&MailboxListFlag::Extension(Atom::from(b"HasChildren"))) && + flags.contains(&MailboxListFlag::Extension(Atom::from(b"UnMarked"))) && + flags.contains(&MailboxListFlag::Extension(Atom::from(b"Trash"))) && &*mailbox == &b"Trash"[..] )); } diff --git a/proto-common/Cargo.toml b/proto-common/Cargo.toml index 9742cc0..9ff560d 100644 --- a/proto-common/Cargo.toml +++ b/proto-common/Cargo.toml @@ -10,6 +10,8 @@ workspace = ".." [dependencies] anyhow = "1.0.42" +bstr = "0.2.15" bytes = "1.0.1" format-bytes = "0.2.2" -nom = "6.2.1" +log = "0.4.14" +nom = "6.2.1" \ No newline at end of file diff --git a/imap/src/proto/convert_error.rs b/proto-common/src/convert_error.rs similarity index 100% rename from imap/src/proto/convert_error.rs rename to proto-common/src/convert_error.rs diff --git a/proto-common/src/lib.rs b/proto-common/src/lib.rs index 060e752..c7571de 100644 --- a/proto-common/src/lib.rs +++ b/proto-common/src/lib.rs @@ -1,10 +1,15 @@ #[macro_use] extern crate anyhow; +#[macro_use] +extern crate log; mod bytes; +mod convert_error; mod formatter; mod parsers; +mod rule; pub use crate::bytes::{Bytes, ShitCompare, ShitNeededForParsing}; +pub use crate::convert_error::convert_error; pub use crate::formatter::quote_string; pub use crate::parsers::{byte, never, parse_u32, satisfy, skip, tagi, take, take_while1, VResult}; diff --git a/imap/src/proto/macros.rs b/proto-common/src/rule.rs similarity index 67% rename from imap/src/proto/macros.rs rename to proto-common/src/rule.rs index de289b5..be0566b 100644 --- a/imap/src/proto/macros.rs +++ b/proto-common/src/rule.rs @@ -1,3 +1,7 @@ +use crate::{Bytes, VResult}; + +/// Defines a new parser rule that operates on [`Bytes`] and produces a [`VResult`]. +#[macro_export] macro_rules! rule { ($vis:vis $name:ident : $ret:ty => $expr:expr) => { $vis fn $name ( diff --git a/smtp/src/proto/rfc5321.rs b/smtp/src/proto/rfc5321.rs index 77d3700..9ccdb1c 100644 --- a/smtp/src/proto/rfc5321.rs +++ b/smtp/src/proto/rfc5321.rs @@ -1,4 +1,5 @@ //! SMTP Specification //! --- //! -//! Grammar from \ No newline at end of file +//! Grammar from +