private void UACInviteTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { // BranchId for 2xx responses needs to be a new one, non-2xx final responses use same one as original request. if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode < 299) { if (_sendOkAckManually == false) { Send2xxAckRequest(null, null); } } else { // ACK for non 2xx response is part of the INVITE transaction and gets routed to the same endpoint as the INVITE. var ackRequest = GetInTransactionACKRequest(sipResponse, m_transactionRequest.URI); base.SendRequest(ackRequest); } UACInviteTransactionFinalResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.LogError($"Exception UACInviteTransaction_TransactionFinalResponseReceived. {excp.Message}"); } }
private async Task <SocketError> UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { if (sipResponse.StatusCode > 100 && sipResponse.StatusCode <= 199) { if (sipResponse.Header.RSeq > 0) { // Send a PRACK for this provisional response. PRackRequest = GetPRackRequest(sipResponse); await SendRequestAsync(PRackRequest); } } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } return(await UACInviteTransactionInformationResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse));; } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); return(SocketError.Fault); } }
private void UACInviteTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { // BranchId for 2xx responses needs to be a new one, non-2xx final responses use same one as original request. SIPRequest ackRequest = null; if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode < 299) { if (sipResponse.Header.To != null) { m_remoteTag = sipResponse.Header.To.ToTag; } SIPURI ackURI = m_transactionRequest.URI; if (sipResponse.Header.Contact != null && sipResponse.Header.Contact.Count > 0) { ackURI = sipResponse.Header.Contact[0].ContactURI; // Don't mangle private contacts if there is a Record-Route header. If a proxy is putting private IP's in a Record-Route header that's its problem. if ((sipResponse.Header.RecordRoutes == null || sipResponse.Header.RecordRoutes.Length == 0) && IPSocket.IsPrivateAddress(ackURI.Host) && !sipResponse.Header.ProxyReceivedFrom.IsNullOrBlank()) { // Setting the Proxy-ReceivedOn header is how an upstream proxy will let an agent know it should mangle the contact. SIPEndPoint remoteUASSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(sipResponse.Header.ProxyReceivedFrom); ackURI.Host = remoteUASSIPEndPoint.GetIPEndPoint().ToString(); } } // ACK for 2xx response needs to be a new transaction and gets routed based on SIP request fields. ackRequest = GetNewTransactionACKRequest(sipResponse, ackURI, LocalSIPEndPoint); base.SendRequest(ackRequest); } else { // ACK for non 2xx response is part of the INVITE transaction and gets routed to the same endpoint as the INVITE. ackRequest = GetInTransactionACKRequest(sipResponse, m_transactionRequest.URI, LocalSIPEndPoint); base.SendRequest(RemoteEndPoint, ackRequest); } if (UACInviteTransactionFinalResponseReceived != null) { UACInviteTransactionFinalResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.Error("Exception UACInviteTransaction_TransactionFinalResponseReceived. " + excp.Message); } }
private async Task <SocketError> UACInviteTransaction_TransactionFinalResponseReceived( SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { DeliveryPending = false; base.UpdateTransactionState(SIPTransactionStatesEnum.Confirmed); // BranchId for 2xx responses needs to be a new one, non-2xx final responses use same one as original request. if (sipResponse.StatusCode >= 200 && sipResponse.StatusCode < 299) { if (_sendOkAckManually == false) { AckRequest = Get2xxAckRequest(null, null); await SendRequestAsync(AckRequest).ConfigureAwait(false); } } else { // ACK for non 2xx response is part of the INVITE transaction and gets routed to the same endpoint as the INVITE. AckRequest = GetInTransactionACKRequest(sipResponse, m_transactionRequest.URI); await SendRequestAsync(AckRequest).ConfigureAwait(false); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Answered(sipResponse.StatusCode, sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } if (UACInviteTransactionFinalResponseReceived != null) { return(await UACInviteTransactionFinalResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse).ConfigureAwait(false)); } else { return(SocketError.Success); } } catch (Exception excp) { Logger.Logger.Error( $"Exception UACInviteTransaction_TransactionFinalResponseReceived. ->{excp.Message}"); return(SocketError.Fault); } }
internal UACInviteTransaction(SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, SIPEndPoint outboundProxy) : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy) { TransactionType = SIPTransactionTypesEnum.Invite; m_localTag = sipRequest.Header.From.FromTag; SIPEndPoint localEP = SIPEndPoint.TryParse(sipRequest.Header.ProxySendFrom) ?? localSIPEndPoint; CDR = new SIPCDR(SIPCallDirection.Out, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId, localEP, dstEndPoint); TransactionFinalResponseReceived += UACInviteTransaction_TransactionFinalResponseReceived; TransactionInformationResponseReceived += UACInviteTransaction_TransactionInformationResponseReceived; TransactionTimedOut += UACInviteTransaction_TransactionTimedOut; TransactionRequestReceived += UACInviteTransaction_TransactionRequestReceived; TransactionRemoved += UACInviteTransaction_TransactionRemoved; }
public UASInviteTransaction( SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint outboundProxy, bool noCDR = false) : base(sipTransport, sipRequest, outboundProxy) { TransactionType = SIPTransactionTypesEnum.InviteServer; m_remoteTag = sipRequest.Header.From.FromTag; if (sipRequest.Header.To.ToTag == null) { // This UAS needs to set the To Tag. m_localTag = CallProperties.CreateNewTag(); } else { // This is a re-INVITE. m_localTag = sipRequest.Header.To.ToTag; } //logger.LogDebug("New UASTransaction (" + TransactionId + ") for " + TransactionRequest.URI.ToString() + " to " + RemoteEndPoint + "."); SIPEndPoint localEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedOn) ?? sipRequest.LocalSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedFrom) ?? sipRequest.RemoteSIPEndPoint; if (!noCDR) { CDR = new SIPCDR(SIPCallDirection.In, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId, localEP, remoteEP); } TransactionRequestReceived += UASInviteTransaction_TransactionRequestReceived; TransactionInformationResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionFinalResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionTimedOut += UASInviteTransaction_TransactionTimedOut; TransactionRemoved += UASInviteTransaction_TransactionRemoved; OnAckRequestReceived += UASInviteTransaction_OnAckRequestReceived; sipTransport.AddTransaction(this); }
internal UASInviteTransaction( SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, SIPEndPoint outboundProxy, IPAddress contactIPAddress, bool noCDR = false) : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy) { TransactionType = SIPTransactionTypesEnum.Invite; m_remoteTag = sipRequest.Header.From.FromTag; m_contactIPAddress = contactIPAddress; if (sipRequest.Header.To.ToTag == null) { // This UAS needs to set the To Tag. m_localTag = CallProperties.CreateNewTag(); } else { // This is a re-INVITE. m_localTag = sipRequest.Header.To.ToTag; } //logger.LogDebug("New UASTransaction (" + TransactionId + ") for " + TransactionRequest.URI.ToString() + " to " + RemoteEndPoint + "."); SIPEndPoint localEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipRequest.Header.ProxyReceivedFrom) ?? dstEndPoint; if (!noCDR) { CDR = new SIPCDR(SIPCallDirection.In, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId, localEP, remoteEP); } //UpdateTransactionState(SIPTransactionStatesEnum.Proceeding); TransactionRequestReceived += UASInviteTransaction_TransactionRequestReceived; TransactionInformationResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionFinalResponseReceived += UASInviteTransaction_TransactionResponseReceived; TransactionTimedOut += UASInviteTransaction_TransactionTimedOut; TransactionRemoved += UASInviteTransaction_TransactionRemoved; }
private void UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { if (UACInviteTransactionInformationResponseReceived != null) { UACInviteTransactionInformationResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); } }
/// <summary> /// Default constructor for user agent client INVITE transaction. /// </summary> /// <param name="sendOkAckManually">If set an ACK request for the 2xx response will NOT be sent and it will be up to the application to explicitly call the SendACK request.</param> /// <param name="disablePrackSupport">If set to true then PRACK support will not be set in the initial INVITE reqeust.</param> internal UACInviteTransaction(SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, SIPEndPoint outboundProxy, bool sendOkAckManually = false, bool disablePrackSupport = false) : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy) { TransactionType = SIPTransactionTypesEnum.InivteClient; m_localTag = sipRequest.Header.From.FromTag; SIPEndPoint localEP = SIPEndPoint.TryParse(sipRequest.Header.ProxySendFrom) ?? localSIPEndPoint; CDR = new SIPCDR(SIPCallDirection.Out, sipRequest.URI, sipRequest.Header.From, sipRequest.Header.CallId, localEP, dstEndPoint); _sendOkAckManually = sendOkAckManually; _disablePrackSupport = disablePrackSupport; TransactionFinalResponseReceived += UACInviteTransaction_TransactionFinalResponseReceived; TransactionInformationResponseReceived += UACInviteTransaction_TransactionInformationResponseReceived; TransactionTimedOut += UACInviteTransaction_TransactionTimedOut; TransactionRequestReceived += UACInviteTransaction_TransactionRequestReceived; TransactionRemoved += UACInviteTransaction_TransactionRemoved; }
private async Task <SocketError> UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { if (sipResponse.StatusCode > 100 && sipResponse.StatusCode <= 199) { if (sipResponse.Header.RSeq > 0) { // Send a PRACK for this provisional response. m_cseq++; PRackRequest = GetAcknowledgeRequest(sipResponse, SIPMethodsEnum.PRACK, m_cseq, null, null); await SendRequestAsync(PRackRequest).ConfigureAwait(false); } } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } if (UACInviteTransactionInformationResponseReceived != null) { return(await UACInviteTransactionInformationResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse).ConfigureAwait(false)); } else { return(SocketError.Success); } } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); return(SocketError.Fault); } }
private void UACInviteTransaction_TransactionInformationResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { try { UACInviteTransactionInformationResponseReceived?.Invoke(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); if (sipResponse.StatusCode > 100 && sipResponse.StatusCode <= 199 && sipResponse.Header.RSeq > 0) { // Send a PRACK for this provisional response. SendPRackRequest(sipResponse); } if (CDR != null) { SIPEndPoint localEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedOn) ?? localSIPEndPoint; SIPEndPoint remoteEP = SIPEndPoint.TryParse(sipResponse.Header.ProxyReceivedFrom) ?? remoteEndPoint; CDR.Progress(sipResponse.Status, sipResponse.ReasonPhrase, localEP, remoteEP); } } catch (Exception excp) { logger.LogError("Exception UACInviteTransaction_TransactionInformationResponseReceived. " + excp.Message); } }