Example #1
0
        public void OnRequest(SipRequestLine requestLine)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("OnRequest called. Method:'{0}', Uri:'{1}'", requestLine.Method, requestLine.Uri.FormatToString());
            }

            _message = _messageFactory.CreateRequest(requestLine);
        }
Example #2
0
        private void OnFirstLine(string firstLine)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("OnFirstLine called. firstLine:'{0}'", firstLine);
            }

            if (firstLine.EndsWith(SipConstants.SipTwoZeroString))
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Firstline is expected to be a SipRequestLine. Try parsing...");
                }

                var requestLine = new SipRequestLineParser().Parse(firstLine);
                _message = _messageFactory.CreateRequest(requestLine);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("RequestLine parsed. Continuing SipRequest parsing...");
                }
            }
            else if (firstLine.StartsWith(SipConstants.SipTwoZeroString))
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Firstline is expected to be a SipStatusLine. Try parsing...");
                }

                var statusLine = new SipStatusLineParser().Parse(firstLine);
                _message = _messageFactory.CreateResponse(statusLine);

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("SipStatusLine parsed. Continuing SipResponse parsing..");
                }
            }
            else
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Firstline format could not be recognized.");
                }

                throw new ParseException(ExceptionMessage.InvalidFirstLineFormat);
            }
        }
        /// <summary>
        /// creates a ack. this is to be sent by the testclient UA
        /// </summary>
        /// <param name="invite"></param>
        /// <param name="ringing"></param>
        /// <returns></returns>
        protected SipRequest CreateAckRequest(SipRequest invite, SipResponse ringing)
        {
            var addressFactory = new SipAddressFactory();
            var headerFactory = new SipHeaderFactory();
            var messageFactory = new SipMessageFactory();

            var localSequenceNr = invite.CSeq.Sequence;
            /*_remoteSequenceNr remains empty */
            var callId = invite.CallId.Value;
            var localTag = invite.From.Tag;
            var remoteUri = invite.To.SipUri;
            var localUri = invite.From.SipUri;

            var remoteTag = ringing.To.Tag;
            var remoteTarget = ringing.Contacts.GetTopMost().SipUri;
            var routeSet = ringing.RecordRoutes.ToList();//refuse looseroutin-less recordroutes
            routeSet.Reverse();

            var cseqHeader = headerFactory.CreateSCeqHeader(SipMethods.Ack, localSequenceNr);
            var toAddress = addressFactory.CreateAddress(null, remoteUri);
            var toHeader = headerFactory.CreateToHeader(toAddress, remoteTag);
            var fromAddress = addressFactory.CreateAddress(null, localUri);
            var fromHeader = headerFactory.CreateFromHeader(fromAddress, localTag);
            var callIdheader = headerFactory.CreateCallIdHeader(callId);
            var viaHeader = invite.Vias.GetTopMost();
            var requestUri = remoteUri.Clone();

            var maxForwardsHeader = headerFactory.CreateMaxForwardsHeader();
            var request = messageFactory.CreateRequest(
                requestUri,
                SipMethods.Ack,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            foreach (var route in routeSet)
            {
                request.Routes.Add(new SipRouteHeader() { SipUri = route.SipUri, Parameters = route.Parameters });
            }

            return request;
        }
        protected SipRequest CreateCancelRequest(SipRequest request)
        {
            var hf = new SipHeaderFactory();
            var mf = new SipMessageFactory();
            var requestUri = request.RequestLine.Uri.Clone();
            var callIdheader = (SipCallIdHeader)request.CallId.Clone();
            var cseqHeader = new SipHeaderFactory().CreateSCeqHeader(SipMethods.Cancel, request.CSeq.Sequence);
            var fromHeader = (SipFromHeader)request.From.Clone();
            var toHeader = (SipToHeader)request.To.Clone();
            var viaHeader = (SipViaHeader)request.Vias.GetTopMost().Clone();
            var maxForwardsHeader = hf.CreateMaxForwardsHeader();
            var cancelRequest = mf.CreateRequest(
                requestUri,
                SipMethods.Cancel,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

            foreach (var route in request.Routes)
            {
                cancelRequest.Routes.Add((SipRouteHeader)route.Clone());
            }

            return cancelRequest;
        }