|
|
@ -1,13 +1,22 @@
|
|
|
|
//! Feeding the chain
|
|
|
|
//! Feeding the chain
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn feed(chain: &mut Chain<String>, what: impl AsRef<str>)
|
|
|
|
const FEED_BOUNDS: std::ops::RangeFrom<usize> = 2..; //TODO: Add to config somehow
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn feed(chain: &mut Chain<String>, what: impl AsRef<str>, bounds: impl std::ops::RangeBounds<usize>) -> bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let map = what.as_ref().split_whitespace()
|
|
|
|
let map = what.as_ref().split_whitespace()
|
|
|
|
.filter(|word| !word.is_empty())
|
|
|
|
.filter(|word| !word.is_empty())
|
|
|
|
.map(|s| s.to_owned()).collect::<Vec<_>>();
|
|
|
|
.map(|s| s.to_owned()).collect::<Vec<_>>();
|
|
|
|
if map.len() > 0 {
|
|
|
|
debug_assert!(!bounds.contains(&0), "Cannot allow 0 size feeds");
|
|
|
|
|
|
|
|
if bounds.contains(&map.len()) {
|
|
|
|
chain.feed(map);
|
|
|
|
chain.feed(map);
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
debug!("Ignoring feed of invalid length {}", map.len());
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -38,10 +47,10 @@ pub async fn full(who: &IpAddr, state: State, body: impl Unpin + Stream<Item = R
|
|
|
|
cfg_if! {
|
|
|
|
cfg_if! {
|
|
|
|
if #[cfg(feature="split-newlines")] {
|
|
|
|
if #[cfg(feature="split-newlines")] {
|
|
|
|
for buffer in buffer.split('\n').filter(|line| !line.trim().is_empty()) {
|
|
|
|
for buffer in buffer.split('\n').filter(|line| !line.trim().is_empty()) {
|
|
|
|
feed(&mut chain, buffer);
|
|
|
|
feed(&mut chain, buffer, FEED_BOUNDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
feed(&mut chain, buffer);
|
|
|
|
feed(&mut chain, buffer, FEED_BOUNDS);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -59,7 +68,7 @@ pub async fn full(who: &IpAddr, state: State, body: impl Unpin + Stream<Item = R
|
|
|
|
#[cfg(not(feature="hog-buffer"))]
|
|
|
|
#[cfg(not(feature="hog-buffer"))]
|
|
|
|
let mut chain = state.chain().write().await; // Acquire mutex once per line? Is this right?
|
|
|
|
let mut chain = state.chain().write().await; // Acquire mutex once per line? Is this right?
|
|
|
|
|
|
|
|
|
|
|
|
feed(&mut chain, line);
|
|
|
|
feed(&mut chain, line, FEED_BOUNDS);
|
|
|
|
info!("{} -> {:?}", who, line);
|
|
|
|
info!("{} -> {:?}", who, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
written+=line.len();
|
|
|
|
written+=line.len();
|
|
|
|