Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 169 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion smb-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ edition = "2024"
[dependencies]
uuid = "1.3.0"
serde = { version = "1.0.144", features = ["derive"] }
num_enum = "0.5.7"
num_enum = "0.5.7"
tracing = { version = "0.1", optional = true }

[features]
tracing = ["dep:tracing"]
logging = ["tracing/log"]
8 changes: 1 addition & 7 deletions smb-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use uuid::Uuid;
use error::SMBError;

pub mod error;
pub mod logging;

pub mod nt_status;

Expand All @@ -31,18 +32,12 @@ impl<T: SMBByteSize> SMBVecByteSize for Vec<T> {
fn smb_byte_size_vec(&self, align: usize, start: usize) -> usize {
let align = std::cmp::max(align, 1);
self.iter().fold(start, |prev, x| {
if align > 1 {
// println!("Start position for item at {prev} with align {align}");
}
let size = x.smb_byte_size();
let aligned_start = if prev % align == 0 {
prev
} else {
prev + (align - prev % align)
};
if align > 1 {
// println!("adj Start position for item at {aligned_start} with align {align} and size {size}");
}
aligned_start + size
}) - start
}
Expand Down Expand Up @@ -96,7 +91,6 @@ pub trait SMBEnumFromBytes {

impl<T: SMBFromBytes> SMBVecFromBytesCnt for Vec<T> {
fn smb_from_bytes_vec_cnt(input: &[u8], align: usize, count: usize) -> SMBParseResult<&[u8], Self> where Self: Sized {
// println!("attempting to parse {:?}", count);
let mut remaining = input;
let mut done_cnt = 0;
let mut msg_vec = Vec::<T>::new();
Expand Down
58 changes: 58 additions & 0 deletions smb-core/src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// Feature-gated logging macros.
///
/// When the `tracing` feature is enabled, these re-export the corresponding
/// macros from the `tracing` crate. When disabled, they compile to no-ops.

#[cfg(feature = "tracing")]
pub use tracing::{trace, debug, info, warn, error, info_span, debug_span, trace_span};

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! trace {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! debug {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! info {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! warn {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! error {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! info_span {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! debug_span {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
#[macro_export]
macro_rules! trace_span {
($($t:tt)*) => {()};
}

#[cfg(not(feature = "tracing"))]
pub use crate::{trace, debug, info, warn, error, info_span, debug_span, trace_span};
Loading
Loading