From cbc111f90b5facc1f2a9dd79ced216279d6260af Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 19 Nov 2024 02:08:52 +0100 Subject: move files + rtp parser --- sip/src/encoding/mod.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sip/src/encoding/mod.rs (limited to 'sip/src/encoding/mod.rs') diff --git a/sip/src/encoding/mod.rs b/sip/src/encoding/mod.rs new file mode 100644 index 0000000..816aa01 --- /dev/null +++ b/sip/src/encoding/mod.rs @@ -0,0 +1,46 @@ +use std::{fmt::Display, str::FromStr}; + +use request::Request; +use response::Response; + +pub mod headermap; +pub mod headers; +pub mod method; +pub mod request; +pub mod response; +pub mod status; +pub mod uri; + +#[derive(Debug, Clone)] +pub enum Message { + Request(Request), + Response(Response), +} + +impl Display for Message { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Message::Request(r) => write!(f, "{r}"), + Message::Response(r) => write!(f, "{r}"), + } + } +} +impl FromStr for Message { + type Err = anyhow::Error; + fn from_str(s: &str) -> Result { + if s.starts_with("SIP/") { + Response::from_str(s).map(Message::Response) + } else { + Request::from_str(s).map(Message::Request) + } + } +} + +impl Message { + pub fn body_mut(&mut self) -> &mut String { + match self { + Message::Request(r) => &mut r.body, + Message::Response(r) => &mut r.body, + } + } +} -- cgit v1.2.3-70-g09d2