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 /src/encoding | |
parent | 6de0a5e827b0b18f589c28f489b4ff88169f156c (diff) | |
download | sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar.bz2 sip-rs-b5e408b02cd99a7833faab9b46d33042786c568c.tar.zst |
stuff
Diffstat (limited to 'src/encoding')
-rw-r--r-- | src/encoding/headers.rs | 4 | ||||
-rw-r--r-- | src/encoding/response.rs | 17 | ||||
-rw-r--r-- | src/encoding/status.rs | 1 |
3 files changed, 17 insertions, 5 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 } } } |