aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/request.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-11-19 02:08:52 +0100
committermetamuffin <metamuffin@disroot.org>2024-11-19 02:08:52 +0100
commitcbc111f90b5facc1f2a9dd79ced216279d6260af (patch)
treefa5a1d2d67874413d8e66673825c6789e8cc0945 /src/encoding/request.rs
parent2d9a31244eab6d3a9871369d3148de253e902d36 (diff)
downloadsip-rs-cbc111f90b5facc1f2a9dd79ced216279d6260af.tar
sip-rs-cbc111f90b5facc1f2a9dd79ced216279d6260af.tar.bz2
sip-rs-cbc111f90b5facc1f2a9dd79ced216279d6260af.tar.zst
move files + rtp parser
Diffstat (limited to 'src/encoding/request.rs')
-rw-r--r--src/encoding/request.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/encoding/request.rs b/src/encoding/request.rs
deleted file mode 100644
index ab41b7c..0000000
--- a/src/encoding/request.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-use super::{headermap::HeaderMap, method::Method, uri::Uri};
-use anyhow::{anyhow, bail};
-use std::{fmt::Display, str::FromStr};
-
-#[derive(Debug, Clone)]
-pub struct Request {
- pub method: Method,
- pub uri: Uri,
- pub headers: HeaderMap,
- pub body: String,
-}
-
-impl Display for Request {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let Self {
- headers,
- method,
- uri,
- ..
- } = self;
- write!(f, "{method} {uri} SIP/2.0\r\n")?;
- write!(f, "{headers}\r\n")?;
- Ok(())
- }
-}
-impl FromStr for Request {
- type Err = anyhow::Error;
- fn from_str(s: &str) -> Result<Self, Self::Err> {
- let mut lines = s.lines();
- let statusline = lines.next().ok_or(anyhow!("status line missing"))?;
- let (method, rest) = statusline
- .split_once(" ")
- .ok_or(anyhow!("status line malformed"))?;
- let (uri, sipver) = rest
- .split_once(" ")
- .ok_or(anyhow!("status line malformed"))?;
-
- let Some(ver) = sipver.strip_prefix("SIP/") else {
- bail!("sip version malformed");
- };
- if ver != "2.0" {
- bail!("sip version {ver:?} is not supported");
- }
-
- let uri = Uri::from_str(uri)?;
-
- let headers = HeaderMap::parse(&mut lines)?;
- let method = Method::from_str(method)?;
-
- Ok(Self {
- body: String::new(),
- headers,
- method,
- uri,
- })
- }
-}