示例#1
0
        public SipInviteServerDialog CreateServerDialog(ISipServerTransaction transaction)
        {
            var inviteTx = transaction as SipInviteServerTransaction;

            Check.Require(transaction, "transaction");
            Check.IsTrue(inviteTx != null, "The transaction must be of type 'SipInviteServerTransaction'");
            Check.Require(inviteTx.Request, "The request can not be null");
            Check.Require(inviteTx.Request.From, "The From header can not be null");
            Check.NotNullOrEmpty(inviteTx.Request.From.Tag, "From tag");

            var dialog = new SipInviteServerDialog(
                transaction,
                _dialogTable,
                _stack.GetTimerFactory(),
                _stack.CreateHeaderFactory(),
                _stack.CreateMessageFactory(),
                _stack.CreateAddressFactory(),
                this,
                _sipListener,
                _contextSource.ListeningPoint);

            //setting the dialog is done out of the transaction.
            //(otherwise you need to interface the SetDialog method, both on InviteClient & InviteServer transaction)
            //thus creating again two separate interfaces or adding the method on existing interface thereby poluting.
            inviteTx.SetDialog(dialog);
            return(dialog);
        }
示例#2
0
        public void ProcessRequest(IInternalSoftPhone softPhone, SipRequestEvent requestEvent)
        {
            string method = requestEvent.Request.RequestLine.Method;

            if (method != SipMethods.Cancel)
            {
                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Received request: '{0}'. Request ignored.", method);
                }
                return;
            }

            if (_logger.IsInfoEnabled)
            {
                _logger.Info("'CANCEL' received. Start processing...");
            }

            #region attempt to match transaction

            /*terminate pending invite with 487 (assumption: PendingInvite.OriginalRequest= requestEvent.ServerTransaction.Request)*/

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug("Attempting to match 'CANCEL' target-tx against a tx in the ServerTransactionTable...");
            }

            var txIdAttempts = CreateTxIdAttempts(requestEvent.Request);

            ISipServerTransaction serverTransaction = null;
            foreach (var txIdAttempt in txIdAttempts)
            {
                serverTransaction = softPhone.SipProvider.FindServerTransactionById(txIdAttempt);
                if (serverTransaction != null)
                {
                    break;
                }
            }

            #endregion

            if (serverTransaction == null)
            {
                #region no match

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Could not match 'CANCEL' to an existing transaction. Sending x487 response...");
                }

                var cancelResponse = requestEvent.Request.CreateResponse(SipResponseCodes.x481_Call_Transaction_Does_Not_Exist);
                var cancelTx       = softPhone.SipProvider.CreateServerTransaction(requestEvent.Request);
                cancelTx.SendResponse(cancelResponse);
                requestEvent.IsSent = true;

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("x487 response send.");
                }

                #endregion
            }
            else
            {
                #region matched

                #region respond to cancel with ok

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("'CANCEL' target-tx matched. Answering to cancel with ok...");
                }

                var cancelOkResponse = requestEvent.Request.CreateResponse(SipResponseCodes.x200_Ok);
                var cancelOkTx       = softPhone.SipProvider.CreateServerTransaction(requestEvent.Request);
                cancelOkTx.SendResponse(cancelOkResponse);
                requestEvent.IsSent = true;

                if (_logger.IsDebugEnabled)
                {
                    _logger.Debug("Answered.");
                }

                #endregion

                #region respond to matched tx with x487

                if (serverTransaction.GetId() != softPhone.PendingInvite.InviteServerTransaction.GetId())
                {
                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info("'CANCEL' target-tx does NOT match 'INVITE.' Processing ABORTED. The 'CANCEL' target-tx is expected, to match only to the pending 'INVITE' servertransaction.");
                    }
                }
                else
                {
                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug("Creating '487-Request terminated' response and sending...");
                    }

                    var requestToCancel   = serverTransaction.Request;
                    var terminateResponse = requestToCancel.CreateResponse(SipResponseCodes.x487_Request_Terminated);

                    /*terminate pending invite.*/
                    softPhone.PendingInvite.InviteServerTransaction.SendResponse(terminateResponse);

                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug("Response send.");
                    }

                    if (_logger.IsDebugEnabled)
                    {
                        _logger.Debug("Changing callstate to 'CANCELLED'.");
                    }

                    softPhone.PendingCall.RaiseCallStateChanged(CallState.Cancelled);

                    if (_logger.IsInfoEnabled)
                    {
                        _logger.Info("'CANCEL' Processed. Transitioning (back) to 'Idle'");
                    }

                    softPhone.ChangeState(softPhone.StateProvider.GetIdle());
                }

                #endregion

                #endregion
            }
        }
示例#3
0
        public SipInviteServerDialog CreateServerDialog(ISipServerTransaction transaction)
        {
            var inviteTx = transaction as SipInviteServerTransaction;

            Check.Require(transaction, "transaction");
            Check.IsTrue(inviteTx != null, "The transaction must be of type 'SipInviteServerTransaction'");
            Check.Require(inviteTx.Request, "The request can not be null");
            Check.Require(inviteTx.Request.From, "The From header can not be null");
            Check.NotNullOrEmpty(inviteTx.Request.From.Tag, "From tag");

            var dialog = new SipInviteServerDialog(
                transaction,
                _dialogTable,
                _stack.GetTimerFactory(),
                _stack.CreateHeaderFactory(),
                _stack.CreateMessageFactory(),
                _stack.CreateAddressFactory(),
                this,
                _sipListener,
                _contextSource.ListeningPoint);

            //setting the dialog is done out of the transaction.
            //(otherwise you need to interface the SetDialog method, both on InviteClient & InviteServer transaction)
            //thus creating again two separate interfaces or adding the method on existing interface thereby poluting.
            inviteTx.SetDialog(dialog);
            return dialog;
        }