diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-22 12:25:32 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-22 12:25:32 +0100 |
commit | 622ed285b029dfa3b65cc3f13b51c1e0b83262b9 (patch) | |
tree | e6b6ba61c1824b16f1ae24059cac1499af5717ac /sip/src | |
parent | 8e19859996eee29ba28c4e4a933ba396924ac163 (diff) | |
download | sip-rs-622ed285b029dfa3b65cc3f13b51c1e0b83262b9.tar sip-rs-622ed285b029dfa3b65cc3f13b51c1e0b83262b9.tar.bz2 sip-rs-622ed285b029dfa3b65cc3f13b51c1e0b83262b9.tar.zst |
fix things
Diffstat (limited to 'sip/src')
-rw-r--r-- | sip/src/encoding/mod.rs | 7 | ||||
-rw-r--r-- | sip/src/encoding/request.rs | 3 | ||||
-rw-r--r-- | sip/src/lib.rs | 4 | ||||
-rw-r--r-- | sip/src/transport/tcp.rs | 14 |
4 files changed, 23 insertions, 5 deletions
diff --git a/sip/src/encoding/mod.rs b/sip/src/encoding/mod.rs index 816aa01..3c2f3fd 100644 --- a/sip/src/encoding/mod.rs +++ b/sip/src/encoding/mod.rs @@ -1,5 +1,6 @@ use std::{fmt::Display, str::FromStr}; +use headers::ContentLength; use request::Request; use response::Response; @@ -43,4 +44,10 @@ impl Message { Message::Response(r) => &mut r.body, } } + pub fn content_length(&self) -> Option<Result<ContentLength, anyhow::Error>> { + match self { + Message::Request(r) => r.headers.get::<ContentLength>(), + Message::Response(r) => r.headers.get::<ContentLength>(), + } + } } diff --git a/sip/src/encoding/request.rs b/sip/src/encoding/request.rs index ab41b7c..06f9f9d 100644 --- a/sip/src/encoding/request.rs +++ b/sip/src/encoding/request.rs @@ -16,10 +16,11 @@ impl Display for Request { headers, method, uri, - .. + body, } = self; write!(f, "{method} {uri} SIP/2.0\r\n")?; write!(f, "{headers}\r\n")?; + write!(f, "{body}")?; Ok(()) } } diff --git a/sip/src/lib.rs b/sip/src/lib.rs index 6c6cc3b..52f7fa7 100644 --- a/sip/src/lib.rs +++ b/sip/src/lib.rs @@ -1,4 +1,4 @@ -#![feature(iterator_try_collect)] +#![feature(iterator_try_collect, string_from_utf8_lossy_owned)] pub mod encoding; -pub mod transport; pub mod transaction; +pub mod transport; diff --git a/sip/src/transport/tcp.rs b/sip/src/transport/tcp.rs index efe433d..58dfb7e 100644 --- a/sip/src/transport/tcp.rs +++ b/sip/src/transport/tcp.rs @@ -4,7 +4,7 @@ use anyhow::Result; use log::debug; use std::str::FromStr; use tokio::{ - io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter}, + io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}, net::{ tcp::{OwnedReadHalf, OwnedWriteHalf}, TcpStream, @@ -34,8 +34,18 @@ impl Transport for TcpTransport { while !message.ends_with("\r\n\r\n") { g.read_line(&mut message).await?; } - let mesg = Message::from_str(message.trim())?; + let mut mesg = Message::from_str(message.trim())?; debug!("<- {mesg}"); + + let cl = mesg + .content_length() + .transpose()? + .map(|e| e.0) + .unwrap_or_default(); + let mut body = vec![0u8; cl]; + g.read_exact(&mut body).await?; + *mesg.body_mut() = String::from_utf8_lossy_owned(body); + Ok(mesg) } async fn send(&self, request: Message) -> Result<()> { |