|
|
|
@ -3,34 +3,43 @@ use super::*;
|
|
|
|
|
|
|
|
|
|
pub fn feed(chain: &mut Chain<String>, what: impl AsRef<str>)
|
|
|
|
|
{
|
|
|
|
|
chain.feed(what.as_ref().split_whitespace()
|
|
|
|
|
.filter(|word| !word.is_empty())
|
|
|
|
|
.map(|s| s.to_owned()).collect::<Vec<_>>());
|
|
|
|
|
let map = what.as_ref().split_whitespace()
|
|
|
|
|
.filter(|word| !word.is_empty())
|
|
|
|
|
.map(|s| s.to_owned()).collect::<Vec<_>>();
|
|
|
|
|
if map.len() > 0 {
|
|
|
|
|
chain.feed(map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn full(who: &IpAddr, state: State, mut body: impl Unpin + Stream<Item = Result<impl Buf, impl std::error::Error + 'static>>) -> Result<usize, FillBodyError> {
|
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
|
|
|
|
|
|
let mut written = 0usize;
|
|
|
|
|
//TODO: Change to pushing lines to mpsc channel, instead of manually aggregating.
|
|
|
|
|
while let Some(buf) = body.next().await {
|
|
|
|
|
let mut body = buf.map_err(|_| FillBodyError)?;
|
|
|
|
|
while body.has_remaining() {
|
|
|
|
|
if body.bytes().len() > 0 {
|
|
|
|
|
buffer.extend_from_slice(body.bytes()); // XXX: what the fuck is wrong with this??? why it eat spaces????
|
|
|
|
|
buffer.extend_from_slice(body.bytes());
|
|
|
|
|
let cnt = body.bytes().len();
|
|
|
|
|
body.advance(cnt);
|
|
|
|
|
written += cnt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !buffer.ends_with(&[b'\n']) { // probably useless eh?
|
|
|
|
|
buffer.push(b'\n');
|
|
|
|
|
}
|
|
|
|
|
let buffer = std::str::from_utf8(&buffer[..]).map_err(|_| FillBodyError)?;
|
|
|
|
|
info!("{} -> {:?}", who, buffer);
|
|
|
|
|
let mut chain = state.chain().write().await;
|
|
|
|
|
feed(&mut chain, buffer);
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature="split-newlines")] {
|
|
|
|
|
for buffer in buffer.split('\n').filter(|line| !line.trim().is_empty()) {
|
|
|
|
|
feed(&mut chain, buffer);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
feed(&mut chain, buffer);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
state.notify_save();
|
|
|
|
|
Ok(written)
|
|
|
|
|
}
|
|
|
|
|