aboutsummaryrefslogtreecommitdiff
path: root/src/encoding
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-06 17:37:35 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-06 17:37:35 +0200
commit7aa211a8d7ae2efeebd9362699a1aea4b5690e3d (patch)
treee0af8720ee3b770688600a8ea025de2ce81e5017 /src/encoding
parent7177367ae41a5e2d6ed401f60ee1455812dd8ffb (diff)
downloadsip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar
sip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar.bz2
sip-rs-7aa211a8d7ae2efeebd9362699a1aea4b5690e3d.tar.zst
start on sdp impl
Diffstat (limited to 'src/encoding')
-rw-r--r--src/encoding/mod.rs9
-rw-r--r--src/encoding/request.rs3
-rw-r--r--src/encoding/response.rs15
-rw-r--r--src/encoding/status.rs2
4 files changed, 25 insertions, 4 deletions
diff --git a/src/encoding/mod.rs b/src/encoding/mod.rs
index f0796c8..816aa01 100644
--- a/src/encoding/mod.rs
+++ b/src/encoding/mod.rs
@@ -35,3 +35,12 @@ impl FromStr for Message {
}
}
}
+
+impl Message {
+ pub fn body_mut(&mut self) -> &mut String {
+ match self {
+ Message::Request(r) => &mut r.body,
+ Message::Response(r) => &mut r.body,
+ }
+ }
+}
diff --git a/src/encoding/request.rs b/src/encoding/request.rs
index c62bab3..ab41b7c 100644
--- a/src/encoding/request.rs
+++ b/src/encoding/request.rs
@@ -7,6 +7,7 @@ pub struct Request {
pub method: Method,
pub uri: Uri,
pub headers: HeaderMap,
+ pub body: String,
}
impl Display for Request {
@@ -15,6 +16,7 @@ impl Display for Request {
headers,
method,
uri,
+ ..
} = self;
write!(f, "{method} {uri} SIP/2.0\r\n")?;
write!(f, "{headers}\r\n")?;
@@ -46,6 +48,7 @@ impl FromStr for Request {
let method = Method::from_str(method)?;
Ok(Self {
+ body: String::new(),
headers,
method,
uri,
diff --git a/src/encoding/response.rs b/src/encoding/response.rs
index ffd2878..0b7996c 100644
--- a/src/encoding/response.rs
+++ b/src/encoding/response.rs
@@ -6,6 +6,7 @@ use std::{fmt::Display, str::FromStr};
pub struct Response {
pub status: Status,
pub headers: HeaderMap,
+ pub body: String,
}
impl FromStr for Response {
@@ -31,14 +32,22 @@ impl FromStr for Response {
let headers = HeaderMap::parse(&mut lines)?;
let status = Status::from_code(code);
- Ok(Self { status, headers })
+ Ok(Self {
+ status,
+ headers,
+ body: String::new(),
+ })
}
}
impl Display for Response {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let Self { status, headers } = self;
+ let Self {
+ status,
+ headers,
+ body,
+ } = self;
write!(f, "SIP/2.0 {} {status:?}\r\n", status.to_code())?;
- write!(f, "{headers}\r\n")?;
+ write!(f, "{headers}\r\n{body}")?;
Ok(())
}
}
diff --git a/src/encoding/status.rs b/src/encoding/status.rs
index 9fe03d7..61b2d2a 100644
--- a/src/encoding/status.rs
+++ b/src/encoding/status.rs
@@ -1,6 +1,6 @@
macro_rules! status_enum {
($v:vis enum $name:ident { $($variant:ident = $value:literal),*, }) => {
- #[derive(Debug, Clone)]
+ #[derive(Debug, Clone, Eq, PartialEq, Hash)]
$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 } } }