From beab67b2e38808f91ecd390190d527fc7db5499d Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 23 Feb 2025 12:14:27 +0100 Subject: call receive tool --- sip/examples/server.rs | 19 ++++--------------- sip/src/encoding/headers.rs | 2 +- sip/src/transport/mod.rs | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) (limited to 'sip') diff --git a/sip/examples/server.rs b/sip/examples/server.rs index 02c06b4..859c35e 100644 --- a/sip/examples/server.rs +++ b/sip/examples/server.rs @@ -47,7 +47,10 @@ async fn handle_client(stream: TcpStream, addr: SocketAddr) -> Result<()> { let to: To = req.headers.get_res()?; let via: Via = req.headers.get_res()?; let contact: Contact = req.headers.get_res()?; - info!("Registered {}", contact.uri.localpart.as_ref().unwrap()); + info!( + "({addr}) Registered {}", + contact.uri.localpart.as_ref().unwrap() + ); tu.respond( &req, @@ -67,17 +70,3 @@ async fn handle_client(stream: TcpStream, addr: SocketAddr) -> Result<()> { if req.method == Method::Invite {} } } - -/* -[2024-07-05T22:22:40Z DEBUG sip::transport::udp] SIP/2.0 200 OK - Via: SIP/2.0/UDP 198.18.1.135:52125;branch=Uz7r7ysvrS91q9j9;rport=52125 - Contact: ;expires=379;+sip.instance="" - Contact: ;expires=411 - Contact: ;expires=600 - To: ;tag=81756f4e - From: ;tag=-AK4OkphTFVZv50h - Call-ID: U3Fyb6vT1BhWxiKG - CSeq: 1 REGISTER - User-Agent: AGFEO SIP V3.00.15 n (MAC=00094070069C) - Content-Length: 0 -*/ diff --git a/sip/src/encoding/headers.rs b/sip/src/encoding/headers.rs index e880739..30587c7 100644 --- a/sip/src/encoding/headers.rs +++ b/sip/src/encoding/headers.rs @@ -140,7 +140,7 @@ pub fn unquote(v: &str) -> Result { .to_string()) } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Contact { pub display_name: Option, pub uri: Uri, diff --git a/sip/src/transport/mod.rs b/sip/src/transport/mod.rs index b4c512b..b9cdaeb 100644 --- a/sip/src/transport/mod.rs +++ b/sip/src/transport/mod.rs @@ -1,5 +1,7 @@ use crate::encoding::Message; use anyhow::Result; +use tcp::TcpTransport; +use udp::UdpTransport; pub mod tcp; pub mod udp; @@ -9,3 +11,22 @@ pub trait Transport { async fn recv(&self) -> Result; async fn send(&self, message: Message) -> Result<()>; } + +pub enum InetTransport { + Udp(UdpTransport), + Tcp(TcpTransport), +} +impl Transport for InetTransport { + async fn recv(&self) -> Result { + match self { + InetTransport::Udp(t) => t.recv().await, + InetTransport::Tcp(t) => t.recv().await, + } + } + async fn send(&self, message: Message) -> Result<()> { + match self { + InetTransport::Udp(t) => t.send(message).await, + InetTransport::Tcp(t) => t.send(message).await, + } + } +} -- cgit v1.2.3-70-g09d2