### Create and Serve SIP Endpoint Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/endpoint/struct.Endpoint.html Demonstrates how to build a SIP endpoint with a custom user agent, start its serving process, and begin processing incoming transactions. This example requires tokio and tokio_util dependencies. ```rust use rsipstack::EndpointBuilder; use tokio_util::sync::CancellationToken; #[tokio::main] async fn main() -> Result<(), Box> { let endpoint = EndpointBuilder::new() .with_user_agent("MyApp/1.0") .build(); // Get incoming transactions let mut incoming = endpoint.incoming_transactions().expect("incoming_transactions"); // Start the endpoint let endpoint_inner = endpoint.inner.clone(); tokio::spawn(async move { endpoint_inner.serve().await.ok(); }); // Process incoming transactions while let Some(transaction) = incoming.recv().await { // Handle transaction break; // Exit for example } Ok(()) } ``` -------------------------------- ### Endpoint Usage Example Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/endpoint/struct.Endpoint.html?search= This example demonstrates how to build, start, and process incoming transactions using the Endpoint struct. ```APIDOC ## §Examples ```rust use rsipstack::EndpointBuilder; use tokio_util::sync::CancellationToken; #[tokio::main] async fn main() -> Result<(), Box> { let endpoint = EndpointBuilder::new() .with_user_agent("MyApp/1.0") .build(); // Get incoming transactions let mut incoming = endpoint.incoming_transactions().expect("incoming_transactions"); // Start the endpoint let endpoint_inner = endpoint.inner.clone(); tokio::spawn(async move { endpoint_inner.serve().await.ok(); }); // Process incoming transactions while let Some(transaction) = incoming.recv().await { // Handle transaction break; // Exit for example } Ok(()) } ``` ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/dialog/struct.DialogInner.html?search= Demonstrates example search queries for different patterns, such as specific types, type conversions, and generic type transformations. ```text std::vec ``` ```text u32 -> bool ``` ```text Option, (T -> U) -> Option ``` -------------------------------- ### Basic Voice Call Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html?search=u32+-%3E+bool Example demonstrating how to create an InviteOption for a basic voice call. ```APIDOC ## Example: Basic Voice Call ```rust let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, content_type: Some("application/sdp".to_string()), offer: Some(sdp_offer_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, ..Default::default() }; let request = dialog_layer.make_invite_request(&invite_option)?; println!("Created INVITE to: {}", request.uri); ``` ``` -------------------------------- ### Example Searches for AlertInfo Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.AlertInfo.html?search= Demonstrates common search patterns for AlertInfo. These examples show how to search for standard library types, type conversions, and generic type transformations. ```rust * std::vec ``` ```rust * u32 -> bool ``` ```rust * Option, (T -> U) -> Option ``` -------------------------------- ### Basic Usage Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/struct.Credential.html?search=u32+-%3E+bool Demonstrates how to create a `Credential` struct with a username, password, and realm. ```APIDOC ## §Examples ### §Basic Usage ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; ``` ``` -------------------------------- ### StreamConnectionInner Search Examples Source: https://docs.rs/rsipstack/latest/rsipstack/transport/stream/struct.StreamConnectionInner.html?search= This section provides examples of how to perform searches on StreamConnectionInner. The examples demonstrate various search patterns and expected outcomes. ```APIDOC ## StreamConnectionInner Search ### Description Provides methods for searching within StreamConnectionInner objects. ### Endpoint `/transport/stream/struct.StreamConnectionInner_search=` ### Parameters This endpoint does not explicitly define parameters in the provided documentation. Search functionality is likely based on the context or internal state. ### Request Example ```json { "query": "example search query" } ``` ### Response #### Success Response (200) - **results** (array) - A list of matching StreamConnectionInner objects or identifiers. #### Response Example ```json { "results": [ { "id": "stream_123", "status": "active" }, { "id": "stream_456", "status": "inactive" } ] } ``` ``` -------------------------------- ### Dialog Enum Usage Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/dialog/enum.Dialog.html Example demonstrating how to use the Dialog enum with a match statement. ```APIDOC ## Examples ```rust use rsipstack::dialog::dialog::Dialog; match dialog { Dialog::ServerInvite(server_dialog) => { // Handle server dialog }, Dialog::ClientInvite(client_dialog) => { // Handle client dialog }, Dialog::ServerSubscription(server_dialog) => { // Handle server subscription dialog }, Dialog::ClientSubscription(client_dialog) => { // Handle client subscription dialog }, Dialog::ServerPublication(server_dialog) => { // Handle server publication dialog }, Dialog::ClientPublication(client_dialog) => { // Handle client publication dialog } } ``` ``` -------------------------------- ### TransportLayer::serve_listens Source: https://docs.rs/rsipstack/latest/rsipstack/transport/transport_layer/struct.TransportLayer.html Starts serving listen sockets for the TransportLayer. ```APIDOC ## TransportLayer::serve_listens ### Description Starts serving listen sockets for the TransportLayer. ### Signature ```rust pub async fn serve_listens(&self) -> Result<()> ``` ``` -------------------------------- ### Trim Start Example Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Expires.html?search= Demonstrates removing leading whitespace from a string. ```rust let s = " עברית "; assert!(Some('ע') == s.trim_start().chars().next()); ``` -------------------------------- ### Example of using poll_recv_many in a Future Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/transaction/type.TransactionEventReceiver.html This example demonstrates how to use `poll_recv_many` within a custom Future to receive multiple messages from an `UnboundedReceiver`. It shows the setup for the Future, sending messages, and awaiting the result. ```rust use std::task::{Context, Poll}; use std::pin::Pin; use tokio::sync::mpsc; use futures::Future; struct MyReceiverFuture<'a> { receiver: mpsc::UnboundedReceiver, buffer: &'a mut Vec, limit: usize, } impl<'a> Future for MyReceiverFuture<'a> { type Output = usize; // Number of messages received fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let MyReceiverFuture { receiver, buffer, limit } = &mut *self; // Now `receiver` and `buffer` are mutable references, and `limit` is copied match receiver.poll_recv_many(cx, *buffer, *limit) { Poll::Pending => Poll::Pending, Poll::Ready(count) => Poll::Ready(count), } } } let (tx, rx) = mpsc::unbounded_channel::(); let mut buffer = Vec::new(); let my_receiver_future = MyReceiverFuture { receiver: rx, buffer: &mut buffer, limit: 3, }; for i in 0..10 { tx.send(i).expect("Unable to send integer"); } // Note: In a real async context, you would use `.await` on `my_receiver_future`. // For demonstration purposes, we'll simulate the await and assert. // let count = my_receiver_future.await; // assert_eq!(count, 3); // assert_eq!(buffer, vec![0,1,2]) // Simulating the await and assertion for completeness in this context: // This part is conceptual as the actual await requires an async runtime. // For the purpose of documentation extraction, the code up to the send loop is the primary example. // The following lines are illustrative of the expected outcome. // Placeholder for actual await and assertion in an async context println!("Simulating await and assertion..."); // In a real scenario, the following would be executed after the Future is polled to completion: // assert_eq!(buffer.len(), 3); // assert_eq!(buffer, vec![0, 1, 2]); ``` -------------------------------- ### Call with Authentication Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to configure an InviteOption with authentication credentials, including username, password, and realm. ```APIDOC ### Call with Authentication ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, offer: Some(sdp_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, credential: Some(credential), ..Default::default() }; ``` ``` -------------------------------- ### Trim Start Matches Examples Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Branch.html Removes all prefixes that match a given pattern, which can be a character, a string slice, a slice of characters, or a closure. ```rust assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11"); assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123"); ``` -------------------------------- ### Trim Matches Example Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Expires.html Shows how to remove characters matching a pattern from both the start and end of a string slice. The pattern can be a character, a slice of characters, or a closure. ```rust assert_eq!("11foo1bar11".trim_matches('1'), "foo1bar"); assert_eq!("123foo1bar123".trim_matches(char::is_numeric), "foo1bar"); let x: &[_] = &['1', '2']; assert_eq!("12foo1bar12".trim_matches(x), "foo1bar"); ``` ```rust assert_eq!("1foo1barXX".trim_matches(|c| c == '1' || c == 'X'), "foo1bar"); ``` -------------------------------- ### Usage with Registration Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/struct.Credential.html?search=u32+-%3E+bool Shows how to initialize a `Credential` struct when the realm is not initially known and will be extracted from a server challenge. ```APIDOC ### §Usage with Registration ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: None, // Will be extracted from server challenge }; // Use credential with registration // let registration = Registration::new(endpoint.inner.clone(), Some(credential)); ``` ``` -------------------------------- ### Manual Authentication Flow using handle_client_authenticate Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/fn.handle_client_authenticate.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E This example illustrates a manual SIP authentication flow. It shows how to send an initial request, receive a response, check for authentication challenges (401/407), use `handle_client_authenticate` to create an authenticated transaction, and then send the authenticated request. The original transaction is updated if authentication is successful. ```rust // Send initial request tx.send().await?; while let Some(message) = tx.receive().await { match message { SipMessage::Response(resp) => { match resp.status_code { StatusCode::Unauthorized | StatusCode::ProxyAuthenticationRequired => { // Handle authentication challenge let auth_tx = handle_client_authenticate( new_seq, &tx, resp, &credential ).await?; // Send authenticated request auth_tx.send().await?; tx = auth_tx; }, StatusCode::OK => { println!("Request successful"); break; }, _ => { println!("Request failed: {}", resp.status_code); break; } } }, _ => {} } } ``` -------------------------------- ### Basic InviteOption Creation Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html Demonstrates how to create a basic InviteOption for a voice call. Ensure that URIs are correctly converted and that sdp_offer_bytes is provided. ```rust let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, content_type: Some("application/sdp".to_string()), offer: Some(sdp_offer_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, ..Default::default() }; ``` -------------------------------- ### Error Search Examples Source: https://docs.rs/rsipstack/latest/rsipstack/error/enum.Error.html?search= Examples of how to perform searches for errors. These examples demonstrate different query patterns and parameter usage. ```APIDOC ## Example Searches These examples illustrate common search queries: * `std::vec` * `u32 -> bool` * `Option, (T -> U) -> Option` ``` -------------------------------- ### Create a SIP Endpoint with RSIPStack Source: https://docs.rs/rsipstack/latest/rsipstack/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to build and initialize a SIP endpoint using `EndpointBuilder`. It also shows how to retrieve incoming transactions for processing. ```rust use rsipstack::EndpointBuilder; use tokio_util::sync::CancellationToken; #[tokio::main] async fn main() -> Result<(), Box> { // Create a SIP endpoint let endpoint = EndpointBuilder::new() .with_user_agent("MyApp/1.0") .build(); // Get incoming transactions let mut incoming = endpoint.incoming_transactions().expect("incoming_transactions"); // Start the endpoint (in production, you'd run this in a separate task) // let endpoint_inner = endpoint.inner.clone(); // tokio::spawn(async move { // endpoint_inner.serve().await.ok(); // }); // Process incoming requests while let Some(transaction) = incoming.recv().await { // Handle the transaction println!("Received: {}", transaction.original.method); break; // Exit for example } Ok(()) } ``` -------------------------------- ### Create New Registration Client Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/registration/struct.Registration.html?search= Instantiate a Registration client. Use `None` for credentials if no authentication is required, or provide a `Credential` struct for authentication. ```rust let registration = Registration::new(endpoint.inner.clone(), None); let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let registration = Registration::new(endpoint.inner.clone(), Some(credential)); ``` -------------------------------- ### ClientInviteDialog Basic Call Flow Examples Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/client_dialog/struct.ClientInviteDialog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates sending in-dialog requests like UPDATE and INFO, and terminating the call with BYE after the dialog is established. ```rust // After dialog is established: // Send an UPDATE request let response = dialog.update(None, Some(new_sdp_body)).await?; // Send INFO request let response = dialog.info(None, Some(info_body)).await?; // End the call dialog.bye().await?; ``` -------------------------------- ### Get String Length Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Expires.html?search= Demonstrates how to get the length of a string in bytes. Note that this may not correspond to the number of characters or graphemes. ```rust let len = "foo".len(); assert_eq!(3, len); assert_eq!("ƒoo".len(), 4); // fancy f! assert_eq!("ƒoo".chars().count(), 3); ``` -------------------------------- ### Basic SIP Registration Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/registration/struct.Registration.html?search=std%3A%3Avec Demonstrates how to create a Credential, initialize a Registration, and perform a single registration attempt. It checks the response status code and prints the expiration time upon success. ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let mut registration = Registration::new(endpoint.inner.clone(), Some(credential)); let server = rsipstack::sip::Uri::try_from("sip:sip.example.com").unwrap(); let response = registration.register(server.clone(), None).await?; if response.status_code == rsipstack::sip::StatusCode::OK { println!("Registration successful"); println!("Expires in: {} seconds", registration.expires()); } } ``` -------------------------------- ### Get the value of the Accept header Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.Accept.html Use the `value` method to get a string slice representing the header's value. ```rust pub fn value(&self) -> &str ``` -------------------------------- ### Basic Voice Call Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create an InviteOption for a basic voice call with caller, callee, content type, and offer. ```APIDOC ### Basic Voice Call ```rust let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, content_type: Some("application/sdp".to_string()), offer: Some(sdp_offer_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, ..Default::default() }; ``` ```rust let request = dialog_layer.make_invite_request(&invite_option)?; println!("Created INVITE to: {}", request.uri); ``` ``` -------------------------------- ### type_id Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.AcceptEncoding.html Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns `TypeId` ``` -------------------------------- ### Q::new Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Q.html Constructs a new Q instance from a string. ```APIDOC ### pub fn new(s: impl Into) -> Self Creates a new `Q` instance from any type that can be converted into a `String`. ``` -------------------------------- ### type_id Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/key/struct.TransactionKey.html Gets the `TypeId` of the transaction key. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method fn ### Parameters None ### Response #### Success Response - **TypeId**: The unique type identifier of the transaction key. ``` -------------------------------- ### cancel_token Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/client_dialog/struct.ClientInviteDialog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get the cancellation token for this dialog. ```APIDOC ## cancel_token() ### Description Get the cancellation token for this dialog. This token can be used to cancel ongoing operations for this dialog. ### Returns - &CancellationToken: A reference to the cancellation token. ``` -------------------------------- ### Create New Registration (With Authentication) Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/registration/struct.Registration.html?search=std%3A%3Avec Instantiates a new Registration client with authentication credentials. Provide username, password, and realm for server authentication. ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let registration = Registration::new(endpoint.inner.clone(), Some(credential)); ``` -------------------------------- ### ServerPublicationDialog::state Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ServerPublicationDialog.html?search= Gets the current state of the dialog. ```APIDOC ## ServerPublicationDialog::state ### Description Returns the current state of the dialog. ### Signature `pub fn state(&self) -> DialogState` ``` -------------------------------- ### init Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.AcceptEncoding.html Initializes a with the given initializer. ```APIDOC ## unsafe fn init(init: ::Init) -> usize ### Description Initializes a with the given initializer. ### Method `init` ### Parameters * `init` (::Init) - The initializer value. ### Returns `usize` - The pointer to the initialized memory. ``` -------------------------------- ### Create New Registration - Rsipstack Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/registration/struct.Registration.html Instantiate a new Registration client. Use `None` for credentials if no authentication is required, or provide a `Credential` struct for authentication. ```rust let registration = Registration::new(endpoint.inner.clone(), None); ``` ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let registration = Registration::new(endpoint.inner.clone(), Some(credential)); ``` -------------------------------- ### ClientPublicationDialog::state Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ClientPublicationDialog.html?search= Gets the current state of the dialog. ```APIDOC ## ClientPublicationDialog::state ### Description Gets the current state of the dialog. ### Signature `pub fn state(&self) -> DialogState` ``` -------------------------------- ### ServerPublicationDialog::new Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ServerPublicationDialog.html?search= Constructs a new ServerPublicationDialog instance. ```APIDOC ## ServerPublicationDialog::new ### Description Constructs a new `ServerPublicationDialog`. ### Signature `pub fn new(inner: Arc) -> Self` ``` -------------------------------- ### Get CancellationToken Source: https://docs.rs/rsipstack/latest/rsipstack/transport/channel/struct.ChannelConnection.html?search= Retrieves the CancellationToken associated with the ChannelConnection, if set. ```rust pub fn cancel_token(&self) -> Option ``` -------------------------------- ### Get SipMessage Headers Source: https://docs.rs/rsipstack/latest/rsipstack/sip/message/enum.SipMessage.html?search= Returns a reference to the headers of the SipMessage. ```rust fn headers(&self) -> &Headers ``` -------------------------------- ### InviteOption with Authentication Credentials Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html Shows how to configure an InviteOption with authentication credentials, including username, password, and realm. The Credential struct must be properly populated. ```rust let credential = Credential { username: "alice".to_string(), password: "secret123".to_string(), realm: Some("example.com".to_string()), }; let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, offer: Some(sdp_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, credential: Some(credential), ..Default::default() }; ``` -------------------------------- ### Manual Authentication Flow using handle_client_authenticate Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/fn.handle_client_authenticate.html?search=std%3A%3Avec This example illustrates a manual SIP authentication flow. It involves sending an initial request, receiving a 401 or 407 response, using `handle_client_authenticate` to create an authenticated transaction, and then sending the authenticated request. The loop continues until a successful response (200 OK) or an error occurs. ```rust // Send initial request tx.send().await?; while let Some(message) = tx.receive().await { match message { SipMessage::Response(resp) => { match resp.status_code { StatusCode::Unauthorized | StatusCode::ProxyAuthenticationRequired => { // Handle authentication challenge let auth_tx = handle_client_authenticate( new_seq, &tx, resp, &credential ).await?; // Send authenticated request auth_tx.send().await?; tx = auth_tx; }, StatusCode::OK => { println!("Request successful"); break; }, _ => { println!("Request failed: {}", resp.status_code); break; } } }, _ => {} // Ignore other message types } } ``` -------------------------------- ### Implement `Any` for T Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.ContentLength.html Provides the `type_id` method to get the `TypeId` of a type. ```rust impl Any for T where T: 'static + ?Sized, ``` -------------------------------- ### Creating a SIP Endpoint with EndpointBuilder Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/endpoint/struct.EndpointBuilder.html?search= Demonstrates how to use the EndpointBuilder to construct a SIP endpoint with custom configurations for user agent, timer interval, and allowed methods. ```rust use rsipstack::EndpointBuilder; use std::time::Duration; let endpoint = EndpointBuilder::new() .with_user_agent("MyApp/1.0") .with_timer_interval(Duration::from_millis(10)) .with_allows(vec![rsipstack::sip::Method::Invite, rsipstack::sip::Method::Bye]) .build(); ``` -------------------------------- ### Any for T Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.Contact.html Provides the `type_id` method to get the unique identifier of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method fn type_id ### Parameters None ### Returns - TypeId: The unique identifier of the type. ``` -------------------------------- ### impl Any for T Source: https://docs.rs/rsipstack/latest/rsipstack/sip/error/enum.Error.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `type_id` method to get the `TypeId` of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns - `TypeId`: The unique identifier for the type of `self`. ``` -------------------------------- ### Example: same_channel() Comparison Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/dialog/type.DialogStateSender.html?search= Shows how to use `same_channel` to verify if two senders originate from the same unbounded channel. ```rust let (tx, rx) = tokio::sync::mpsc::unbounded_channel::<()>(); let tx2 = tx.clone(); assert!(tx.same_channel(&tx2)); let (tx3, rx3) = tokio::sync::mpsc::unbounded_channel::<()>(); assert!(!tx3.same_channel(&tx2)); ``` -------------------------------- ### Get ServerPublicationDialog State Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ServerPublicationDialog.html Returns the current state of the ServerPublicationDialog. ```rust pub fn state(&self) -> DialogState> ``` -------------------------------- ### Manual Authentication Flow Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/fn.handle_client_authenticate.html This snippet demonstrates a manual flow for handling SIP authentication challenges. It involves sending an initial request, receiving a response, and if it's an authentication challenge, calling handle_client_authenticate to create and send an authenticated request. ```rust // Send initial request tx.send().await?; while let Some(message) = tx.receive().await { match message { SipMessage::Response(resp) => { match resp.status_code { StatusCode::Unauthorized | StatusCode::ProxyAuthenticationRequired => { // Handle authentication challenge let auth_tx = handle_client_authenticate( new_seq, &tx, resp, &credential ).await?; // Send authenticated request auth_tx.send().await?; tx = auth_tx; }, StatusCode::OK => { println!("Request successful"); break; }, _ => { println!("Request failed: {}", resp.status_code); break; } } }, _ => {} } } ``` -------------------------------- ### Get ServerPublicationDialog ID Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ServerPublicationDialog.html Retrieves the unique identifier for the ServerPublicationDialog. ```rust pub fn id(&self) -> DialogId> ``` -------------------------------- ### Q::new Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Q.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new Q instance from any type that can be converted into a String. ```APIDOC ### impl Q #### pub fn new(s: impl Into) -> Self Source ``` -------------------------------- ### Basic Call Handling Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/server_dialog/struct.ServerInviteDialog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to accept or reject an incoming INVITE request to establish a SIP dialog, and how to terminate an established call. ```APIDOC ## Basic Call Handling ### Description Handles the initial acceptance or rejection of an incoming INVITE request, and provides a method to terminate an established call. ### Methods #### `accept` Accepts an incoming INVITE request. - **Parameters**: - `headers` (Option>): Optional headers to include in the response. - `answer_sdp` (Option): The SDP answer for the session, if applicable. ### `reject` Rejects an incoming INVITE request. - **Parameters**: - `headers` (Option>): Optional headers to include in the response. - `reason` (Option): The reason for rejection. ### `bye` Sends a BYE request to terminate an established call. - **Usage**: ```rust // End an established call dialog.bye().await?; ``` ``` -------------------------------- ### snapshot Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/client_dialog/struct.ClientInviteDialog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Get a snapshot of the dialog's current state. ```APIDOC ## snapshot() ### Description Get a snapshot of the dialog's current state. ### Returns - DialogSnapshot: A snapshot of the dialog's state. ``` -------------------------------- ### impl Any for T Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/struct.Credential.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `type_id` method to get the `TypeId` of an instance. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### Creating and Using SipAddr Source: https://docs.rs/rsipstack/latest/rsipstack/transport/sip_addr/struct.SipAddr.html?search=std%3A%3Avec Demonstrates how to create SipAddr instances from a socket address or with a specific transport, and how to convert it back to a socket address. ```rust use rsipstack::transport::SipAddr; use rsipstack::sip::{HostWithPort, Transport}; use std::net::SocketAddr; // Create from socket address let socket_addr: SocketAddr = "192.168.1.100:5060".parse().unwrap(); let sip_addr = SipAddr::from(socket_addr); // Create with specific transport let sip_addr = SipAddr::new( Transport::Tcp, HostWithPort::try_from("example.com:5060").unwrap() ); // Convert to socket address (for IP addresses) if let Ok(socket_addr) = sip_addr.get_socketaddr() { println!("Socket address: {}", socket_addr); } ``` -------------------------------- ### Basic Call Handling Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/server_dialog/struct.ServerInviteDialog.html?search=std%3A%3Avec Demonstrates how to accept or reject an incoming INVITE request, and how to end an established call using the ServerInviteDialog. ```APIDOC ## Basic Call Handling ### Description Handles the initial acceptance or rejection of an INVITE request, and the termination of an established dialog. ### Methods #### `accept` Accepts an incoming INVITE request. - **Parameters**: - `headers` (Option>): Optional headers to include in the 2xx response. - `sdp` (Option): Optional SDP offer/answer for session establishment. #### `reject` Rejects an incoming INVITE request. - **Parameters**: - `headers` (Option>): Optional headers to include in the rejection response. - `sdp` (Option): Optional SDP for rejection response. #### `bye` Sends a BYE request to terminate an established dialog. ### Request Example ```rust // After receiving INVITE: // Accept the call dialog.accept(None, Some(answer_sdp))?; // Or reject the call dialog.reject(None, None)?; // End an established call dialog.bye().await?; ``` ``` -------------------------------- ### stream_position Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/endpoint/type.EndpointInnerRef.html Returns the current seek position from the start of the stream. ```APIDOC ## stream_position ### Description Returns the current seek position from the start of the stream. ### Method `stream_position` ### Returns - `Result`: The current position in the stream, or an error if one occurred. ``` -------------------------------- ### EndpointBuilder::new Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/endpoint/struct.EndpointBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a new instance of EndpointBuilder. ```APIDOC ## EndpointBuilder::new ### Description Initializes a new instance of `EndpointBuilder`. ### Method `new()` ### Returns - `Self`: A new `EndpointBuilder` instance. ``` -------------------------------- ### starts_with() Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Maddr.html?search= Checks if the string slice starts with a given pattern. ```APIDOC ## starts_with() ### Description Returns `true` if the given pattern matches a prefix of this string slice, and `false` otherwise. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure. ### Method `starts_with(pat)` ### Parameters - **pat** (Pattern) - The pattern to check against the prefix. ### Request Example ```rust let bananas = "bananas"; assert!(bananas.starts_with("bana")); assert!(!bananas.starts_with("nana")); ``` ### Response #### Success Response - **bool** - `true` if the string starts with the pattern, `false` otherwise. ``` -------------------------------- ### InviteOption with Custom Headers Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html Illustrates creating an InviteOption that includes custom SIP headers like User-Agent and Subject. Ensure custom_headers are correctly formatted. ```rust let custom_headers = vec![ rsipstack::sip::Header::UserAgent("MyApp/1.0".into()), rsipstack::sip::Header::Subject("Important Call".into()), ]; let invite_option = InviteOption { caller: "sip:alice@example.com".try_into()?, callee: "sip:bob@example.com".try_into()?, content_type: Some("application/sdp".to_string()), offer: Some(sdp_bytes), contact: "sip:alice@192.168.1.100:5060".try_into()?, credential: Some(auth_credential), headers: Some(custom_headers), ..Default::default() }; ``` -------------------------------- ### TlsConnection::get_addr (StreamConnection) Source: https://docs.rs/rsipstack/latest/rsipstack/transport/tls/struct.TlsConnection.html?search= Gets the SIP address associated with the TlsConnection. ```APIDOC ## fn get_addr (StreamConnection) ### Description Gets the SIP address associated with the `TlsConnection`. ### Method `fn` ### Returns * `&SipAddr` - A reference to the SIP address. ``` -------------------------------- ### ClientPublicationDialog::new Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/publication/struct.ClientPublicationDialog.html?search= Creates a new ClientPublicationDialog instance. ```APIDOC ## ClientPublicationDialog::new ### Description Creates a new ClientPublicationDialog instance. ### Signature `pub fn new(inner: Arc) -> Self` ``` -------------------------------- ### impl Any for T Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/struct.Ttl.html?search=std%3A%3Avec Provides the `type_id` method to get the unique identifier of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method GET ``` -------------------------------- ### DummyResolver::new Source: https://docs.rs/rsipstack/latest/rsipstack/resolver/struct.DummyResolver.html Creates a new instance of DummyResolver. ```APIDOC ## DummyResolver::new ### Description Creates a new instance of DummyResolver. ### Method `new()` ### Returns - `Self`: A new instance of DummyResolver. ``` -------------------------------- ### Usage with INVITE Example Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/authenticate/struct.Credential.html?search=u32+-%3E+bool Illustrates how to include a `Credential` struct within an `InviteOption` for making an INVITE request. ```APIDOC ### §Usage with INVITE ```rust let invite_option = InviteOption { caller: rsipstack::sip::Uri::try_from("sip:alice@example.com")?, callee: rsipstack::sip::Uri::try_from("sip:bob@example.com")?, content_type: Some("application/sdp".to_string()), offer: Some(sdp_bytes), contact: rsipstack::sip::Uri::try_from("sip:alice@192.168.1.100:5060")?, credential: Some(credential), ..Default::default() }; ``` ``` -------------------------------- ### Accessing To Header Source: https://docs.rs/rsipstack/latest/rsipstack/sip/message/trait.HeadersExt.html?search=std%3A%3Avec Provides methods to get a reference to the 'To' header. ```APIDOC ## to_header ### Description Retrieves an immutable reference to the 'To' header. ### Method `&self` ### Endpoint N/A (Method call) ### Parameters None ### Request Example N/A ### Response #### Success Response - **To** (Result<&To, Error>) - A reference to the 'To' header or an error. #### Response Example N/A ``` ```APIDOC ## to_header_mut ### Description Retrieves a mutable reference to the 'To' header. ### Method `&mut self` ### Endpoint N/A (Method call) ### Parameters None ### Request Example N/A ### Response #### Success Response - **To** (Result<&mut To, Error>) - A mutable reference to the 'To' header or an error. #### Response Example N/A ``` -------------------------------- ### Accessing Transaction ID Source: https://docs.rs/rsipstack/latest/rsipstack/sip/message/trait.HeadersExt.html Provides a method to get the transaction ID. ```APIDOC ## Accessing Transaction ID ### Description Method to retrieve the transaction ID. ### Method - `transaction_id(&self) -> Result, Error>`: Gets the transaction ID. ``` -------------------------------- ### Configure Basic UDP Server in RSIPStack Source: https://docs.rs/rsipstack/latest/rsipstack/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Sets up a basic UDP transport layer for a SIP endpoint. Requires importing necessary components from rsipstack and tokio_util. ```rust use rsipstack::EndpointBuilder; use rsipstack::transport::{TransportLayer, udp::UdpConnection}; use tokio_util::sync::CancellationToken; let transport_layer = TransportLayer::new(cancel_token.child_token()); let udp_conn = UdpConnection::create_connection("0.0.0.0:5060".parse()?, None, Some(cancel_token.child_token())).await?; transport_layer.add_transport(udp_conn.into()); let endpoint = EndpointBuilder::new() .with_transport_layer(transport_layer) .build(); ``` -------------------------------- ### Create and Send Client Transaction Source: https://docs.rs/rsipstack/latest/rsipstack/transaction/transaction/struct.Transaction.html?search= Demonstrates creating a client transaction, sending a SIP request, and then receiving and handling responses. Ensure the necessary imports and mock objects (endpoint_inner, connection) are available. ```rust use rsipstack::transaction::{ transaction::Transaction, key::{TransactionKey, TransactionRole} }; use rsipstack::sip::SipMessage; // Create a mock request let request = rsipstack::sip::Request { method: rsipstack::sip::Method::Register, uri: rsipstack::sip::Uri::try_from("sip:example.com")?, headers: vec![ rsipstack::sip::Header::Via("SIP/2.0/UDP example.com:5060;branch=z9hG4bKnashds".into()), rsipstack::sip::Header::CSeq("1 REGISTER".into()), rsipstack::sip::Header::From("Alice ;tag=1928301774".into()), rsipstack::sip::Header::CallId("a84b4c76e66710@pc33.atlanta.com".into()), ].into(), version: rsipstack::sip::Version::V2, body: Default::default(), }; let key = TransactionKey::from_request(&request, TransactionRole::Client)?; // Create a client transaction let mut transaction = Transaction::new_client( key, request, endpoint_inner, connection ); // Send the request transaction.send().await?; // Receive responses while let Some(message) = transaction.receive().await { match message { SipMessage::Response(response) => { // Handle response }, _ => {} } } ``` -------------------------------- ### Accessing Path Headers Source: https://docs.rs/rsipstack/latest/rsipstack/sip/message/trait.HeadersExt.html Provides a method to get all 'Path' headers. ```APIDOC ## Accessing Path Headers ### Description Method to retrieve all 'Path' headers. ### Method - `path_headers(&self) -> Vec<&Path>`: Gets all 'Path' headers. ``` -------------------------------- ### impl Any for T Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.Priority.html?search=std%3A%3Avec Provides the `type_id` method to get the unique identifier of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Parameters None ### Returns - `TypeId`: The unique identifier of the type. ``` -------------------------------- ### Creating INVITE Request Source: https://docs.rs/rsipstack/latest/rsipstack/dialog/invitation/struct.InviteOption.html Shows how to use the created InviteOption to generate an actual INVITE request using the dialog_layer. This requires the dialog_layer to be initialized. ```rust let request = dialog_layer.make_invite_request(&invite_option)?; println!("Created INVITE to: {}", request.uri); ``` -------------------------------- ### SipCodec::new Source: https://docs.rs/rsipstack/latest/rsipstack/transport/stream/struct.SipCodec.html?search=u32+-%3E+bool Constructs a new instance of SipCodec. ```APIDOC ## SipCodec::new ### Description Constructs a new instance of the SipCodec. ### Method `new()` ### Returns - `Self`: A new instance of SipCodec. ``` -------------------------------- ### type_id Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.ContentType.html Gets the `TypeId` of `self`. This method is part of the `Any` trait implementation. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Response #### Success Response (200) - **TypeId**: The type identifier of the object. ``` -------------------------------- ### SipCodec::new Source: https://docs.rs/rsipstack/latest/rsipstack/transport/stream/struct.SipCodec.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new instance of SipCodec. ```APIDOC ## SipCodec::new ### Description Constructs a new instance of the `SipCodec`. ### Method `new()` ### Returns - `Self`: A new `SipCodec` instance. ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/rsipstack/latest/rsipstack/sip/headers/untyped/struct.ContentLanguage.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the type_id method to get the TypeId of the instance. ```APIDOC ## impl Any for T ### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### Vec From<&[T]> Example Source: https://docs.rs/rsipstack/latest/rsipstack/sip/uri/type.UriWithParamsList.html?search=std%3A%3Avec Creates a Vec by cloning elements from a slice. Available on non-'no_global_oom_handling'. ```rust impl where T: Clone, { fn from(s: &[T]) -> Vec } assert_eq!(Vec::from(&[1, 2, 3][..]), vec![1, 2, 3]); ```