Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/dialog/client_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,18 @@ impl ClientInviteDialog {
return Ok(());
}
info!(id=%self.id(),"sending cancel request");
let mut cancel_request = self.inner.initial_request.clone();
let mut cancel_request = self
.inner
.initial_request
.lock()
.expect("cancel mutext poisoned")
.clone();
let invite_seq = cancel_request.cseq_header()?.seq()?;
cancel_request
.headers_mut()
.retain(|h| !matches!(h, Header::ContentLength(_) | Header::ContentType(_)));

cancel_request
.to_header_mut()?
.mut_tag(self.id().to_tag.clone().into())?; // ensure to-tag has tag param

cancel_request.method = rsip::Method::Cancel;
let invite_seq = self.inner.initial_request.cseq_header()?.seq()?;
cancel_request
.cseq_header_mut()?
.mut_seq(invite_seq)?
Expand Down Expand Up @@ -539,6 +540,15 @@ impl ClientInviteDialog {
.await?;
tx.send().await?;
self.inner.update_remote_tag("").ok();
// Update initial_request with the new invite request
{
let mut req = self
.inner
.initial_request
.lock()
.expect("update initial request mutex poisoned");
*req = tx.original.clone();
}
continue;
} else {
info!(id=%self.id(),"received 407 response without auth option");
Expand Down
11 changes: 8 additions & 3 deletions src/dialog/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ pub struct DialogInner {
pub(super) endpoint_inner: EndpointInnerRef,
pub(super) state_sender: DialogStateSender,
pub(super) tu_sender: TransactionEventSender,
pub(super) initial_request: Request,
// initial request updated when INVITE auth failed with new INVITE
pub(super) initial_request: Mutex<Request>,
pub(super) supports_100rel: bool,
pub(super) remote_reliable: Mutex<Option<RemoteReliableState>>,
}
Expand Down Expand Up @@ -285,7 +286,7 @@ impl DialogInner {
state_sender,
tu_sender,
state: Mutex::new(DialogState::Calling(id)),
initial_request,
initial_request: Mutex::new(initial_request),
local_contact,
remote_contact: Mutex::new(None),
supports_100rel,
Expand Down Expand Up @@ -512,7 +513,11 @@ impl DialogInner {

pub(super) fn build_vias_from_request(&self) -> Result<Vec<Via>> {
let mut vias = vec![];
for header in self.initial_request.headers.iter() {
let initial_request = self
.initial_request
.lock()
.expect("build vias from request poisoned mutex");
for header in initial_request.headers.iter() {
if let Header::Via(via) = header {
if let Ok(mut typed_via) = via.typed() {
for param in typed_via.params.iter_mut() {
Expand Down
21 changes: 11 additions & 10 deletions src/dialog/server_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ impl ServerInviteDialog {
/// Returns a reference to the initial INVITE request that created
/// this dialog. This can be used to access the original request
/// headers, body, and other information.
pub fn initial_request(&self) -> &Request {
&self.inner.initial_request
pub fn initial_request(&self) -> Request {
self.inner
.initial_request
.lock()
.expect("get initial request posioned")
.clone()
}

pub fn ringing(&self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>) -> Result<()> {
Expand All @@ -126,7 +130,7 @@ impl ServerInviteDialog {
}
info!(id = %self.id(), "sending ringing response");
let resp = self.inner.make_response(
&self.inner.initial_request,
&self.initial_request(),
if body.is_some() {
StatusCode::SessionProgress
} else {
Expand Down Expand Up @@ -173,12 +177,9 @@ impl ServerInviteDialog {
/// # }
/// ```
pub fn accept(&self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>) -> Result<()> {
let resp = self.inner.make_response(
&self.inner.initial_request,
rsip::StatusCode::OK,
headers,
body,
);
let resp =
self.inner
.make_response(&self.initial_request(), rsip::StatusCode::OK, headers, body);
self.inner
.tu_sender
.send(TransactionEvent::Respond(resp.clone()))?;
Expand Down Expand Up @@ -290,7 +291,7 @@ impl ServerInviteDialog {
None
};
let resp = self.inner.make_response(
&self.inner.initial_request,
&self.initial_request(),
code.unwrap_or(rsip::StatusCode::Decline),
headers,
None,
Expand Down