Exemple #1
0
        public override SipCSeqHeader Parse(StringReader r)
        {
            SipCSeqHeader header = new SipCSeqHeader();

            var word = r.ReadWord();

            IfNullThrowParseExceptionInvalidFormat(word);

            word = word.Trim();

            IfFalseThrowParseException(ParseUtil.IsInteger(word), ExceptionMessage.InvalidFormat);

            header.Sequence = int.Parse(word);

            word = r.ReadWord();

            IfNullOrEmptyThrowParseExceptionInvalidFormat(word);

            IfFalseThrowParseException(SipMethods.IsMethod(word), ExceptionMessage.SipMethodNotSupprted);

            IfFalseThrowParseException(string.IsNullOrWhiteSpace(r.ReadToEnd()), ExceptionMessage.InvalidFormat);

            header.Command = word.Trim();

            return(header);
        }
Exemple #2
0
        public ValidateRequestResult ValidateRequest(SipRequest request)
        {
            var result = new ValidateRequestResult();

            if (!SipMethods.IsMethod(request.RequestLine.Method))
            {
                result.UnSupportedSipMethod = request.RequestLine.Method;
            }
            result.MissingRequiredHeader    = FindFirstMissingRequiredHeader(request);
            result.HasUnSupportedSipVersion = !ValidateSipVersion(request.RequestLine.Version);
            if (result.HasRequiredHeadersMissing)
            {
                return(result);
            }
            result.HasInvalidSCeqMethod = !ValidateCSeqMethod(request);
            return(result);
        }
Exemple #3
0
        public SipRequest CreateRequest(string method, SipViaHeader viaheader = null)
        {
            if (State < DialogState.Early)
            {
                throw new InvalidOperationException("The dialog is unable to create the request. A dialog in 'NULL' state can not create requests.");
            }

            Check.IsTrue(SipMethods.IsMethod(method), "method argument must be a SIP method");

            var cseqHeader   = _headerFactory.CreateSCeqHeader(method, _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    = viaheader ?? _headerFactory.CreateViaHeader(_listeningPoint, SipConstants.Udp, SipUtil.CreateBranch());
            var requestUri   = _remoteUri.Clone();

            var maxForwardsHeader = _headerFactory.CreateMaxForwardsHeader();
            var request           = _messageFactory.CreateRequest(
                requestUri,
                method,
                callIdheader,
                cseqHeader,
                fromHeader,
                toHeader,
                viaHeader,
                maxForwardsHeader);

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

            return(request);
        }