Skip to content

Commit d805d2a

Browse files
committed
fix: update version to 0.2.37 and enhance SIP connection handling
1 parent 82e8cab commit d805d2a

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsipstack"
3-
version = "0.2.36"
3+
version = "0.2.37"
44
edition = "2021"
55
description = "SIP Stack Rust library for building SIP applications"
66
license = "MIT"

src/dialog/server_dialog.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,14 @@ impl ServerInviteDialog {
176176
body,
177177
);
178178
let via = self.inner.initial_request.via_header()?;
179-
let via_received = SipConnection::parse_target_from_via(via)?;
179+
let (via_transport, via_received) = SipConnection::parse_target_from_via(via)?;
180+
let mut params = vec![];
181+
if via_transport != rsip::transport::Transport::Udp {
182+
params.push(rsip::param::Param::Transport(via_transport));
183+
}
180184
let contact = rsip::Uri {
181185
host_with_port: via_received,
182-
params: vec![rsip::Param::Transport(via.trasnport()?)],
186+
params,
183187
..Default::default()
184188
};
185189
debug!(id = %self.id(), "accepting dialog with contact: {}", contact);

src/rsip_ext.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ impl RsipResponseExt for rsip::Response {
3131
/// and returns it as a HostWithPort struct.
3232
fn via_received(&self) -> Option<rsip::HostWithPort> {
3333
let via = self.via_header().ok()?;
34-
SipConnection::parse_target_from_via(via).ok()
34+
SipConnection::parse_target_from_via(via)
35+
.map(|(_, host_with_port)| host_with_port)
36+
.ok()
3537
}
3638
fn content_type(&self) -> Option<rsip::headers::ContentType> {
3739
let headers = self.headers();

src/transport/connection.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,17 @@ impl SipConnection {
336336
typed_via.params.retain(|param| {
337337
if let Param::Other(key, _) = param {
338338
!key.value().eq_ignore_ascii_case("rport")
339+
} else if let Param::Transport(_) = param {
340+
false
339341
} else {
340342
true
341343
}
342344
});
343345

346+
if transport != rsip::transport::Transport::Udp && typed_via.transport != transport {
347+
typed_via.params.push(Param::Transport(transport));
348+
}
349+
344350
*via = typed_via
345351
.with_param(Param::Received(rsip::param::Received::new(
346352
received.host.to_string(),
@@ -353,8 +359,11 @@ impl SipConnection {
353359
Ok(())
354360
}
355361

356-
pub fn parse_target_from_via(via: &rsip::headers::untyped::Via) -> Result<rsip::HostWithPort> {
362+
pub fn parse_target_from_via(
363+
via: &rsip::headers::untyped::Via,
364+
) -> Result<(rsip::Transport, rsip::HostWithPort)> {
357365
let mut host_with_port = via.uri()?.host_with_port;
366+
let mut transport = via.trasnport().unwrap_or(rsip::Transport::Udp);
358367
if let Ok(params) = via.params().as_ref() {
359368
for param in params {
360369
match param {
@@ -363,6 +372,9 @@ impl SipConnection {
363372
host_with_port.host = addr.into();
364373
}
365374
}
375+
Param::Transport(t) => {
376+
transport = t.clone();
377+
}
366378
Param::Other(key, Some(value)) if key.value().eq_ignore_ascii_case("rport") => {
367379
if let Ok(port) = value.value().try_into() {
368380
host_with_port.port = Some(port);
@@ -372,13 +384,13 @@ impl SipConnection {
372384
}
373385
}
374386
}
375-
Ok(host_with_port)
387+
Ok((transport, host_with_port))
376388
}
377389

378390
pub fn get_destination(msg: &rsip::SipMessage) -> Result<SocketAddr> {
379391
let host_with_port = match msg {
380392
rsip::SipMessage::Request(req) => req.uri().host_with_port.clone(),
381-
rsip::SipMessage::Response(res) => Self::parse_target_from_via(res.via_header()?)?,
393+
rsip::SipMessage::Response(res) => Self::parse_target_from_via(res.via_header()?)?.1,
382394
};
383395
host_with_port.try_into().map_err(Into::into)
384396
}

src/transport/tests/test_sipaddr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn test_via_received() {
1818
body: Default::default(),
1919
};
2020

21-
let parse_addr =
21+
let (_, parse_addr) =
2222
SipConnection::parse_target_from_via(&register_req.via_header().expect("via_header"))
2323
.expect("get_target_socketaddr");
2424

@@ -38,7 +38,7 @@ fn test_via_received() {
3838

3939
match msg {
4040
SipMessage::Request(req) => {
41-
let parse_addr =
41+
let (_, parse_addr) =
4242
SipConnection::parse_target_from_via(&req.via_header().expect("via_header"))
4343
.expect("get_target_socketaddr");
4444
assert_eq!(parse_addr, addr.into());

0 commit comments

Comments
 (0)