diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-05 16:14:41 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-05 16:14:41 +0200 |
commit | b5e408b02cd99a7833faab9b46d33042786c568c (patch) | |
tree | 143d99f54fb7412a82640a0c4a0ab1190f47f2ef | |
parent | 6de0a5e827b0b18f589c28f489b4ff88169f156c (diff) | |
download | sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar.bz2 sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar.zst |
stuff
-rw-r--r-- | src/encoding/headers.rs | 4 | ||||
-rw-r--r-- | src/encoding/response.rs | 17 | ||||
-rw-r--r-- | src/encoding/status.rs | 1 | ||||
-rw-r--r-- | src/transport/tcp.rs | 4 |
4 files changed, 19 insertions, 7 deletions
diff --git a/src/encoding/headers.rs b/src/encoding/headers.rs index e9196d1..b45cfd5 100644 --- a/src/encoding/headers.rs +++ b/src/encoding/headers.rs @@ -108,6 +108,7 @@ impl FromStr for WWWAuthenticate { pub struct Authorization { pub username: String, pub realm: String, + pub uri: String, pub nonce: String, pub response: String, } @@ -120,11 +121,12 @@ impl Display for Authorization { username, realm, nonce, + uri, response, } = self; write!( f, - "Digest username={username:?} realm={realm:?}, nonce={nonce:?}, response={response:?}" + "Digest username={username:?} realm={realm:?}, nonce={nonce:?}, uri={uri:?}, response={response:?}" ) } } diff --git a/src/encoding/response.rs b/src/encoding/response.rs index 3564b34..7ee124f 100644 --- a/src/encoding/response.rs +++ b/src/encoding/response.rs @@ -1,10 +1,10 @@ -use super::headermap::HeaderMap; +use super::{headermap::HeaderMap, status::Status}; use anyhow::{anyhow, bail, Context}; -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; #[derive(Debug)] pub struct Response { - pub code: u16, + pub status: Status, pub headers: HeaderMap, } @@ -35,6 +35,15 @@ impl FromStr for Response { headers.insert_raw(key.trim().to_string(), value.trim().to_string()) } - Ok(Self { code, headers }) + let status = Status::from_code(code); + Ok(Self { status, headers }) + } +} +impl Display for Response { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { status, headers } = self; + write!(f, "SIP/2.0 {} {status:?}\r\n", status.to_code())?; + write!(f, "{headers}\r\n")?; + Ok(()) } } diff --git a/src/encoding/status.rs b/src/encoding/status.rs index de9ea88..f06110d 100644 --- a/src/encoding/status.rs +++ b/src/encoding/status.rs @@ -1,6 +1,7 @@ macro_rules! status_enum { ($v:vis enum $name:ident { $($variant:ident = $value:literal),*, }) => { + #[derive(Debug)] $v enum $name { $($variant),*, Other(u16) } impl $name { pub fn from_code(c: u16) -> Self { match c { $($value => Self::$variant),*, x => Self::Other(x) } } } impl $name { pub fn to_code(&self) -> u16 { match self { $(Self::$variant => $value),*, Self::Other(x) => *x } } } diff --git a/src/transport/tcp.rs b/src/transport/tcp.rs index e196db3..f5986b9 100644 --- a/src/transport/tcp.rs +++ b/src/transport/tcp.rs @@ -32,7 +32,7 @@ impl TcpTransport { sock.read_line(&mut message).await.unwrap(); } let mesg = Response::from_str(message.trim()).unwrap(); - debug!("<- {mesg:?}"); + debug!("<- {mesg}"); tx.send(mesg).await.unwrap(); message.clear(); } @@ -49,7 +49,7 @@ impl Transport for TcpTransport { self.read.lock().await.recv().await.ok_or(anyhow!("end")) } async fn send(&self, request: Request) -> Result<()> { - debug!("-> {request:?}"); + debug!("-> {request}"); let mut g = self.write.lock().await; g.write_all(format!("{request}").as_bytes()).await?; g.flush().await?; |