public SIPEndPoint LocalSIPEndPoint; // The local SIP socket the message was received on or sent from. public static SIPMessage ParseSIPMessage(byte[] buffer, SIPEndPoint localSIPEndPoint, SIPEndPoint remoteSIPEndPoint) { string message = null; try { if (buffer == null || buffer.Length < m_minFirstLineLength) { // Ignore. return(null); } else if (buffer.Length > SIPConstants.SIP_MAXIMUM_RECEIVE_LENGTH) { throw new ApplicationException("SIP message received that exceeded the maximum allowed message length, ignoring."); } else if (!ByteBufferInfo.HasString(buffer, 0, buffer.Length, SIP_MESSAGE_IDENTIFIER, m_CRLF)) { // Message does not contain "SIP" anywhere on the first line, ignore. return(null); } else { message = Encoding.UTF8.GetString(buffer, 0, buffer.Length); SIPMessage sipMessage = ParseSIPMessage(message, localSIPEndPoint, remoteSIPEndPoint); if (sipMessage != null) { sipMessage.RawBuffer = buffer; return(sipMessage); } else { return(null); } } } catch (Exception excp) { message = message.Replace("\n", "LF"); message = message.Replace("\r", "CR"); logger.Error("Exception ParseSIPMessage. " + excp.Message + "\nSIP Message=" + message + "."); return(null); } }
public void ACKReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { UpdateTransactionState(SIPTransactionStatesEnum.Confirmed); }
public static SIPMessage ParseSIPMessage(string message, SIPEndPoint localSIPEndPoint, SIPEndPoint remoteSIPEndPoint) { try { SIPMessage sipMessage = new SIPMessage(); sipMessage.LocalSIPEndPoint = localSIPEndPoint; sipMessage.RemoteSIPEndPoint = remoteSIPEndPoint; sipMessage.RawMessage = message; int endFistLinePosn = message.IndexOf(m_CRLF); if (endFistLinePosn != -1) { sipMessage.FirstLine = message.Substring(0, endFistLinePosn); if (sipMessage.FirstLine.Substring(0, 3) == SIP_RESPONSE_PREFIX) { sipMessage.SIPMessageType = SIPMessageTypesEnum.Response; } else { sipMessage.SIPMessageType = SIPMessageTypesEnum.Request; } int endHeaderPosn = message.IndexOf(m_CRLF + m_CRLF); if (endHeaderPosn == -1) { // Assume flakey implementation if message does not contain the required CRLFCRLF sequence and treat the message as having no body. string headerString = message.Substring(endFistLinePosn + 2, message.Length - endFistLinePosn - 2); sipMessage.SIPHeaders = SIPHeader.SplitHeaders(headerString); //Regex.Split(headerString, m_CRLF); } else { string headerString = message.Substring(endFistLinePosn + 2, endHeaderPosn - endFistLinePosn - 2); sipMessage.SIPHeaders = SIPHeader.SplitHeaders(headerString); //Regex.Split(headerString, m_CRLF); if (message.Length > endHeaderPosn + 4) { sipMessage.Body = message.Substring(endHeaderPosn + 4); } } return(sipMessage); } else { logger.Warn("Error ParseSIPMessage, there were no end of line characters in the string being parsed."); return(null); } } catch (Exception excp) { logger.Error("Exception ParseSIPMessage. " + excp.Message + "\nSIP Message=" + message + "."); return(null); } }
public SIPEndPoint CopyOf() { SIPEndPoint copy = new SIPEndPoint(Protocol, new IPAddress(Address.GetAddressBytes()), Port); return(copy); }
//private bool m_closed = false; public SIPUDPChannel(IPEndPoint endPoint) { m_localSIPEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, endPoint); Initialise(); }
private void SIPTLSMessageReceived(SIPChannel channel, SIPEndPoint remoteEndPoint, byte[] buffer) { SIPMessageReceived?.Invoke(channel, remoteEndPoint, buffer); }
public static bool AreEqual(SIPEndPoint endPoint1, SIPEndPoint endPoint2) { return(endPoint1 == endPoint2); }
public SIPResponse(SIPResponseStatusCodesEnum responseType, string reasonPhrase, SIPEndPoint localSIPEndPoint) { SIPVersion = m_sipVersion; StatusCode = (int)responseType; Status = responseType; ReasonPhrase = reasonPhrase; ReasonPhrase = responseType.ToString(); LocalSIPEndPoint = localSIPEndPoint; }
private void SIPCancelTransaction_TransactionRequestReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPRequest sipRequest) { try { //logger.Debug("CANCEL request received, attempting to locate and cancel transaction."); //UASInviteTransaction originalTransaction = (UASInviteTransaction)GetTransaction(GetRequestTransactionId(sipRequest.Header.Via.TopViaHeader.Branch, SIPMethodsEnum.INVITE)); SIPResponse cancelResponse; if (m_originalTransaction != null) { //logger.Debug("Transaction found to cancel " + originalTransaction.TransactionId + " type " + originalTransaction.TransactionType + "."); m_originalTransaction.CancelCall(); cancelResponse = GetCancelResponse(sipRequest, SIPResponseStatusCodesEnum.Ok); } else { cancelResponse = GetCancelResponse(sipRequest, SIPResponseStatusCodesEnum.CallLegTransactionDoesNotExist); } //UpdateTransactionState(SIPTransactionStatesEnum.Completed); SendFinalResponse(cancelResponse); } catch (Exception excp) { logger.Error("Exception SIPCancelTransaction GotRequest. " + excp.Message); } }
private void SIPCancelTransaction_TransactionFinalResponseReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPTransaction sipTransaction, SIPResponse sipResponse) { if (sipResponse.StatusCode < 200) { logger.Warn("A SIP CANCEL transaction received an unexpected SIP information response " + sipResponse.ReasonPhrase + "."); } else { if (CancelTransactionFinalResponseReceived != null) { CancelTransactionFinalResponseReceived(localSIPEndPoint, remoteEndPoint, sipTransaction, sipResponse); } } }
internal SIPCancelTransaction(SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, UASInviteTransaction originalTransaction) : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, originalTransaction.OutboundProxy) { m_originalTransaction = originalTransaction; TransactionType = SIPTransactionTypesEnum.NonInvite; TransactionRequestReceived += SIPCancelTransaction_TransactionRequestReceived; TransactionFinalResponseReceived += SIPCancelTransaction_TransactionFinalResponseReceived; TransactionRemoved += SIPCancelTransaction_TransactionRemoved; }
/// <summary> /// This constructor is used by client user agents or SIP elements acting in a client user agent role. When /// acting as a client user agent the local fields are contained in the From header and the remote fields are /// in the To header. /// </summary> public SIPDialogue( UACInviteTransaction uacInviteTransaction, string owner, string adminMemberId) { Id = Guid.NewGuid(); CallId = uacInviteTransaction.TransactionRequest.Header.CallId; RouteSet = (uacInviteTransaction.TransactionFinalResponse != null && uacInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null) ? uacInviteTransaction.TransactionFinalResponse.Header.RecordRoutes.Reversed() : null; LocalUserField = uacInviteTransaction.TransactionFinalResponse.Header.From.FromUserField; LocalTag = uacInviteTransaction.TransactionFinalResponse.Header.From.FromTag; RemoteUserField = uacInviteTransaction.TransactionFinalResponse.Header.To.ToUserField; RemoteTag = uacInviteTransaction.TransactionFinalResponse.Header.To.ToTag; CSeq = uacInviteTransaction.TransactionRequest.Header.CSeq; CDRId = uacInviteTransaction.CDR.CDRId; Owner = owner; AdminMemberId = adminMemberId; ContentType = uacInviteTransaction.TransactionRequest.Header.ContentType; SDP = uacInviteTransaction.TransactionRequest.Body; RemoteSDP = uacInviteTransaction.TransactionFinalResponse.Body; Inserted = DateTimeOffset.UtcNow; Direction = SIPCallDirection.Out; // Set the dialogue remote target and take care of mangling if an upstream proxy has indicated it's required. RemoteTarget = new SIPURI(uacInviteTransaction.TransactionRequest.URI.Scheme, SIPEndPoint.ParseSIPEndPoint(uacInviteTransaction.RemoteEndPoint.ToString())); ProxySendFrom = uacInviteTransaction.TransactionFinalResponse.Header.ProxyReceivedOn; if (uacInviteTransaction.TransactionFinalResponse.Header.Contact != null && uacInviteTransaction.TransactionFinalResponse.Header.Contact.Count > 0) { RemoteTarget = uacInviteTransaction.TransactionFinalResponse.Header.Contact[0].ContactURI.CopyOf(); if (!uacInviteTransaction.TransactionFinalResponse.Header.ProxyReceivedFrom.IsNullOrBlank()) { // Setting the Proxy-ReceivedOn header is how an upstream proxy will let an agent know it should mangle the contact. // 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 (RouteSet == null && IPSocket.IsPrivateAddress(RemoteTarget.Host)) { SIPEndPoint remoteUASSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(uacInviteTransaction.TransactionFinalResponse.Header.ProxyReceivedFrom); RemoteTarget.Host = remoteUASSIPEndPoint.GetIPEndPoint().ToString(); } } } }