aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-06 15:43:45 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-06 15:43:45 +0200
commit7177367ae41a5e2d6ed401f60ee1455812dd8ffb (patch)
tree75c89835d03e1a1ccd4e8c930c95310f757b2b3a /src/encoding
parent5dd0fafce20ed37fdc97dc96539391ebdebffaff (diff)
downloadsip-rs-7177367ae41a5e2d6ed401f60ee1455812dd8ffb.tar
sip-rs-7177367ae41a5e2d6ed401f60ee1455812dd8ffb.tar.bz2
sip-rs-7177367ae41a5e2d6ed401f60ee1455812dd8ffb.tar.zst
phone is ringing
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/headermap.rs3
-rw-r--r--src/encoding/headers.rs36
2 files changed, 36 insertions, 3 deletions
diff --git a/src/encoding/headermap.rs b/src/encoding/headermap.rs
index 5d1fa0a..01e1962 100644
--- a/src/encoding/headermap.rs
+++ b/src/encoding/headermap.rs
@@ -25,6 +25,9 @@ impl HeaderMap {
pub fn get<H: Header>(&self) -> Option<Result<H>> {
self.get_raw(H::NAME).map(H::from_str)
}
+ pub fn get_res<H: Header>(&self) -> Result<H> {
+ self.get().ok_or(anyhow!("{} header missing", H::NAME))?
+ }
pub fn insert_raw(&mut self, key: String, value: String) {
self.0.push((key, value))
}
diff --git a/src/encoding/headers.rs b/src/encoding/headers.rs
index 9e785f0..afcfef1 100644
--- a/src/encoding/headers.rs
+++ b/src/encoding/headers.rs
@@ -1,4 +1,4 @@
-use super::{headermap::HeaderMap, method::Method};
+use super::{headermap::HeaderMap, method::Method, uri::Uri};
use anyhow::{anyhow, bail, Result};
use std::{fmt::Display, str::FromStr};
@@ -31,7 +31,6 @@ header!("Content-Length", struct ContentLength(usize));
header!("Content-Type", struct ContentType(String));
header!("Call-ID", struct CallID(String));
header!("Via", struct Via(String));
-header!("Contact", struct Contact(String));
header!("Max-Forwards", struct MaxForwards(usize));
header!("From", struct From(String));
header!("To", struct To(String));
@@ -100,7 +99,7 @@ impl FromStr for WWWAuthenticate {
}
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct Authorization {
pub username: String,
pub realm: String,
@@ -140,3 +139,34 @@ pub fn unquote(v: &str) -> Result<String> {
.ok_or(anyhow!("end quote missing"))?
.to_string())
}
+
+#[derive(Debug)]
+pub struct Contact {
+ pub display_name: Option<String>,
+ pub uri: Uri,
+ pub params: String,
+}
+
+impl Header for Contact {
+ const NAME: &'static str = "Contact";
+}
+impl Display for Contact {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ let Self {
+ display_name,
+ uri,
+ params,
+ } = self;
+ if let Some(display_name) = display_name {
+ write!(f, "{display_name} <{uri}>{params}")
+ } else {
+ write!(f, "<{uri}>{params}")
+ }
+ }
+}
+impl FromStr for Contact {
+ type Err = anyhow::Error;
+ fn from_str(_s: &str) -> Result<Self, Self::Err> {
+ todo!()
+ }
+}