示例#1
0
        public override void SetLastResponse(SipResponse response)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("ServerDialog[Id={0}]. Reponse[StatusCode:'{1}']", GetId(), response.StatusLine.StatusCode);
            }

            Check.Require(response, "response");

            if (response.StatusLine.StatusCode == 100)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("ServerDialog[Id={0}]. StatusCode == 100. Ignoring 'TRYING' response");
                }
                return;
            }

            bool terminate = false;

            lock (_lock)
            {
                var newResponseState = GetCorrespondingState(response.StatusLine.StatusCode);

                if (_firstResponse == null)
                {
                    CheckFirstResponse(response);
                    _firstResponse = response;
                    SetDialogProps();
                }
                if (newResponseState > _state)
                {
                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info("ServerDialog[Id={0}]: State Transition: '{1}'-->'{2}'", GetId(), _state, newResponseState);
                    }

                    _state = newResponseState;

                    if (_state == DialogState.Early)
                    {
                        if (!_dialogTable.TryAdd(GetId(), this))
                        {
                            throw new SipCoreException("Could not add ServerDialog[Id={0}] to table, because it already exists.", GetId());
                        }

                        if (_logger.IsDebugEnabled)
                        {
                            _logger.Debug("ServerDialog[Id={0}] added to table.", GetId());
                        }
                    }
                    else if (_state == DialogState.Confirmed)
                    {
                        if (_logger.IsDebugEnabled)
                        {
                            _logger.Debug("ServerDialog[Id={0}]. RETRANSMIT_OK & WAIT_FOR_ACK timers started.", GetId());
                        }

                        _okResponse = response;
                        /*start timers*/
                        _retransmitOkTimer.Start();
                        //_endWaitForAckTimer.Start();
                    }
                    else if (_state == DialogState.Terminated)
                    {
                        terminate = true;
                    }
                }
            }

            if (terminate)
            {
                //terminate outside of lock, to prevent from deadlock !!
                //(terminate is a public method and uses a lock)
                Terminate();
            }
        }
示例#2
0
        public override void SetLastResponse(SipResponse response)
        {
            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("ClientDialog[Id={0}]. Reponse[StatusCode:'{1}']", GetId(), response.StatusLine.StatusCode);
            }

            Check.Require(response, "response");

            if (response.StatusLine.StatusCode == 100)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("StatusCode == 100. Ignoring 'TRYING' response");
                }
                return;
            }

            bool terminate = false;

            lock (_lock)
            {
                var newResponseState = GetCorrespondingState(response.StatusLine.StatusCode);

                if (_firstResponse == null)
                {
                    CheckFirstResponse(response);
                    _firstResponse = response;
                    SetDialogProps();
                }
                if (newResponseState > _state)
                {
                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info("ClientDialog[Id={0}]: State Transition: '{1}'-->'{2}'", GetId(), _state, newResponseState);
                    }

                    if (_state == DialogState.Null &&
                        (newResponseState == DialogState.Early || newResponseState == DialogState.Confirmed))  /*it is possible to receive an 'OK' without first receiving a 'RINGING'.*/
                    {
                        if (!_dialogTable.TryAdd(GetId(), this))
                        {
                            throw new SipCoreException("Could not add ClientDialog[Id={0}] to table, because it already exists.", GetId());
                        }

                        if (_logger.IsDebugEnabled)
                        {
                            _logger.Debug("ClientDialog[Id={0}] added to table.", GetId());
                        }
                    }
                    else if (newResponseState == DialogState.Terminated)
                    {
                        terminate = true;
                    }

                    _state = newResponseState;
                }
            }

            if (terminate)
            {
                //terminate outside of lock, to prevent from deadlock !!
                //terminate is public method and uses a lock !!
                Terminate();
            }
        }