The server transaction for an INVITE request. This transaction processes incoming calls RECEIVED by the application.
Inheritance: SIPTransaction
Esempio n. 1
0
        /// <summary>
        /// This constructor is used by server user agents or SIP elements acting in a server user agent role. When
        /// acting as a server user agent the local fields are contained in the To header and the remote fields are
        /// in the From header.
        /// </summary>
        public SIPDialogue(UASInviteTransaction uasInviteTransaction)
        {
            Id = Guid.NewGuid();

            CallId = uasInviteTransaction.TransactionRequest.Header.CallId;
            //RouteSet = (uasInviteTransaction.TransactionFinalResponse != null && uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null) ? uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes.Reversed() : null;
            RouteSet        = (uasInviteTransaction.TransactionFinalResponse != null && uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null) ? uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes : null;
            LocalUserField  = uasInviteTransaction.TransactionFinalResponse.Header.To.ToUserField;
            LocalTag        = uasInviteTransaction.TransactionFinalResponse.Header.To.ToTag;
            RemoteUserField = uasInviteTransaction.TransactionFinalResponse.Header.From.FromUserField;
            RemoteTag       = uasInviteTransaction.TransactionFinalResponse.Header.From.FromTag;
            CSeq            = uasInviteTransaction.TransactionRequest.Header.CSeq;
            CDRId           = uasInviteTransaction.CDR != null ? uasInviteTransaction.CDR.CDRId : Guid.Empty;
            ContentType     = uasInviteTransaction.TransactionFinalResponse.Header.ContentType;
            SDP             = uasInviteTransaction.TransactionFinalResponse.Body;
            RemoteSDP       = uasInviteTransaction.TransactionRequest.Body ?? uasInviteTransaction.AckRequest.Body;
            Inserted        = DateTime.UtcNow;
            Direction       = SIPCallDirection.In;

            if (uasInviteTransaction.m_gotPrack)
            {
                CSeq++;
            }

            var inviteReq = uasInviteTransaction.TransactionRequest;

            // Set the dialogue remote target taking into account optional Proxy header fields.
            // No mangling takes place. All the information is recorded to allow an application to perform mangling
            // if so required.
            SIPEndPoint remoteEndPointViaProxy = SIPEndPoint.ParseSIPEndPoint(inviteReq.Header.ProxyReceivedFrom);

            RemoteSIPEndPoint = remoteEndPointViaProxy ?? inviteReq.RemoteSIPEndPoint.CopyOf();
            ProxySendFrom     = inviteReq.Header.ProxyReceivedOn;

            if (inviteReq.Header.Contact != null && inviteReq.Header.Contact.Count > 0)
            {
                RemoteTarget = inviteReq.Header.Contact[0].ContactURI.CopyOf();
            }
            else
            {
                RemoteTarget = new SIPURI(inviteReq.URI.Scheme, inviteReq.RemoteSIPEndPoint);
            }

            //if (uasInviteTransaction.TransactionRequest.Header.Contact != null && uasInviteTransaction.TransactionRequest.Header.Contact.Count > 0)
            //{
            //    RemoteTarget = uasInviteTransaction.TransactionRequest.Header.Contact[0].ContactURI.CopyOf();
            //    if (!uasInviteTransaction.TransactionRequest.Header.ProxyReceivedFrom.IsNullOrBlank())
            //    {
            //        // Setting the Proxy-ReceivedOn header is how an upstream proxy will let an agent know it should mangle the contact.
            //        // Don't mangle private contacts if there is a Record-Route header. If a proxy is putting private IP's in a Record-Route header that's its problem.
            //        if (RouteSet == null && IPSocket.IsPrivateAddress(RemoteTarget.HostAddress))
            //        {
            //            SIPEndPoint remoteUASSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(uasInviteTransaction.TransactionRequest.Header.ProxyReceivedFrom);
            //            RemoteTarget.Host = remoteUASSIPEndPoint.GetIPEndPoint().ToString();
            //        }
            //    }
            //}
        }
 internal SIPCancelTransaction(SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, UASInviteTransaction originalTransaction)
     : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, originalTransaction.OutboundProxy)
 {
     m_originalTransaction = originalTransaction;
     TransactionType = SIPTransactionTypesEnum.NonInvite;
     TransactionRequestReceived += SIPCancelTransaction_TransactionRequestReceived;
     TransactionFinalResponseReceived += SIPCancelTransaction_TransactionFinalResponseReceived;
     TransactionRemoved += SIPCancelTransaction_TransactionRemoved;
 }
 internal SIPCancelTransaction(SIPTransport sipTransport, SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, UASInviteTransaction originalTransaction)
     : base(sipTransport, sipRequest, dstEndPoint, localSIPEndPoint, originalTransaction.OutboundProxy)
 {
     m_originalTransaction             = originalTransaction;
     TransactionType                   = SIPTransactionTypesEnum.NonInvite;
     TransactionRequestReceived       += SIPCancelTransaction_TransactionRequestReceived;
     TransactionFinalResponseReceived += SIPCancelTransaction_TransactionFinalResponseReceived;
     TransactionRemoved               += SIPCancelTransaction_TransactionRemoved;
 }
Esempio n. 4
0
            public void AckRecognitionUnitTest()
            {
                SIPTransport clientTransport = null;
                SIPTransport serverTransport = null;

                try
                {
                    SIPTransactionEngine clientEngine   = new SIPTransactionEngine();   // Client side of the INVITE.
                    SIPEndPoint          clientEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(IPAddress.Loopback, 12013));
                    clientTransport = new SIPTransport(MockSIPDNSManager.Resolve, clientEngine, new SIPUDPChannel(clientEndPoint.GetIPEndPoint()), false);
                    SetTransportTraceEvents(clientTransport);

                    SIPTransactionEngine serverEngine      = new SIPTransactionEngine(); // Server side of the INVITE.
                    UASInviteTransaction serverTransaction = null;
                    SIPEndPoint          serverEndPoint    = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 12014));
                    serverTransport = new SIPTransport(MockSIPDNSManager.Resolve, serverEngine, new SIPUDPChannel(serverEndPoint.GetIPEndPoint()), false);
                    SetTransportTraceEvents(serverTransport);
                    serverTransport.SIPTransportRequestReceived += (localEndPoint, remoteEndPoint, sipRequest) =>
                    {
                        Console.WriteLine("Server Transport Request In: " + sipRequest.Method + ".");
                        serverTransaction = serverTransport.CreateUASTransaction(sipRequest, remoteEndPoint, localEndPoint, null);
                        SetTransactionTraceEvents(serverTransaction);
                        serverTransaction.GotRequest(localEndPoint, remoteEndPoint, sipRequest);
                    };

                    SIPURI     dummyURI      = SIPURI.ParseSIPURI("sip:dummy@" + serverEndPoint);
                    SIPRequest inviteRequest = GetDummyINVITERequest(dummyURI);
                    inviteRequest.LocalSIPEndPoint = clientTransport.GetDefaultTransportContact(SIPProtocolsEnum.udp);

                    // Send the invite to the server side.
                    UACInviteTransaction clientTransaction = new UACInviteTransaction(clientTransport, inviteRequest, serverEndPoint, clientEndPoint, null);
                    SetTransactionTraceEvents(clientTransaction);
                    clientEngine.AddTransaction(clientTransaction);
                    clientTransaction.SendInviteRequest(serverEndPoint, inviteRequest);

                    Thread.Sleep(500);

                    Assert.IsTrue(clientTransaction.TransactionState == SIPTransactionStatesEnum.Completed, "Client transaction in incorrect state.");
                    Assert.IsTrue(serverTransaction.TransactionState == SIPTransactionStatesEnum.Confirmed, "Server transaction in incorrect state.");
                }
                finally
                {
                    if (clientTransport != null)
                    {
                        clientTransport.Shutdown();
                    }

                    if (serverTransport != null)
                    {
                        serverTransport.Shutdown();
                    }
                }
            }
Esempio n. 5
0
        /// <summary>
        /// This constructor is used by server user agents or SIP elements acting in a server user agent role. When
        /// acting as a server user agent the local fields are contained in the To header and the remote fields are
        /// in the From header.
        /// </summary>
        public SIPDialogue(
            UASInviteTransaction uasInviteTransaction)
        {
            Id = Guid.NewGuid();

            CallId = uasInviteTransaction.TransactionRequest.Header.CallId;
            //RouteSet = (uasInviteTransaction.TransactionFinalResponse != null && uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null) ? uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes.Reversed() : null;
            RouteSet = (uasInviteTransaction.TransactionFinalResponse != null &&
                        uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null)
                ? uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes
                : null;
            LocalUserField  = uasInviteTransaction.TransactionFinalResponse.Header.To.ToUserField;
            LocalTag        = uasInviteTransaction.TransactionFinalResponse.Header.To.ToTag;
            RemoteUserField = uasInviteTransaction.TransactionFinalResponse.Header.From.FromUserField;
            RemoteTag       = uasInviteTransaction.TransactionFinalResponse.Header.From.FromTag;
            CSeq            = uasInviteTransaction.TransactionRequest.Header.CSeq;
            CDRId           = uasInviteTransaction.CDR != null ? uasInviteTransaction.CDR.CDRId : Guid.Empty;
            ContentType     = uasInviteTransaction.TransactionFinalResponse.Header.ContentType;
            SDP             = uasInviteTransaction.TransactionFinalResponse.Body;
            RemoteSDP       = uasInviteTransaction.TransactionRequest.Body ?? uasInviteTransaction.AckRequest.Body;
            Inserted        = DateTimeOffset.UtcNow;
            Direction       = SIPCallDirection.In;

            if (uasInviteTransaction.m_gotPrack)
            {
                CSeq++;
            }

            RemoteTarget = new SIPURI(uasInviteTransaction.TransactionRequest.URI.Scheme,
                                      uasInviteTransaction.TransactionRequest.RemoteSIPEndPoint.CopyOf());
            ProxySendFrom = uasInviteTransaction.TransactionRequest.Header.ProxyReceivedOn;
            if (uasInviteTransaction.TransactionRequest.Header.Contact != null &&
                uasInviteTransaction.TransactionRequest.Header.Contact.Count > 0)
            {
                RemoteTarget = uasInviteTransaction.TransactionRequest.Header.Contact[0].ContactURI.CopyOf();
                if (!uasInviteTransaction.TransactionRequest.Header.ProxyReceivedFrom.IsNullOrBlank())
                {
                    // Setting the Proxy-ReceivedOn header is how an upstream proxy will let an agent know it should mangle the contact.
                    // Don't mangle private contacts if there is a Record-Route header. If a proxy is putting private IP's in a Record-Route header that's its problem.
                    if (RouteSet == null && IPSocket.IsPrivateAddress(RemoteTarget.Host))
                    {
                        SIPEndPoint remoteUASSIPEndPoint =
                            SIPEndPoint.ParseSIPEndPoint(uasInviteTransaction.TransactionRequest.Header
                                                         .ProxyReceivedFrom);
                        RemoteTarget.Host = remoteUASSIPEndPoint.GetIPEndPoint().ToString();
                    }
                }
            }
        }
Esempio n. 6
0
            public void AckRecognitionIIUnitTest()
            {
                SIPTransactionEngine engine = new SIPTransactionEngine();     // Client side of the INVITE.

                string inviteRequestStr =
                    "INVITE sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 INVITE" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "Content-Type: application/sdp" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest(inviteRequestStr);

                // Server has received the invite.
                SIPEndPoint          dummySIPEndPoint  = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                UASInviteTransaction serverTransaction = new UASInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);

                engine.AddTransaction(serverTransaction);

                //SIPResponse errorResponse = SIPTransport.GetResponse(inviteRequest.Header, SIPResponseStatusCodesEnum.Decline, "Unit Test", null, null);

                string ackRequestStr =
                    "ACK sip:[email protected] SIP/2.0" + m_CRLF +
                    "Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
                    "From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
                    "To: <sip:[email protected]>" + m_CRLF +
                    "Contact: <sip:[email protected]:5065>" + m_CRLF +
                    "Call-ID: [email protected]" + m_CRLF +
                    "CSeq: 49429 ACK" + m_CRLF +
                    "Max-Forwards: 70" + m_CRLF +
                    "User-Agent: Dummy" + m_CRLF +
                    m_CRLF;

                SIPRequest ackRequest = SIPRequest.ParseSIPRequest(ackRequestStr);

                SIPTransaction matchingTransaction = engine.GetTransaction(ackRequest);

                Assert.IsTrue(matchingTransaction.TransactionId == serverTransaction.TransactionId, "ACK transaction did not match INVITE transaction.");
            }
        public SIPServerUserAgent(
            SIPTransport sipTransport,
            SIPEndPoint outboundProxy,
            string sipUsername,
            string sipDomain,
            SIPCallDirection callDirection,
            SIPAssetGetDelegate<SIPAccount> getSIPAccount,
            SIPAuthenticateRequestDelegate sipAuthenticateRequest,
            SIPMonitorLogDelegate logDelegate,
            UASInviteTransaction uasTransaction)
        {
            m_sipTransport = sipTransport;
            m_outboundProxy = outboundProxy;
            m_sipUsername = sipUsername;
            m_sipDomain = sipDomain;
            m_sipCallDirection = callDirection;
            GetSIPAccount_External = getSIPAccount;
            SIPAuthenticateRequest_External = sipAuthenticateRequest;
            Log_External = logDelegate ?? Log_External;
            m_uasTransaction = uasTransaction;

            m_uasTransaction.TransactionTraceMessage += TransactionTraceMessage;
            m_uasTransaction.UASInviteTransactionTimedOut += ClientTimedOut;
            m_uasTransaction.UASInviteTransactionCancelled += UASTransactionCancelled;
            m_uasTransaction.TransactionRemoved += new SIPTransactionRemovedDelegate(UASTransaction_TransactionRemoved);
            //m_uasTransaction.TransactionStateChanged += (t) => { logger.Debug("Transaction state change to " + t.TransactionState + ", uri=" + t.TransactionRequestURI.ToString() + "."); };
        }
Esempio n. 8
0
        public UASInviteTransaction CreateUASTransaction(SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, SIPEndPoint outboundProxy, bool noCDR = false)
        {
            try
            {
                if (localSIPEndPoint == null)
                {
                    localSIPEndPoint = GetDefaultSIPEndPoint();
                }

                CheckTransactionEngineExists();
                UASInviteTransaction uasInviteTransaction = new UASInviteTransaction(this, sipRequest, dstEndPoint, localSIPEndPoint, outboundProxy, ContactIPAddress, noCDR);
                m_transactionEngine.AddTransaction(uasInviteTransaction);
                return uasInviteTransaction;
            }
            catch (Exception excp)
            {
                logger.Error("Exception CreateUASTransaction. " + excp);
                throw;
            }
        }
Esempio n. 9
0
        public SIPCancelTransaction CreateCancelTransaction(SIPRequest sipRequest, SIPEndPoint dstEndPoint, SIPEndPoint localSIPEndPoint, UASInviteTransaction inviteTransaction)
        {
            try
            {
                if (localSIPEndPoint == null)
                {
                    localSIPEndPoint = GetDefaultSIPEndPoint();
                }

                CheckTransactionEngineExists();
                SIPCancelTransaction cancelTransaction = new SIPCancelTransaction(this, sipRequest, dstEndPoint, localSIPEndPoint, inviteTransaction);
                m_transactionEngine.AddTransaction(cancelTransaction);
                return cancelTransaction;
            }
            catch (Exception excp)
            {
                logger.Error("Exception CreateUASTransaction. " + excp);
                throw;
            }
        }
Esempio n. 10
0
        private RTSPAppStruct m_rtspAppStruct; // Describes the RTSP server leg of the call from the sipswitch.

        #endregion Fields

        #region Constructors

        public RTSPApp(
            SIPMonitorLogDelegate statefulProxyLogEvent,
            UASInviteTransaction clientTransaction,
            string username)
        {
            m_statefulProxyLogEvent = statefulProxyLogEvent;

            m_clientTransaction = clientTransaction;
            //m_clientTransaction.TransactionCancelled += new SIPTransactionCancelledDelegate(CallCancelled);

            m_clientUsername = username;

            logger.Debug(m_clientTransaction.TransactionRequest.Body);

            m_rtpPort = Convert.ToInt32(Regex.Match(m_clientTransaction.TransactionRequest.Body, @"m=audio (?<port>\d+)", RegexOptions.Singleline).Result("${port}"));
            logger.Debug("RTP port=" + m_rtpPort);
        }
            public void AckRecognitionIIUnitTest()
            {
                SIPTransactionEngine engine = new SIPTransactionEngine();     // Client side of the INVITE.
                
                string inviteRequestStr = 
                    "INVITE sip:[email protected] SIP/2.0" + m_CRLF +
					"Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
					"From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
					"To: <sip:[email protected]>" + m_CRLF +
					"Contact: <sip:[email protected]:5065>" + m_CRLF +
					"Call-ID: [email protected]" + m_CRLF +
					"CSeq: 49429 INVITE" + m_CRLF +
					"Max-Forwards: 70" + m_CRLF +
					"Content-Type: application/sdp" + m_CRLF +
					"User-Agent: Dummy" + m_CRLF +
					m_CRLF;

                SIPRequest inviteRequest = SIPRequest.ParseSIPRequest(inviteRequestStr);

                // Server has received the invite.
                SIPEndPoint dummySIPEndPoint = new SIPEndPoint(new IPEndPoint(IPAddress.Loopback, 1234));
                UASInviteTransaction serverTransaction = new UASInviteTransaction(new SIPTransport(MockSIPDNSManager.Resolve, null), inviteRequest, dummySIPEndPoint, dummySIPEndPoint, null);
                engine.AddTransaction(serverTransaction);

                //SIPResponse errorResponse = SIPTransport.GetResponse(inviteRequest.Header, SIPResponseStatusCodesEnum.Decline, "Unit Test", null, null);

                string ackRequestStr = 
                    "ACK sip:[email protected] SIP/2.0" + m_CRLF +
					"Via: SIP/2.0/UDP 192.168.1.2:5065;rport;branch=z9hG4bKFBB7EAC06934405182D13950BD51F001" + m_CRLF +
					"From: SER Test X <sip:[email protected]:5065>;tag=196468136" + m_CRLF +
					"To: <sip:[email protected]>" + m_CRLF +
					"Contact: <sip:[email protected]:5065>" + m_CRLF +
					"Call-ID: [email protected]" + m_CRLF +
					"CSeq: 49429 ACK" + m_CRLF +
					"Max-Forwards: 70" + m_CRLF +
					"User-Agent: Dummy" + m_CRLF +
					m_CRLF;

                SIPRequest ackRequest = SIPRequest.ParseSIPRequest(ackRequestStr);

                SIPTransaction matchingTransaction = engine.GetTransaction(ackRequest);

                Assert.IsTrue(matchingTransaction.TransactionId == serverTransaction.TransactionId, "ACK transaction did not match INVITE transaction.");
            }
Esempio n. 12
0
        /// <summary>
        /// This constructor is used by server user agents or SIP elements acting in a server user agent role. When
        /// acting as a server user agent the local fields are contained in the To header and the remote fields are 
        /// in the From header.
        /// </summary>
        public SIPDialogue(
            UASInviteTransaction uasInviteTransaction,
            string owner,
            string adminMemberId)
        {
            Id = Guid.NewGuid();

            CallId = uasInviteTransaction.TransactionRequest.Header.CallId;
            RouteSet = (uasInviteTransaction.TransactionFinalResponse != null && uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes != null) ? uasInviteTransaction.TransactionFinalResponse.Header.RecordRoutes.Reversed() : null;
            LocalUserField = uasInviteTransaction.TransactionFinalResponse.Header.To.ToUserField;
            LocalTag = uasInviteTransaction.TransactionFinalResponse.Header.To.ToTag;
            RemoteUserField = uasInviteTransaction.TransactionFinalResponse.Header.From.FromUserField;
            RemoteTag = uasInviteTransaction.TransactionFinalResponse.Header.From.FromTag;
            CSeq = uasInviteTransaction.TransactionRequest.Header.CSeq;
            CDRId = uasInviteTransaction.CDR.CDRId;
            Owner = owner;
            AdminMemberId = adminMemberId;
            ContentType = uasInviteTransaction.TransactionFinalResponse.Header.ContentType;
            SDP = uasInviteTransaction.TransactionFinalResponse.Body;
            RemoteSDP = uasInviteTransaction.TransactionRequest.Body;
            Inserted = DateTimeOffset.UtcNow;
            Direction = SIPCallDirection.In;

            //DialogueId = GetDialogueId(CallId, LocalTag, RemoteTag);

            RemoteTarget = new SIPURI(uasInviteTransaction.TransactionRequest.URI.Scheme, SIPEndPoint.ParseSIPEndPoint(uasInviteTransaction.RemoteEndPoint.ToString()));
            ProxySendFrom = uasInviteTransaction.TransactionRequest.Header.ProxyReceivedOn;
            if (uasInviteTransaction.TransactionRequest.Header.Contact != null && uasInviteTransaction.TransactionRequest.Header.Contact.Count > 0)
            {
                RemoteTarget = uasInviteTransaction.TransactionRequest.Header.Contact[0].ContactURI.CopyOf();
                if (!uasInviteTransaction.TransactionRequest.Header.ProxyReceivedFrom.IsNullOrBlank())
                {
                    // Setting the Proxy-ReceivedOn header is how an upstream proxy will let an agent know it should mangle the contact. 
                    // Don't mangle private contacts if there is a Record-Route header. If a proxy is putting private IP's in a Record-Route header that's its problem.
                    if (RouteSet == null && IPSocket.IsPrivateAddress(RemoteTarget.Host))
                    {
                        SIPEndPoint remoteUASSIPEndPoint = SIPEndPoint.ParseSIPEndPoint(uasInviteTransaction.TransactionRequest.Header.ProxyReceivedFrom);
                        RemoteTarget.Host = remoteUASSIPEndPoint.GetIPEndPoint().ToString();
                    }
                }
            }
        }