Example #1
0
        /// <summary>
        /// Builds the REFER request to transfer an established call.
        /// </summary>
        /// <param name="sipDialogue">A SIP dialogue object representing the established call.</param>
        /// <param name="referToUri">The SIP URI to transfer the call to.</param>
        /// <returns>A SIP REFER request.</returns>
        private static SIPRequest GetReferRequest(SIPClientUserAgent uac, SIPURI referToUri)
        {
            SIPDialogue sipDialogue = uac.SIPDialogue;

            SIPRequest    referRequest    = new SIPRequest(SIPMethodsEnum.REFER, sipDialogue.RemoteTarget);
            SIPFromHeader referFromHeader = SIPFromHeader.ParseFromHeader(sipDialogue.LocalUserField.ToString());
            SIPToHeader   referToHeader   = SIPToHeader.ParseToHeader(sipDialogue.RemoteUserField.ToString());
            int           cseq            = sipDialogue.CSeq + 1;

            sipDialogue.CSeq++;

            SIPHeader referHeader = new SIPHeader(referFromHeader, referToHeader, cseq, sipDialogue.CallId);

            referHeader.CSeqMethod            = SIPMethodsEnum.REFER;
            referRequest.Header               = referHeader;
            referRequest.Header.Routes        = sipDialogue.RouteSet;
            referRequest.Header.ProxySendFrom = sipDialogue.ProxySendFrom;

            SIPViaHeader viaHeader = new SIPViaHeader(uac.ServerTransaction.LocalSIPEndPoint, CallProperties.CreateBranchId());

            referRequest.Header.Vias.PushViaHeader(viaHeader);

            referRequest.Header.ReferTo = referToUri.ToString();
            referRequest.Header.Contact = new List <SIPContactHeader>()
            {
                new SIPContactHeader(null, uac.ServerTransaction.TransactionRequest.Header.Contact.First().ContactURI)
            };
            referRequest.RemoteSIPEndPoint = uac.ServerTransaction.RemoteEndPoint;

            return(referRequest);
        }
Example #2
0
        public SIPFromHeader GetFromHeader()
        {
            SIPFromHeader fromHeader = null;

            // If the call is for a sipsorcery extension and a SwitchboardFrom header has been set use it.
            //if (CallDirection == SIPCallDirection.In && SwitchboardHeaders != null && !SwitchboardHeaders.SwitchboardOriginalFrom.IsNullOrBlank())
            //{
            //    fromHeader = SIPFromHeader.ParseFromHeader(SwitchboardHeaders.SwitchboardOriginalFrom);
            //}
            //else
            //{
            fromHeader = SIPFromHeader.ParseFromHeader(From);
            //}

            if (!FromDisplayName.IsNullOrBlank())
            {
                fromHeader.FromName = FromDisplayName;
            }
            if (!FromURIUsername.IsNullOrBlank())
            {
                fromHeader.FromURI.User = FromURIUsername;
            }
            if (!FromURIHost.IsNullOrBlank())
            {
                fromHeader.FromURI.Host = FromURIHost;
            }

            return(fromHeader);
        }
Example #3
0
        public SIPRequest GetRegisterRequest(string server, string toURIStr, string contactStr)
        {
            try
            {
                IPEndPoint localSIPEndPoint = m_sipTransport.GetDefaultTransportContact(SIPProtocolsEnum.UDP);

                SIPRequest registerRequest = new SIPRequest(SIPMethodsEnum.REGISTER, "sip:" + server);
                SIPHeader  registerHeader  = new SIPHeader(SIPFromHeader.ParseFromHeader(toURIStr), SIPToHeader.ParseToHeader(toURIStr), 1, CallProperties.CreateNewCallId());
                registerHeader.From.FromTag = CallProperties.CreateNewTag();
                registerHeader.Contact      = SIPContactHeader.ParseContactHeader(contactStr);
                SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());
                registerHeader.Via.PushViaHeader(viaHeader);
                registerHeader.CSeqMethod = SIPMethodsEnum.REGISTER;
                registerHeader.Expires    = SIPConstants.DEFAULT_REGISTEREXPIRY_SECONDS;

                registerRequest.Header = registerHeader;

                return(registerRequest);
            }
            catch (Exception excp)
            {
                logger.Error("Exception GetRegisterRequest. " + excp.Message);
                throw new ApplicationException("GetRegisterRequest " + excp.GetType().ToString() + ".  " + excp.Message);
            }
        }
Example #4
0
        /// <summary>
        /// Builds the REFER request to transfer an established call.
        /// </summary>
        /// <param name="sipDialogue">A SIP dialogue object representing the established call.</param>
        /// <param name="referToUri">The SIP URI to transfer the call to.</param>
        /// <returns>A SIP REFER request.</returns>
        private static SIPRequest GetReferRequest(SIPClientUserAgent uac, SIPURI referToUri)
        {
            SIPDialogue sipDialogue = uac.SIPDialogue;

            SIPRequest referRequest = new SIPRequest(SIPMethodsEnum.REFER, sipDialogue.RemoteTarget);

            referRequest.SetSendFromHints(uac.ServerTransaction.TransactionRequest.LocalSIPEndPoint);

            SIPFromHeader referFromHeader = SIPFromHeader.ParseFromHeader(sipDialogue.LocalUserField.ToString());
            SIPToHeader   referToHeader   = SIPToHeader.ParseToHeader(sipDialogue.RemoteUserField.ToString());
            int           cseq            = sipDialogue.CSeq + 1;

            sipDialogue.CSeq++;

            SIPHeader referHeader = new SIPHeader(referFromHeader, referToHeader, cseq, sipDialogue.CallId);

            referHeader.CSeqMethod            = SIPMethodsEnum.REFER;
            referRequest.Header               = referHeader;
            referRequest.Header.Routes        = sipDialogue.RouteSet;
            referRequest.Header.ProxySendFrom = sipDialogue.ProxySendFrom;
            referRequest.Header.Vias.PushViaHeader(SIPViaHeader.GetDefaultSIPViaHeader());
            referRequest.Header.ReferTo = referToUri.ToString();
            referRequest.Header.Contact = new List <SIPContactHeader>()
            {
                SIPContactHeader.GetDefaultSIPContactHeader()
            };

            return(referRequest);
        }
Example #5
0
        [Ignore] // Broken after NEtStandard migration.
        public void SingleProviderLegUnitTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            SIPRequest   inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI("sip:1234@localhost"));
            SIPHeader    inviteHeader  = new SIPHeader(SIPFromHeader.ParseFromHeader("<sip:joe@localhost>"), SIPToHeader.ParseToHeader("<sip:jane@localhost>"), 23, CallProperties.CreateNewCallId());
            SIPViaHeader viaHeader     = new SIPViaHeader("127.0.0.1", 5060, CallProperties.CreateBranchId());

            inviteHeader.Vias.PushViaHeader(viaHeader);
            inviteRequest.Header = inviteHeader;

            List <SIPProvider> providers = new List <SIPProvider>();
            SIPProvider        provider  = new SIPProvider(ProviderTypes.SIP, "test", "blueface", "test", "password", SIPURI.ParseSIPURIRelaxed("sip.blueface.ie"), null, null, null, null, 3600, null, null, null, false, false, null, null, null);

            providers.Add(provider);

            DialStringParser dialStringParser           = new DialStringParser(null, "test", null, providers, delegate { return(null); }, delegate { return(null); }, (host, wildcard) => { return(null); }, null, "test");
            Queue <List <SIPCallDescriptor> > callQueue = dialStringParser.ParseDialString(DialPlanContextsEnum.Script, inviteRequest, "blueface", null, null, null, null, null, null, null, null, CustomerServiceLevels.Free);

            Assert.IsNotNull(callQueue, "The call list should have contained a call.");
            Assert.IsTrue(callQueue.Count == 1, "The call queue list should have contained one leg.");

            List <SIPCallDescriptor> firstLeg = callQueue.Dequeue();

            Assert.IsNotNull(firstLeg, "The first call leg should exist.");
            Assert.IsTrue(firstLeg.Count == 1, "The first call leg should have had one switch call.");
            Assert.IsTrue(firstLeg[0].Username == "test", "The username for the first call leg was not correct.");
            Assert.IsTrue(firstLeg[0].Uri.ToString() == "sip:[email protected]", "The destination URI for the first call leg was not correct.");

            Console.WriteLine("---------------------------------");
        }
        private SIPRequest GetDummyINVITERequest(SIPURI dummyURI)
        {
            string     dummyFrom     = "<sip:[email protected]>";
            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dummyURI);

            SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(dummyFrom), new SIPToHeader(null, dummyURI, null), 1, CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();
            inviteHeader.Contact      = new List <SIPContactHeader> {
                SIPContactHeader.GetDefaultSIPContactHeader(inviteRequest.URI.Scheme)
            };
            inviteHeader.CSeqMethod = SIPMethodsEnum.INVITE;
            inviteHeader.UserAgent  = "unittest";
            inviteRequest.Header    = inviteHeader;

            SIPViaHeader viaHeader = SIPViaHeader.GetDefaultSIPViaHeader();

            inviteRequest.Header.Vias.PushViaHeader(viaHeader);

            inviteRequest.Body = "dummy";
            inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
            inviteRequest.Header.ContentType   = "application/sdp";

            return(inviteRequest);
        }
Example #7
0
            private SIPRequest GetDummyINVITERequest(SIPURI dummyURI)
            {
                string     dummyFrom     = "<sip:[email protected]>";
                string     dummyContact  = "sip:127.0.0.1:1234";
                SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dummyURI);

                SIPHeader inviteHeader =
                    new SIPHeader(SIPFromHeader.ParseFromHeader(dummyFrom), new SIPToHeader(null, dummyURI, null), 1, CallProperties.CreateNewCallId());

                inviteHeader.From.FromTag = CallProperties.CreateNewTag();
                inviteHeader.Contact      = SIPContactHeader.ParseContactHeader(dummyContact);
                inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
                inviteHeader.UserAgent    = "unittest";
                inviteRequest.Header      = inviteHeader;

                SIPViaHeader viaHeader =
                    new SIPViaHeader("127.0.0.1", 1234, CallProperties.CreateBranchId(), SIPProtocolsEnum.udp);

                inviteRequest.Header.Vias.PushViaHeader(viaHeader);

                inviteRequest.Body = "dummy";
                inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
                inviteRequest.Header.ContentType   = "application/sdp";

                return(inviteRequest);
            }
Example #8
0
        public object Convert(object value,
                              Type targetType,
                              object parameter,
                              CultureInfo culture)
        {
            SIPFromHeader fromheader = SIPFromHeader.ParseFromHeader(value as string);
            string        fromName   = (fromheader.FromName.IsNullOrBlank()) ? null : fromheader.FromName + " ";

            return(fromName + "<" + fromheader.FromURI.ToParameterlessString() + ">");
        }
Example #9
0
        public void ParseFromHeaderNoSpaceTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "UNAVAILABLE<sip:[email protected]:5060>;tag=abcd";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Assert.IsTrue(sipFromHeader.FromName == "UNAVAILABLE", "The From header name was not parsed correctly, name=" + sipFromHeader.FromName + ".");
            Assert.IsTrue(sipFromHeader.FromURI.ToString() == "sip:[email protected]:5060", "The From header URI was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromTag == "abcd", "The From header Tag was not parsed correctly.");
        }
Example #10
0
        public void ParseFromHeaderNoAngleBracketsTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "sip:[email protected]";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Assert.IsTrue(sipFromHeader.FromName == null, "The From header name was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromURI.ToString() == "sip:[email protected]", "The From header URI was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromTag == null, "The From header Tag was not parsed correctly.");
        }
Example #11
0
        public void ParseFromHeaderSocketDomainAndTagTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "User <sip:[email protected]:5090>;tag=abcdef";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Assert.IsTrue(sipFromHeader.FromName == "User", "The From header name was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromURI.ToString() == "sip:[email protected]:5090", "The From header URI was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromTag == "abcdef", "The From header Tag was not parsed correctly.");
        }
Example #12
0
        public void ParseFromHeaderNoUserTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "<sip:sip.domain.com>;tag=as6900b876";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Assert.IsTrue(sipFromHeader.FromName == null, "The From header name was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromURI.ToString() == "sip:sip.domain.com", "The From header URI was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromTag == "as6900b876", "The From header Tag was not parsed correctly.");
        }
 public void Load(DataRow cdrRow)
 {
     m_sipCDR               = new SIPCDR();
     m_sipCDR.CDRId         = new Guid(cdrRow["id"] as string);
     m_sipCDR.Owner         = cdrRow["owner"] as string;
     m_sipCDR.AdminMemberId = cdrRow["adminmemberid"] as string;
     Inserted               = DateTimeOffset.Parse(cdrRow["inserted"] as string);
     m_sipCDR.CallDirection = (cdrRow["direction"] as string == SIPCallDirection.In.ToString()) ? SIPCallDirection.In : SIPCallDirection.Out;
     Created = DateTimeOffset.Parse(cdrRow["created"] as string);
     m_sipCDR.Destination      = SIPURI.ParseSIPURI(cdrRow["dsturi"] as string);
     m_sipCDR.From             = SIPFromHeader.ParseFromHeader(cdrRow["fromheader"] as string);
     m_sipCDR.CallId           = cdrRow["callid"] as string;
     m_sipCDR.LocalSIPEndPoint = (!(cdrRow["localsocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["localsocket"] as string) : null;
     m_sipCDR.RemoteEndPoint   = (!(cdrRow["remotesocket"] as string).IsNullOrBlank()) ? SIPEndPoint.ParseSIPEndPoint(cdrRow["remotesocket"] as string) : null;
     m_sipCDR.BridgeId         = (!(cdrRow["bridgeid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["bridgeid"] as string) : Guid.Empty;
     if (cdrRow["inprogresstime"] != DBNull.Value && cdrRow["inprogresstime"] != null && !(cdrRow["inprogresstime"] as string).IsNullOrBlank())
     {
         InProgressTime = DateTimeOffset.Parse(cdrRow["inprogresstime"] as string);
     }
     else
     {
         InProgressTime = null;
     }
     m_sipCDR.ProgressStatus       = (cdrRow["inprogressstatus"] != null && cdrRow["inprogressstatus"] != DBNull.Value) ? Convert.ToInt32(cdrRow["inprogressstatus"]) : 0;
     m_sipCDR.ProgressReasonPhrase = cdrRow["inprogressreason"] as string;
     if (cdrRow["answeredtime"] != DBNull.Value && cdrRow["answeredtime"] != null && !(cdrRow["answeredtime"] as string).IsNullOrBlank())
     {
         AnsweredTime = DateTimeOffset.Parse(cdrRow["answeredtime"] as string);
     }
     else
     {
         AnsweredTime = null;
     }
     m_sipCDR.AnswerStatus       = (cdrRow["answeredstatus"] != DBNull.Value && cdrRow["answeredstatus"] != null) ? Convert.ToInt32(cdrRow["answeredstatus"]) : 0;
     m_sipCDR.AnswerReasonPhrase = cdrRow["answeredreason"] as string;
     if (cdrRow["hunguptime"] != DBNull.Value && cdrRow["hunguptime"] != null && !(cdrRow["hunguptime"] as string).IsNullOrBlank())
     {
         HungupTime = DateTimeOffset.Parse(cdrRow["hunguptime"] as string);
     }
     else
     {
         HungupTime = null;
     }
     m_sipCDR.HangupReason = cdrRow["hungupreason"] as string;
     m_sipCDR.InProgress   = (m_sipCDR.ProgressTime != null);
     m_sipCDR.IsAnswered   = (m_sipCDR.AnswerTime != null);
     m_sipCDR.IsHungup     = (m_sipCDR.HangupTime != null);
     if (cdrRow["answeredat"] != DBNull.Value && cdrRow["answeredat"] != null)
     {
         AnsweredAt = (DateTime)cdrRow["answeredat"];
     }
     m_sipCDR.DialPlanContextID = (!(cdrRow["dialplancontextid"] as string).IsNullOrBlank()) ? new Guid(cdrRow["dialplancontextid"] as string) : Guid.Empty;
 }
Example #14
0
        public void ParseFromHeaderNoNameTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "<sip:[email protected]>";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Assert.True(sipFromHeader.FromName == null, "The From header name was not parsed correctly.");
            Assert.True(sipFromHeader.FromURI.ToString() == "sip:[email protected]", "The From header URI was not parsed correctly.");
            Assert.True(sipFromHeader.FromTag == null, "The From header Tag was not parsed correctly.");
        }
        private void SendNotifyRequestForSubscription(SIPEventSubscription subscription)
        {
            try
            {
                subscription.SubscriptionDialogue.CSeq++;

                //logger.Debug(DateTime.Now.ToString("HH:mm:ss:fff") + " Sending NOTIFY request for " + subscription.SubscriptionDialogue.Owner + " event " + subscription.SubscriptionEventPackage.ToString()
                //    + " and " + subscription.ResourceURI.ToString() + " to " + subscription.SubscriptionDialogue.RemoteTarget.ToString() + ", cseq=" + (subscription.SubscriptionDialogue.CSeq) + ".");

                int secondsRemaining = Convert.ToInt32(subscription.LastSubscribe.AddSeconds(subscription.Expiry).Subtract(DateTime.Now).TotalSeconds % Int32.MaxValue);

                SIPRequest notifyRequest = m_sipTransport.GetRequest(SIPMethodsEnum.NOTIFY, subscription.SubscriptionDialogue.RemoteTarget);
                notifyRequest.Header.From              = SIPFromHeader.ParseFromHeader(subscription.SubscriptionDialogue.LocalUserField.ToString());
                notifyRequest.Header.To                = SIPToHeader.ParseToHeader(subscription.SubscriptionDialogue.RemoteUserField.ToString());
                notifyRequest.Header.Event             = subscription.SubscriptionEventPackage.ToString();
                notifyRequest.Header.CSeq              = subscription.SubscriptionDialogue.CSeq;
                notifyRequest.Header.CallId            = subscription.SubscriptionDialogue.CallId;
                notifyRequest.Body                     = subscription.GetNotifyBody();
                notifyRequest.Header.ContentLength     = notifyRequest.Body.Length;
                notifyRequest.Header.SubscriptionState = "active;expires=" + secondsRemaining.ToString();
                notifyRequest.Header.ContentType       = subscription.NotifyContentType;
                notifyRequest.Header.ProxySendFrom     = subscription.SubscriptionDialogue.ProxySendFrom;

                // If the outbound proxy is a loopback address, as it will normally be for local deployments, then it cannot be overriden.
                SIPEndPoint dstEndPoint = m_outboundProxy;
                if (m_outboundProxy != null && IPAddress.IsLoopback(m_outboundProxy.Address))
                {
                    dstEndPoint = m_outboundProxy;
                }
                else if (subscription.SubscriptionDialogue.ProxySendFrom != null)
                {
                    // The proxy will always be listening on UDP port 5060 for requests from internal servers.
                    dstEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, new IPEndPoint(SIPEndPoint.ParseSIPEndPoint(subscription.SubscriptionDialogue.ProxySendFrom).Address, m_defaultSIPPort));
                }

                SIPNonInviteTransaction notifyTransaction = m_sipTransport.CreateNonInviteTransaction(notifyRequest, dstEndPoint, m_sipTransport.GetDefaultSIPEndPoint(dstEndPoint), m_outboundProxy);
                notifyTransaction.NonInviteTransactionFinalResponseReceived += (local, remote, transaction, response) => { NotifyTransactionFinalResponseReceived(local, remote, transaction, response, subscription); };
                m_sipTransport.SendSIPReliable(notifyTransaction);

                //logger.Debug(notifyRequest.ToString());

                MonitorLogEvent_External(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.Notifier, SIPMonitorEventTypesEnum.NotifySent, "Notification sent for " + subscription.SubscriptionEventPackage.ToString() + " and " + subscription.ResourceURI.ToString() + " to " + subscription.SubscriptionDialogue.RemoteTarget.ToString() + " (cseq=" + notifyRequest.Header.CSeq + ").", subscription.SubscriptionDialogue.Owner));

                subscription.NotificationSent();
            }
            catch (Exception excp)
            {
                logger.Error("Exception SendNotifyRequestForSubscription. " + excp.Message);
                throw;
            }
        }
Example #16
0
        public void ParseFromHeaderTest()
        {
            Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

            string testFromHeader = "\"User\" <sip:[email protected]>;tag=abcdef";

            SIPFromHeader sipFromHeader = SIPFromHeader.ParseFromHeader(testFromHeader);

            Console.WriteLine("From header=" + sipFromHeader.ToString() + ".");

            Assert.IsTrue(sipFromHeader.FromName == "User", "The From header name was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromURI.ToString() == "sip:[email protected]", "The From header URI was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.FromTag == "abcdef", "The From header Tag was not parsed correctly.");
            Assert.IsTrue(sipFromHeader.ToString() == testFromHeader, "The From header ToString method did not produce the correct results.");
        }
Example #17
0
        public SIPRequest GetInviteRequest(string inviteURIStr, string fromURIStr, string body, int rtpPort)
        {
            SIPURI        inviteURI  = (inviteURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(inviteURIStr) : SIPURI.ParseSIPURI("sip:" + inviteURIStr);
            SIPFromHeader fromHeader = SIPFromHeader.ParseFromHeader(fromURIStr); // (fromURIStr.StartsWith("sip:")) ? SIPFromHeader.ParseFromHeader(fromURIStr) : SIPFromHeader.ParseFromHeader("sip:" + fromURIStr);
            SIPToHeader   toHeader   = new SIPToHeader(null, inviteURI, null);

            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, inviteURI);

            IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0];
            SIPHeader  inviteHeader     = new SIPHeader(fromHeader, toHeader, 1, CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();
            inviteHeader.Contact      = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString());
            inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
            //inviteHeader.UnknownHeaders.Add("BlueFace-Test: 12324");
            inviteRequest.Header = inviteHeader;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());

            inviteRequest.Header.Via.PushViaHeader(viaHeader);

            rtpPort = (rtpPort != 0) ? rtpPort : Crypto.GetRandomInt(10000, 20000);
            string sessionId = Crypto.GetRandomInt(1000, 5000).ToString();

            if (body != null && body.Trim().Length > 0)
            {
                inviteRequest.Body = body;
            }
            else
            {
                inviteRequest.Body =
                    "v=0" + CRLF +
                    "o=- " + sessionId + " " + sessionId + " IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "s=session" + CRLF +
                    "c=IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "t=0 0" + CRLF +
                    "m=audio " + rtpPort + " RTP/AVP 0 101" + CRLF +
                    "a=rtpmap:0 PCMU/8000" + CRLF +
                    "a=rtpmap:101 telephone-event/8000" + CRLF +
                    "a=fmtp:101 0-16" + CRLF +
                    "a=sendrecv";
            }

            inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
            inviteRequest.Header.ContentType   = "application/sdp";

            return(inviteRequest);
        }
        private SIPRequest GetByeRequest()
        {
            SIPRequest    byeRequest    = new SIPRequest(SIPMethodsEnum.BYE, SIPDialogue.RemoteTarget);
            SIPFromHeader byeFromHeader = SIPFromHeader.ParseFromHeader(SIPDialogue.LocalUserField.ToString());
            SIPToHeader   byeToHeader   = SIPToHeader.ParseToHeader(SIPDialogue.RemoteUserField.ToString());
            int           cseq          = SIPDialogue.CSeq + 1;

            SIPHeader byeHeader = new SIPHeader(byeFromHeader, byeToHeader, cseq, SIPDialogue.CallId);

            byeHeader.CSeqMethod            = SIPMethodsEnum.BYE;
            byeRequest.Header               = byeHeader;
            byeRequest.Header.Routes        = SIPDialogue.RouteSet;
            byeRequest.Header.ProxySendFrom = SIPDialogue.ProxySendFrom;
            byeRequest.Header.Vias.PushViaHeader(SIPViaHeader.GetDefaultSIPViaHeader());

            return(byeRequest);
        }
Example #19
0
        public SIPFromHeader GetFromHeader()
        {
            SIPFromHeader fromHeader = SIPFromHeader.ParseFromHeader(From);

            if (!FromDisplayName.IsNullOrBlank())
            {
                fromHeader.FromName = FromDisplayName;
            }
            if (!FromURIUsername.IsNullOrBlank())
            {
                fromHeader.FromURI.User = FromURIUsername;
            }
            if (!FromURIHost.IsNullOrBlank())
            {
                fromHeader.FromURI.Host = FromURIHost;
            }

            return(fromHeader);
        }
Example #20
0
        /// <summary>
        /// Builds a basic SIP request with the header fields set to correctly identify it as an
        /// in dialog request. Calling this method also increments the dialog's local CSeq counter.
        /// This is safe to do even if the request does not end up being sent.
        /// </summary>
        /// <param name="method">The method of the SIP request to create.</param>
        /// <returns>An in dialog SIP request.</returns>
        public SIPRequest GetInDialogRequest(SIPMethodsEnum method)
        {
            CSeq++;

            SIPRequest    inDialogRequest = new SIPRequest(method, RemoteTarget);
            SIPFromHeader fromHeader      = SIPFromHeader.ParseFromHeader(LocalUserField.ToString());
            SIPToHeader   toHeader        = SIPToHeader.ParseToHeader(RemoteUserField.ToString());
            int           cseq            = CSeq;

            SIPHeader header = new SIPHeader(fromHeader, toHeader, cseq, CallId);

            header.CSeqMethod                    = method;
            inDialogRequest.Header               = header;
            inDialogRequest.Header.Routes        = RouteSet;
            inDialogRequest.Header.ProxySendFrom = ProxySendFrom;
            inDialogRequest.Header.Vias.PushViaHeader(SIPViaHeader.GetDefaultSIPViaHeader());

            return(inDialogRequest);
        }
Example #21
0
        private SIPRequest GetByeRequest(SIPEndPoint localSIPEndPoint)
        {
            SIPRequest    byeRequest    = new SIPRequest(SIPMethodsEnum.BYE, m_sipDialogue.RemoteTarget);
            SIPFromHeader byeFromHeader = SIPFromHeader.ParseFromHeader(m_sipDialogue.LocalUserField.ToString());
            SIPToHeader   byeToHeader   = SIPToHeader.ParseToHeader(m_sipDialogue.RemoteUserField.ToString());
            int           cseq          = m_sipDialogue.CSeq + 1;

            SIPHeader byeHeader = new SIPHeader(byeFromHeader, byeToHeader, cseq, m_sipDialogue.CallId);

            byeHeader.CSeqMethod            = SIPMethodsEnum.BYE;
            byeRequest.Header               = byeHeader;
            byeRequest.Header.Routes        = m_sipDialogue.RouteSet;
            byeRequest.Header.ProxySendFrom = m_sipDialogue.ProxySendFrom;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId());

            byeRequest.Header.Vias.PushViaHeader(viaHeader);

            return(byeRequest);
        }
Example #22
0
        private SIPRequest GetInviteRequest(SIPDialogue dialogue, SIPEndPoint localSIPEndPoint, string body)
        {
            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, dialogue.RemoteTarget);

            SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader(dialogue.LocalUserField.ToString()), SIPToHeader.ParseToHeader(dialogue.RemoteUserField.ToString()), dialogue.CSeq, dialogue.CallId);
            SIPURI    contactURI   = new SIPURI(dialogue.RemoteTarget.Scheme, localSIPEndPoint);

            inviteHeader.Contact        = SIPContactHeader.ParseContactHeader("<" + contactURI.ToString() + ">");
            inviteHeader.CSeqMethod     = SIPMethodsEnum.INVITE;
            inviteRequest.Header        = inviteHeader;
            inviteRequest.Header.Routes = dialogue.RouteSet;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint, CallProperties.CreateBranchId());

            inviteRequest.Header.Vias.PushViaHeader(viaHeader);

            inviteRequest.Body = body;
            inviteRequest.Header.ContentLength = body.Length;
            inviteRequest.Header.ContentType   = m_sdpContentType;

            return(inviteRequest);
        }
Example #23
0
            private SIPRequest GetInviteRequest(IPEndPoint localContact, string inviteBody, IPEndPoint dstEndPoint)
            {
                SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, SIPURI.ParseSIPURI("sip:" + dstEndPoint));

                SIPHeader inviteHeader = new SIPHeader(SIPFromHeader.ParseFromHeader("<sip:" + localContact + ">"), SIPToHeader.ParseToHeader("<sip:" + dstEndPoint + ">"), 1, CallProperties.CreateNewCallId());

                inviteHeader.From.FromTag = CallProperties.CreateNewTag();
                inviteHeader.Contact      = SIPContactHeader.ParseContactHeader("sip:" + localContact);
                inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
                inviteHeader.UserAgent    = "unit test";
                inviteRequest.Header      = inviteHeader;

                SIPViaHeader viaHeader = new SIPViaHeader(localContact.Address.ToString(), localContact.Port, CallProperties.CreateBranchId(), SIPProtocolsEnum.udp);

                inviteRequest.Header.Vias.PushViaHeader(viaHeader);

                //inviteRequest.Body = inviteBody;
                //inviteRequest.Header.ContentLength = inviteBody.Length;
                inviteRequest.Header.ContentType = "application/sdp";

                return(inviteRequest);
            }