public SIPResponse GetOkResponse(string contentType, string messageBody)
        {
            try
            {
                SIPResponse okResponse = new SIPResponse(SIPResponseStatusCodesEnum.Ok, null);
                okResponse.SetSendFromHints(TransactionRequest.LocalSIPEndPoint);

                SIPHeader requestHeader = TransactionRequest.Header;
                okResponse.Header              = new SIPHeader(SIPContactHeader.GetDefaultSIPContactHeader(), requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId);
                okResponse.Header.To.ToTag     = m_localTag;
                okResponse.Header.CSeqMethod   = requestHeader.CSeqMethod;
                okResponse.Header.Vias         = requestHeader.Vias;
                okResponse.Header.Server       = m_sipServerAgent;
                okResponse.Header.MaxForwards  = Int32.MinValue;
                okResponse.Header.RecordRoutes = requestHeader.RecordRoutes;
                okResponse.Header.Supported    = (PrackSupported == true) ? SIPExtensionHeaders.PRACK : null;

                okResponse.Body = messageBody;
                okResponse.Header.ContentType   = contentType;
                okResponse.Header.ContentLength = (messageBody != null) ? messageBody.Length : 0;

                return(okResponse);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception GetOkResponse. " + excp.Message);
                throw excp;
            }
        }
        public SIPResponse GetOkResponse(string contentType, string messageBody)
        {
            SIPResponse okResponse = new SIPResponse(SIPResponseStatusCodesEnum.Ok, null);

            okResponse.SetSendFromHints(TransactionRequest.LocalSIPEndPoint);

            SIPHeader requestHeader = TransactionRequest.Header;

            okResponse.Header = new SIPHeader(
                SIPContactHeader.GetDefaultSIPContactHeader(TransactionRequest.URI.Scheme),
                requestHeader.From, requestHeader.To,
                requestHeader.CSeq,
                requestHeader.CallId);
            okResponse.Header.To.ToTag     = m_localTag;
            okResponse.Header.CSeqMethod   = requestHeader.CSeqMethod;
            okResponse.Header.Vias         = requestHeader.Vias;
            okResponse.Header.Server       = SIPConstants.SipUserAgentVersionString;
            okResponse.Header.MaxForwards  = Int32.MinValue;
            okResponse.Header.RecordRoutes = requestHeader.RecordRoutes;
            okResponse.Header.Supported    = SIPExtensionHeaders.REPLACES + ", " + SIPExtensionHeaders.NO_REFER_SUB
                                             + ((PrackSupported == true) ? ", " + SIPExtensionHeaders.PRACK : "");

            okResponse.Body = messageBody;
            okResponse.Header.ContentType   = contentType;
            okResponse.Header.ContentLength = (messageBody != null) ? messageBody.Length : 0;

            return(okResponse);
        }
Beispiel #3
0
        /// <summary>
        /// Used to create a SIP response for a request when it was not possible to parse the incoming SIP request.
        /// The response generated by this method may or may not make it back to the requester. Because the SIP
        /// request could not be parsed there are no Via headers available and without those the return network
        /// path is missing. Instead a new Via header is generated that may get through if the requester is only
        /// one SIP hop away.
        /// </summary>
        /// <param name="localSIPEndPoint">The local SIP end point the request was received on.</param>
        /// <param name="remoteSIPEndPoint">The remote SIP end point the request was received on.</param>
        /// <param name="responseCode">The response code to set on the response.</param>
        /// <param name="reasonPhrase">Optional reason phrase to set on the response (keep short).</param>
        public static SIPResponse GetResponse(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteSIPEndPoint, SIPResponseStatusCodesEnum responseCode, string reasonPhrase)
        {
            try
            {
                SIPResponse response = new SIPResponse(responseCode, reasonPhrase);
                response.SetSendFromHints(localSIPEndPoint);
                SIPSchemesEnum sipScheme = (localSIPEndPoint.Protocol == SIPProtocolsEnum.tls) ? SIPSchemesEnum.sips : SIPSchemesEnum.sip;
                SIPFromHeader  from      = new SIPFromHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null);
                SIPToHeader    to        = new SIPToHeader(null, new SIPURI(sipScheme, localSIPEndPoint), null);
                int            cSeq      = 1;
                string         callId    = CallProperties.CreateNewCallId();
                response.Header            = new SIPHeader(from, to, cSeq, callId);
                response.Header.CSeqMethod = SIPMethodsEnum.NONE;
                response.Header.Vias.PushViaHeader(new SIPViaHeader(new SIPEndPoint(localSIPEndPoint.Protocol, remoteSIPEndPoint.GetIPEndPoint()), CallProperties.CreateBranchId()));
                response.Header.MaxForwards = Int32.MinValue;
                response.Header.Allow       = m_allowedSIPMethods;

                return(response);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception SIPResponse.GetResponse. " + excp.Message);
                throw;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Helper method to create a SIP response for a SIP request. This method can be thought of as creating a
        /// vanilla (or no frills) response for a request. It's suitable for generating error responses. For requests that
        /// require an action such as creating a call or registering a contact the response will require additional
        /// information and this method will not be suitable.
        /// </summary>
        /// <param name="sipRequest">The SIP request to create the response for.</param>
        /// <param name="responseCode">The response code.</param>
        /// <param name="reasonPhrase">Optional reason phrase to set on the response (needs to be short).</param>
        /// <returns>A SIP response object.</returns>
        public static SIPResponse GetResponse(SIPRequest sipRequest, SIPResponseStatusCodesEnum responseCode,
                                              string reasonPhrase)
        {
            try
            {
                SIPResponse response = new SIPResponse(responseCode, reasonPhrase);
                response.SetSendFromHints(sipRequest.LocalSIPEndPoint);

                if (reasonPhrase != null)
                {
                    response.ReasonPhrase = reasonPhrase;
                }

                SIPHeader     requestHeader = sipRequest.Header;
                SIPFromHeader from          = (requestHeader == null || requestHeader.From != null)
                    ? requestHeader.From
                    : new SIPFromHeader(null, new SIPURI(sipRequest.URI.Scheme, sipRequest.LocalSIPEndPoint), null);
                SIPToHeader to = (requestHeader == null || requestHeader.To != null)
                    ? requestHeader.To
                    : new SIPToHeader(null, new SIPURI(sipRequest.URI.Scheme, sipRequest.LocalSIPEndPoint), null);
                int    cSeq   = (requestHeader == null || requestHeader.CSeq != -1) ? requestHeader.CSeq : 1;
                string callId = (requestHeader == null || requestHeader.CallId != null)
                    ? requestHeader.CallId
                    : CallProperties.CreateNewCallId();

                response.Header            = new SIPHeader(from, to, cSeq, callId);
                response.Header.CSeqMethod = (requestHeader != null) ? requestHeader.CSeqMethod : SIPMethodsEnum.NONE;

                if (requestHeader == null || requestHeader.Vias == null || requestHeader.Vias.Length == 0)
                {
                    response.Header.Vias.PushViaHeader(new SIPViaHeader(sipRequest.RemoteSIPEndPoint,
                                                                        CallProperties.CreateBranchId()));
                }
                else
                {
                    response.Header.Vias = requestHeader.Vias;
                }

                response.Header.MaxForwards = Int32.MinValue;
                response.Header.Allow       = m_allowedSIPMethods;

                return(response);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception SIPResponse.GetResponse. " + excp.Message);
                throw excp;
            }
        }
Beispiel #5
0
        private SIPResponse GetCancelResponse(SIPRequest sipRequest, SIPResponseStatusCodesEnum sipResponseCode)
        {
            try
            {
                SIPResponse cancelResponse = new SIPResponse(sipResponseCode, null);
                cancelResponse.SetSendFromHints(sipRequest.LocalSIPEndPoint);

                SIPHeader requestHeader = sipRequest.Header;
                cancelResponse.Header             = new SIPHeader(requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId);
                cancelResponse.Header.CSeqMethod  = SIPMethodsEnum.CANCEL;
                cancelResponse.Header.Vias        = requestHeader.Vias;
                cancelResponse.Header.MaxForwards = Int32.MinValue;

                return(cancelResponse);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception GetCancelResponse. " + excp.Message);
                throw excp;
            }
        }
        protected SIPResponse GetInfoResponse(SIPRequest sipRequest, SIPResponseStatusCodesEnum sipResponseCode)
        {
            try
            {
                SIPResponse informationalResponse = new SIPResponse(sipResponseCode, null);
                informationalResponse.SetSendFromHints(sipRequest.LocalSIPEndPoint);

                SIPHeader requestHeader = sipRequest.Header;
                informationalResponse.Header             = new SIPHeader(requestHeader.From, requestHeader.To, requestHeader.CSeq, requestHeader.CallId);
                informationalResponse.Header.CSeqMethod  = requestHeader.CSeqMethod;
                informationalResponse.Header.Vias        = requestHeader.Vias;
                informationalResponse.Header.MaxForwards = Int32.MinValue;
                informationalResponse.Header.Timestamp   = requestHeader.Timestamp;

                return(informationalResponse);
            }
            catch (Exception excp)
            {
                logger.LogError("Exception GetInformationalResponse. " + excp.Message);
                throw excp;
            }
        }