From: Ian Jackson Date: Sun, 8 Aug 2021 16:42:01 +0000 (+0100) Subject: server: wip, parse disposition X-Git-Tag: hippotat/1.0.0~208 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=ca0b1efe27fcc222e5a9c6c0fedf15aa8a15607c;p=hippotat.git server: wip, parse disposition Signed-off-by: Ian Jackson --- diff --git a/src/bin/server.rs b/src/bin/server.rs index dfee819..816ae0c 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -61,17 +61,11 @@ async fn handle( else if let Some(start) = find_iter.next() { start + boundary.len() } else { throw!(anyhow!("initial boundary not found")) }; + let comp = multipart::process_component + (&mut warnings, &initial[start..], PartName::m)?; -/* - let comp = multipart::process_component( - - if { - -initial[start..].strip_prefixstarts_with(b"\n") - || initial[start..].starts_with(b"\r\n")*/ - - eprintln!("boundary={:?} initial={:?} start={}", - boundary, initial, start); + eprintln!("boundary={:?} initial={:?} start={} comp={:?}", + boundary, initial, start, &comp); Ok::<_,AE>(()) }.await { diff --git a/src/multipart.rs b/src/multipart.rs index 877d83a..82ce4ac 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -4,6 +4,7 @@ use crate::prelude::*; +#[derive(Debug)] pub struct Component<'b> { pub name: PartName, pub payload_start: &'b [u8], @@ -41,6 +42,13 @@ pub fn process_component<'b>(warnings: &mut Warnings, regex_captures!(r#"^Content-Disposition[ \t]*:[ \t]*(.*)$"#i, l) { y } else { return Ok(()) }; + let disposition = disposition.trim_end(); + if disposition.len() >= 100 { throw!(anyhow!( + "Content-Disposition value implausibly long" + )) } + // This let's us pretend it's a mime type, so we can use mime::Mime + let disposition = format!("dummy/{}", disposition); + let disposition: mime::Mime = disposition.parse() .context("parse Content-Disposition")?; let name = disposition.get_param("name") diff --git a/src/prelude.rs b/src/prelude.rs index f3e0de2..f3d823c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -55,6 +55,7 @@ pub use eyre::Error as AE; pub use crate::config::{self, InstanceConfig, u32Ext as _}; pub use crate::ini; pub use crate::ipif::Ipif; +pub use crate::multipart::{self, PartName}; pub use crate::utils::*; pub use crate::queue::*; pub use crate::reporter::*;