/// <summary> /// Matches specified SIP response to SIP dialog. If no matching dialog found, returns null. /// </summary> /// <param name="response">SIP response.</param> /// <returns>Returns matched SIP dialog or null in no match found.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>response</b> is null.</exception> internal SIP_Dialog MatchDialog(SIP_Response response) { if (response == null) { throw new ArgumentNullException("response"); } SIP_Dialog dialog = null; try { string callID = response.CallID; string fromTag = response.From.Tag; string toTag = response.To.Tag; if (callID != null && fromTag != null && toTag != null) { string dialogID = callID + "-" + fromTag + "-" + toTag; lock (m_pDialogs) { m_pDialogs.TryGetValue(dialogID, out dialog); } } } catch {} return(dialog); }
/// <summary> /// Matches specified SIP request to SIP dialog. If no matching dialog found, returns null. /// </summary> /// <param name="request">SIP request.</param> /// <returns>Returns matched SIP dialog or null in no match found.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>request</b> is null.</exception> internal SIP_Dialog MatchDialog(SIP_Request request) { if (request == null) { throw new ArgumentNullException("request"); } SIP_Dialog dialog = null; try { string callID = request.CallID; string localTag = request.To.Tag; string remoteTag = request.From.Tag; if (callID != null && localTag != null && remoteTag != null) { string dialogID = callID + "-" + localTag + "-" + remoteTag; lock (m_pDialogs) { m_pDialogs.TryGetValue(dialogID, out dialog); } } } catch {} return(dialog); }
/// <summary> /// Removes specified dialog from dialogs collection. /// </summary> /// <param name="dialog">SIP dialog to remove.</param> internal void RemoveDialog(SIP_Dialog dialog) { lock (m_pDialogs) { m_pDialogs.Remove(dialog.ID); } }
/// <summary> /// Default constructor. /// </summary> /// <param name="stack">Reference to SIP stack.</param> /// <param name="flow">SIP data flow.</param> /// <param name="request">Recieved request.</param> /// <param name="dialog">SIP dialog which received request.</param> /// <param name="transaction">SIP server transaction which must be used to send response back to request maker.</param> internal SIP_RequestReceivedEventArgs(SIP_Stack stack, SIP_Flow flow, SIP_Request request, SIP_Dialog dialog, SIP_ServerTransaction transaction) { m_pStack = stack; m_pFlow = flow; m_pRequest = request; m_pDialog = dialog; m_pTransaction = transaction; }
/// <summary> /// Gets existing or creates new dialog. /// </summary> /// <param name="transaction">Owner transaction what forces to create dialog.</param> /// <param name="response">Response what forces to create dialog.</param> /// <returns>Returns dialog.</returns> /// <exception cref="ArgumentNullException">Is raised when <b>transaction</b> or <b>response</b> is null.</exception> public SIP_Dialog GetOrCreateDialog(SIP_Transaction transaction, SIP_Response response) { if (transaction == null) { throw new ArgumentNullException("transaction"); } if (response == null) { throw new ArgumentNullException("response"); } string dialogID = ""; if (transaction is SIP_ServerTransaction) { dialogID = response.CallID + "-" + response.To.Tag + "-" + response.From.Tag; } else { dialogID = response.CallID + "-" + response.From.Tag + "-" + response.To.Tag; } lock (m_pDialogs) { SIP_Dialog dialog = null; m_pDialogs.TryGetValue(dialogID, out dialog); // Dialog doesn't exist, create it. if (dialog == null) { if (response.CSeq.RequestMethod.ToUpper() == SIP_Methods.INVITE) { dialog = new SIP_Dialog_Invite(); dialog.Init(m_pStack, transaction, response); dialog.StateChanged += delegate { if (dialog.State == SIP_DialogState.Terminated) { m_pDialogs.Remove(dialog.ID); } }; m_pDialogs.Add(dialog.ID, dialog); } else { throw new ArgumentException("Method '" + response.CSeq.RequestMethod + "' has no dialog handler."); } } return(dialog); } }