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
9 changes: 3 additions & 6 deletions src/dialog/client_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,20 +471,17 @@ impl ClientInviteDialog {
///
/// # Parameters
///
/// * `refer_to` - The URI to refer to (Refer-To header value)
/// * `refer_to` - The full Refer-To header value. `Uri` inputs are serialized as `<uri>`.
/// * `headers` - Optional additional headers
/// * `body` - Optional message body
pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::Other(
"Refer-To".into(),
format!("<{}>", refer_to),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ impl Dialog {

pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
Expand Down
12 changes: 4 additions & 8 deletions src/dialog/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ impl ClientPublicationDialog {

pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::ReferTo(
format!("<{}>", refer_to).into(),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down Expand Up @@ -229,14 +227,12 @@ impl ServerPublicationDialog {

pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::ReferTo(
format!("<{}>", refer_to).into(),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down
7 changes: 2 additions & 5 deletions src/dialog/server_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,15 +552,12 @@ impl ServerInviteDialog {
/// Send a REFER request
pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::Other(
"Refer-To".into(),
format!("<{}>", refer_to),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down
12 changes: 4 additions & 8 deletions src/dialog/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ impl ClientSubscriptionDialog {

pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::ReferTo(
format!("<{}>", refer_to).into(),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down Expand Up @@ -193,14 +191,12 @@ impl ServerSubscriptionDialog {

pub async fn refer(
&self,
refer_to: crate::sip::Uri,
refer_to: impl Into<crate::sip::ReferTo>,
headers: Option<Vec<crate::sip::Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<crate::sip::Response>> {
let mut headers = headers.unwrap_or_default();
headers.push(crate::sip::Header::ReferTo(
format!("<{}>", refer_to).into(),
));
headers.push(crate::sip::Header::ReferTo(refer_to.into()));
self.request(crate::sip::Method::Refer, Some(headers), body)
.await
}
Expand Down
1 change: 1 addition & 0 deletions src/dialog/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ mod test_client_dialog;
mod test_dialog_layer;
mod test_dialog_states;
mod test_prack;
mod test_refer;
mod test_server_dialog;
mod test_sub_pub;
54 changes: 54 additions & 0 deletions src/dialog/tests/test_refer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::sync::Arc;

use tokio::sync::mpsc::unbounded_channel;

use crate::dialog::{client_dialog::ClientInviteDialog, dialog::DialogInner, DialogId};
use crate::sip::{ReferTo, Uri};
use crate::transaction::key::TransactionRole;

use super::test_dialog_states::{create_invite_request, create_test_endpoint};

#[test]
fn test_refer_to_from_uri_preserves_existing_uri_behavior() -> crate::Result<()> {
let refer_to = ReferTo::from(Uri::try_from("sip:carol@restsend.com")?);
assert_eq!(refer_to.value(), "<sip:carol@restsend.com>");
Ok(())
}

#[tokio::test]
async fn test_client_dialog_refer_accepts_name_addr_values() -> crate::Result<()> {
let endpoint = create_test_endpoint().await?;
let (state_sender, _) = unbounded_channel();

let dialog_id = DialogId {
call_id: "refer-name-addr".to_string(),
local_tag: "alice-tag".to_string(),
remote_tag: "bob-tag".to_string(),
};

let invite_req = create_invite_request("alice-tag", "bob-tag", "refer-name-addr");
let (tu_sender, _tu_receiver) = unbounded_channel();

let dialog_inner = DialogInner::new(
TransactionRole::Client,
dialog_id,
invite_req,
endpoint.inner.clone(),
state_sender,
None,
Some(Uri::try_from("sip:alice@alice.example.com:5060")?),
tu_sender,
)?;

let client_dialog = ClientInviteDialog {
inner: Arc::new(dialog_inner),
};

std::mem::drop(client_dialog.refer(
"\"Display Name\" <sip:user@domain.com;method=INVITE?Replaces=call-id%40host>",
None,
None,
));

Ok(())
}
6 changes: 6 additions & 0 deletions src/sip/headers/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ untyped_header!(Privacy, "Privacy", Header::Privacy);
untyped_header!(Path, "Path", Header::Path);
untyped_header!(Identity, "Identity", Header::Identity);

impl std::convert::From<crate::sip::Uri> for ReferTo {
fn from(uri: crate::sip::Uri) -> Self {
Self(format!("<{}>", uri))
}
}

#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct CallId(pub String);
impl CallId {
Expand Down
Loading