Skip to content

Commit 1e0e1fb

Browse files
committed
bump version to 0.2.73 and refactor dialog handling by removing unused destination extraction logic
1 parent 1dda6bb commit 1e0e1fb

File tree

8 files changed

+44
-68
lines changed

8 files changed

+44
-68
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.72"
3+
version = "0.2.73"
44
edition = "2021"
55
description = "SIP Stack Rust library for building SIP applications"
66
license = "MIT"

src/dialog/client_dialog.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{
1212
};
1313
use rsip::prelude::HasHeaders;
1414
use rsip::{
15-
headers::Route,
1615
prelude::{HeadersExt, ToTypedHeader, UntypedHeader},
1716
Header,
1817
};
@@ -563,17 +562,6 @@ impl ClientInviteDialog {
563562
uri
564563
};
565564
*self.inner.remote_uri.lock().unwrap() = uri;
566-
567-
// update route set from Record-Route header
568-
let mut route_set = Vec::new();
569-
for header in resp.headers.iter() {
570-
if let Header::RecordRoute(record_route) = header {
571-
route_set.push(Route::from(record_route.value()));
572-
}
573-
}
574-
route_set.reverse();
575-
*self.inner.route_set.lock().unwrap() = route_set;
576-
577565
self.inner
578566
.transition(DialogState::Confirmed(dialog_id.clone(), resp))?;
579567
DialogInner::serve_keepalive_options(self.inner.clone());

src/dialog/dialog.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::{
55
DialogId,
66
};
77
use crate::{
8-
rsip_ext::{destination_from_request, extract_uri_from_contact},
8+
rsip_ext::extract_uri_from_contact,
99
transaction::{
1010
endpoint::EndpointInnerRef,
1111
key::{TransactionKey, TransactionRole},
@@ -239,6 +239,7 @@ impl DialogInner {
239239
route_set.push(Route::from(rr.value()));
240240
}
241241
}
242+
route_set.reverse();
242243

243244
Ok(Self {
244245
role,
@@ -472,8 +473,40 @@ impl DialogInner {
472473

473474
pub(super) async fn do_request(&self, request: Request) -> Result<Option<rsip::Response>> {
474475
let method = request.method().to_owned();
475-
let destination =
476-
destination_from_request(&request).or_else(|| self.initial_destination.clone());
476+
// request destination determination
477+
// Route header first, then remote contact, then initial request destination
478+
let mut destination = None;
479+
for h in request.headers.iter() {
480+
if let Header::Route(route) = h {
481+
let dest = route
482+
.typed()
483+
.ok()
484+
.map(|r| {
485+
r.uris()
486+
.first()
487+
.map(|u| SipAddr::try_from(&u.uri).ok())
488+
.flatten()
489+
})
490+
.flatten();
491+
if dest.is_some() {
492+
destination = dest;
493+
break;
494+
}
495+
}
496+
}
497+
498+
if destination.is_none() {
499+
destination = self
500+
.remote_contact
501+
.lock()
502+
.unwrap()
503+
.as_ref()
504+
.map(|c| extract_uri_from_contact(c.value()).ok())
505+
.flatten()
506+
.map(|u| SipAddr::try_from(&u).ok())
507+
.flatten()
508+
.or_else(|| self.initial_destination.clone());
509+
}
477510

478511
let key = TransactionKey::from_request(&request, TransactionRole::Client)?;
479512
let mut tx = Transaction::new_client(key, request, self.endpoint_inner.clone(), None);
@@ -682,6 +715,7 @@ impl Dialog {
682715
Dialog::ClientInvite(d) => d.inner.to.lock().unwrap().clone(),
683716
}
684717
}
718+
685719
pub fn remote_contact(&self) -> Option<rsip::Uri> {
686720
match self {
687721
Dialog::ServerInvite(d) => d
@@ -690,15 +724,15 @@ impl Dialog {
690724
.lock()
691725
.unwrap()
692726
.as_ref()
693-
.map(|c| c.uri().ok())
727+
.map(|c| extract_uri_from_contact(c.value()).ok())
694728
.flatten(),
695729
Dialog::ClientInvite(d) => d
696730
.inner
697731
.remote_contact
698732
.lock()
699733
.unwrap()
700734
.as_ref()
701-
.map(|c| c.uri().ok())
735+
.map(|c| extract_uri_from_contact(c.value()).ok())
702736
.flatten(),
703737
}
704738
}

src/dialog/dialog_layer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl DialogLayer {
149149
tx: &Transaction,
150150
state_sender: DialogStateSender,
151151
credential: Option<Credential>,
152-
contact: Option<rsip::Uri>,
152+
local_contact: Option<rsip::Uri>,
153153
) -> Result<ServerInviteDialog> {
154154
let mut id = DialogId::try_from(&tx.original)?;
155155
if !id.to_tag.is_empty() {
@@ -174,7 +174,7 @@ impl DialogLayer {
174174
self.endpoint.clone(),
175175
state_sender,
176176
credential,
177-
contact,
177+
local_contact,
178178
tx.tu_sender.clone(),
179179
)?;
180180

@@ -186,7 +186,7 @@ impl DialogLayer {
186186
.write()
187187
.unwrap()
188188
.insert(id.clone(), Dialog::ServerInvite(dialog.clone()));
189-
info!("server invite dialog created: {id}");
189+
info!(%id, "server invite dialog created");
190190
Ok(dialog)
191191
}
192192

src/dialog/server_dialog.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,6 @@ impl ServerInviteDialog {
680680
break;
681681
}
682682
info!(id = %self.id(),"received ack {}", req.uri);
683-
match req.contact_header() {
684-
Ok(contact) => {
685-
self.inner
686-
.remote_contact
687-
.lock()
688-
.unwrap()
689-
.replace(contact.clone());
690-
}
691-
_ => {}
692-
}
693-
694683
self.inner.transition(DialogState::Confirmed(
695684
self.id(),
696685
tx.last_response.clone().unwrap_or_default(),

src/dialog/tests/test_client_dialog.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::dialog::{
77
dialog::{DialogInner, DialogState, TerminatedReason},
88
DialogId,
99
};
10-
use crate::rsip_ext::destination_from_request;
1110
use crate::transaction::{endpoint::EndpointBuilder, key::TransactionRole};
1211
use crate::transport::{SipAddr, TransportLayer};
1312
use rsip::{headers::*, Request, Response, StatusCode, Uri};
@@ -356,15 +355,5 @@ async fn test_make_request_preserves_remote_target_and_route_order() -> crate::R
356355
],
357356
"Route headers must match the stored route set order"
358357
);
359-
360-
let destination = destination_from_request(&request)
361-
.expect("route-enabled request should resolve to a destination");
362-
let expected_destination =
363-
SipAddr::try_from(&Uri::try_from("sip:proxy2.example.com:5070;transport=tcp")?)?;
364-
assert_eq!(
365-
destination, expected_destination,
366-
"First Route entry must determine the transport destination"
367-
);
368-
369358
Ok(())
370359
}

src/rsip_ext.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::transport::{SipAddr, SipConnection};
1+
use crate::transport::SipConnection;
22
use crate::{Error, Result};
33
use rsip::{
44
message::HasHeaders,
@@ -116,24 +116,6 @@ fn apply_tokenizer_params(uri: &mut rsip::Uri, tokenizer: &CustomContactTokenize
116116
}
117117
}
118118

119-
pub fn destination_from_request(request: &rsip::Request) -> Option<SipAddr> {
120-
request
121-
.headers
122-
.iter()
123-
.find_map(|header| match header {
124-
rsip::Header::Route(route) => {
125-
let uri_str = route.value().to_string();
126-
let trimmed = uri_str.trim();
127-
let without_brackets = trimmed.trim_matches(['<', '>']);
128-
rsip::Uri::try_from(without_brackets)
129-
.ok()
130-
.and_then(|uri| SipAddr::try_from(&uri).ok())
131-
}
132-
_ => None,
133-
})
134-
.or_else(|| SipAddr::try_from(&request.uri).ok())
135-
}
136-
137119
use nom::{
138120
branch::alt,
139121
bytes::complete::{is_not, take_until},

src/transaction/transaction.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::endpoint::EndpointInnerRef;
22
use super::key::TransactionKey;
33
use super::{SipConnection, TransactionState, TransactionTimer, TransactionType};
44
use crate::dialog::DialogId;
5-
use crate::rsip_ext::destination_from_request;
65
use crate::transaction::make_tag;
76
use crate::transport::SipAddr;
87
use crate::{Error, Result};
@@ -454,11 +453,6 @@ impl Transaction {
454453
} else {
455454
ack.to_owned().into()
456455
};
457-
if let SipMessage::Request(ref req) = ack {
458-
if let Some(destination) = destination_from_request(req) {
459-
self.destination = Some(destination);
460-
}
461-
}
462456
match ack.clone() {
463457
SipMessage::Request(ack) => self.last_ack.replace(ack),
464458
_ => None,

0 commit comments

Comments
 (0)