Skip to content

Commit 52fcdbe

Browse files
committed
feat: enhance dialog handling by adding initial destination and refining request cancellation
1 parent aee7099 commit 52fcdbe

File tree

4 files changed

+25
-16
lines changed

4 files changed

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

src/dialog/client_dialog.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
},
1111
rsip_ext::extract_uri_from_contact,
1212
};
13+
use rsip::prelude::HasHeaders;
1314
use rsip::{
1415
headers::Route,
1516
prelude::{HeadersExt, ToTypedHeader, UntypedHeader},
@@ -199,13 +200,21 @@ impl ClientInviteDialog {
199200
}
200201
info!(id=%self.id(),"sending cancel request");
201202
let mut cancel_request = self.inner.initial_request.clone();
203+
cancel_request
204+
.headers_mut()
205+
.retain(|h| !matches!(h, Header::ContentLength(_) | Header::ContentType(_)));
206+
202207
cancel_request.method = rsip::Method::Cancel;
208+
209+
let mut to = cancel_request.to_header_mut()?.typed()?;
210+
to.params.retain(|p| !matches!(p, rsip::Param::Tag(_)));
211+
cancel_request.to_header_mut()?.replace(to);
203212
cancel_request
204213
.cseq_header_mut()?
205214
.mut_seq(self.inner.get_local_seq())?
206215
.mut_method(rsip::Method::Cancel)?;
207216
cancel_request.body = vec![];
208-
cancel_request.to_header_mut()?.mut_tag("".into())?;
217+
209218
self.inner.do_request(cancel_request).await?;
210219
Ok(())
211220
}

src/dialog/dialog.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
make_via_branch,
1313
transaction::{Transaction, TransactionEventSender},
1414
},
15+
transport::SipAddr,
1516
Result,
1617
};
1718
use rsip::{
@@ -183,6 +184,7 @@ pub struct DialogInner {
183184
pub(super) state_sender: DialogStateSender,
184185
pub(super) tu_sender: TransactionEventSender,
185186
pub(super) initial_request: Request,
187+
pub(super) initial_destination: Option<SipAddr>,
186188
}
187189

188190
pub type DialogStateReceiver = UnboundedReceiver<DialogState>;
@@ -259,6 +261,7 @@ impl DialogInner {
259261
tu_sender,
260262
state: Mutex::new(DialogState::Calling(id)),
261263
initial_request,
264+
initial_destination: None,
262265
local_contact,
263266
remote_contact: Mutex::new(None),
264267
})
@@ -456,21 +459,17 @@ impl DialogInner {
456459

457460
pub(super) async fn do_request(&self, request: Request) -> Result<Option<rsip::Response>> {
458461
let method = request.method().to_owned();
459-
let mut destination = request.route_header().and_then(|r| {
460-
r.typed()
461-
.ok()
462-
.and_then(|r| r.uris().first().map(|u| u.uri.clone()))
463-
});
464-
465-
if destination.is_none() {
466-
if let Some(contact) = self.remote_contact.lock().unwrap().as_ref() {
467-
destination = contact.uri().ok();
468-
}
469-
}
462+
let destination = self
463+
.remote_contact
464+
.lock()
465+
.unwrap()
466+
.as_ref()
467+
.and_then(|c| c.uri().ok().as_ref()?.try_into().ok())
468+
.or_else(|| self.initial_destination.clone());
470469

471470
let key = TransactionKey::from_request(&request, TransactionRole::Client)?;
472471
let mut tx = Transaction::new_client(key, request, self.endpoint_inner.clone(), None);
473-
tx.destination = destination.as_ref().map(|d| d.try_into().ok()).flatten();
472+
tx.destination = destination;
474473

475474
match tx.send().await {
476475
Ok(_) => {
@@ -576,7 +575,7 @@ impl DialogInner {
576575
}
577576
_ => {}
578577
}
579-
info!("transitioning state: {} -> {}", old_state, state);
578+
debug!("transitioning state: {} -> {}", old_state, state);
580579
*old_state = state;
581580
Ok(())
582581
}

src/dialog/invitation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl DialogLayer {
376376
tx.destination = opt.destination;
377377

378378
let id = DialogId::try_from(&request)?;
379-
let dlg_inner = DialogInner::new(
379+
let mut dlg_inner = DialogInner::new(
380380
TransactionRole::Client,
381381
id.clone(),
382382
request.clone(),
@@ -386,6 +386,7 @@ impl DialogLayer {
386386
Some(opt.contact),
387387
tx.tu_sender.clone(),
388388
)?;
389+
dlg_inner.initial_destination = tx.destination.clone();
389390

390391
let dialog = ClientInviteDialog {
391392
inner: Arc::new(dlg_inner),

0 commit comments

Comments
 (0)