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
25 changes: 18 additions & 7 deletions src/dialog/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::dialog::{DialogInnerRef, DialogState, TerminatedReason, TransactionHa
use super::DialogId;
use crate::Result;
use rsip::{Header, Method, StatusCode, StatusCodeKind};
use tokio_util::sync::CancellationToken;
use std::sync::{Arc, Mutex};
use tokio_util::sync::CancellationToken;

#[derive(Clone)]
pub struct ClientPublicationDialog {
Expand Down Expand Up @@ -109,7 +109,10 @@ impl ClientPublicationDialog {
self.request(rsip::Method::Message, headers, body).await
}

pub async fn handle(&mut self, tx: &mut crate::transaction::transaction::Transaction) -> Result<()> {
pub async fn handle(
&mut self,
tx: &mut crate::transaction::transaction::Transaction,
) -> Result<()> {
match tx.original.method {
Method::Publish => {
let (handle, rx) = TransactionHandle::new();
Expand Down Expand Up @@ -155,19 +158,24 @@ impl ServerPublicationDialog {
self.etag.lock().unwrap().clone()
}

pub fn accept(&self, etag: String, headers: Option<Vec<Header>>, body: Option<Vec<u8>>) -> Result<()> {
pub fn accept(
&self,
etag: String,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<()> {
let mut headers = headers.unwrap_or_default();
headers.push(Header::Other("SIP-ETag".into(), etag.clone().into()));

let resp = self.inner.make_response(
&self.inner.initial_request.lock().unwrap(),
StatusCode::OK,
Some(headers),
body,
);

*self.etag.lock().unwrap() = Some(etag);

use crate::transaction::transaction::TransactionEvent;
self.inner
.tu_sender
Expand Down Expand Up @@ -224,7 +232,10 @@ impl ServerPublicationDialog {
self.request(rsip::Method::Message, headers, body).await
}

pub async fn handle(&mut self, tx: &mut crate::transaction::transaction::Transaction) -> Result<()> {
pub async fn handle(
&mut self,
tx: &mut crate::transaction::transaction::Transaction,
) -> Result<()> {
match tx.original.method {
Method::Publish => {
let (handle, rx) = TransactionHandle::new();
Expand Down
3 changes: 1 addition & 2 deletions src/dialog/tests/test_dialog_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ fn create_response(status: StatusCode, from_tag: &str, to_tag: &str, call_id: &s
}
}

pub async fn create_test_endpoint() -> crate::Result<crate::transaction::endpoint::Endpoint>
{
pub async fn create_test_endpoint() -> crate::Result<crate::transaction::endpoint::Endpoint> {
let token = CancellationToken::new();
let tl = TransportLayer::new(token.child_token());
let endpoint = EndpointBuilder::new()
Expand Down
35 changes: 14 additions & 21 deletions src/dialog/tests/test_sub_pub.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use rsip::Method;
use crate::dialog::dialog_layer::DialogLayer;
use super::test_dialog_states::{create_invite_request, create_test_endpoint};
use crate::transaction::transaction::Transaction;
use crate::transaction::key::{TransactionKey, TransactionRole};
use crate::dialog::dialog_layer::DialogLayer;
use crate::dialog::DialogId;
use crate::transaction::key::{TransactionKey, TransactionRole};
use crate::transaction::transaction::Transaction;
use rsip::Method;
use std::sync::Arc;

#[tokio::test]
Expand All @@ -18,13 +18,9 @@ async fn test_server_subscription_creation() -> crate::Result<()> {
let transaction = Transaction::new_server(key, subscribe_req, endpoint.inner.clone(), None);

let (state_sender, _state_receiver) = dialog_layer.new_dialog_state_channel();

let server_sub = dialog_layer.get_or_create_server_subscription(
&transaction,
state_sender,
None,
None
)?;

let server_sub =
dialog_layer.get_or_create_server_subscription(&transaction, state_sender, None, None)?;

assert_eq!(server_sub.id().call_id, "sub-call-id");
assert_eq!(server_sub.id().from_tag, "alice-tag");
Expand All @@ -45,13 +41,9 @@ async fn test_server_publication_creation() -> crate::Result<()> {
let transaction = Transaction::new_server(key, publish_req, endpoint.inner.clone(), None);

let (state_sender, _state_receiver) = dialog_layer.new_dialog_state_channel();

let server_pub = dialog_layer.get_or_create_server_publication(
&transaction,
state_sender,
None,
None
)?;

let server_pub =
dialog_layer.get_or_create_server_publication(&transaction, state_sender, None, None)?;

assert_eq!(server_pub.id().call_id, "pub-call-id");
assert_eq!(server_pub.id().from_tag, "alice-tag");
Expand Down Expand Up @@ -86,10 +78,11 @@ async fn test_client_publication_etag_handling() -> crate::Result<()> {
tu_sender,
)?;

let client_pub = crate::dialog::publication::ClientPublicationDialog::new(Arc::new(dialog_inner));

let client_pub =
crate::dialog::publication::ClientPublicationDialog::new(Arc::new(dialog_inner));

assert!(client_pub.etag().is_none());

// Simulate receiving a 200 OK with SIP-ETag manually
*client_pub.etag.lock().unwrap() = Some("test-etag".to_string());
assert_eq!(client_pub.etag(), Some("test-etag".to_string()));
Expand Down
3 changes: 0 additions & 3 deletions src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,6 @@ impl Transaction {
self.on_received_response(resp, connection).await
}
} {
if let Some(ref inspector) = self.endpoint_inner.message_inspector {
return Some(inspector.after_received(msg));
}
return Some(msg);
}
}
Expand Down