/// <summary>
        /// transfers the <see cref="AudioVideoCall"/>> as an asynchronous operation.
        /// </summary>
        /// <param name="transferTarget">The transfer target.</param>
        /// <param name="replacesCallContext">The replaces call context.</param>
        /// <param name="loggingContext">The logging context.</param>
        /// <returns>Task&lt;ITransfer&gt;.</returns>
        /// <exception cref="CapabilityNotAvailableException">Link to start transfer of AudioVideo is not available.</exception>
        /// <exception cref="RemotePlatformServiceException">Timeout to get incoming transfer started event from platformservice!</exception>

        public async Task <ITransfer> TransferAsync(SipUri transferTarget, string replacesCallContext, LoggingContext loggingContext = null)
        {
            string href = PlatformResource?.StartTransferLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to start transfer of AudioVideo is not available.");
            }

            Uri transferLink = UriHelper.CreateAbsoluteUri(BaseUri, href);

            var operationId = Guid.NewGuid().ToString();
            var tcs         = new TaskCompletionSource <Transfer>();

            this.HandleNewTransferOperationKickedOff(operationId, tcs);
            var input = new TransferOperationInput()
            {
                To = transferTarget.ToString(), ReplacesCallContext = replacesCallContext, OperationId = operationId
            };

            await PostRelatedPlatformResourceAsync(transferLink, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            Transfer result = null;

            try
            {
                result = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false);
            }
            catch (TimeoutException)
            {
                throw new RemotePlatformServiceException("Timeout to get incoming transfer started event from platformservice!");
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Add bridged participant
        /// </summary>
        /// <param name="loggingContext"></param>
        /// <param name="displayName"></param>
        /// <param name="sipUri"></param>
        /// <param name="enableMessageFilter"></param>
        /// <returns>the bridgeParticipant added</returns>
        public async Task <IBridgedParticipant> AddBridgedParticipantAsync(string displayName, SipUri sipUri, bool enableMessageFilter, LoggingContext loggingContext = null)
        {
            if (sipUri == null)
            {
                throw new ArgumentNullException(nameof(sipUri));
            }

            string href = PlatformResource?.BridgedParticipantsResourceLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to get BridgedsParticipants is not available.");
            }

            Uri bridgeUri = UriHelper.CreateAbsoluteUri(this.BaseUri, href);

            var input = new BridgedParticipantInput()
            {
                DisplayName        = displayName,
                MessageFilterState = enableMessageFilter ? FilterState.Enabled : FilterState.Disabled,
                Uri = sipUri.ToString()
            };

            var tcs = new TaskCompletionSource <BridgedParticipant>();

            m_bridgedParticipantTcses.TryAdd(sipUri.ToString().ToLower(), tcs);
            //Waiting for bridgedParticipant operation added
            await PostRelatedPlatformResourceAsync(bridgeUri, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            BridgedParticipant result = null;

            try
            {
                result = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false);
            }
            catch (TimeoutException)
            {
                throw new RemotePlatformServiceException("Timeout to get bridged participant added from platformservice!");
            }

            if (result == null)
            {
                throw new RemotePlatformServiceException("Platformservice do not deliver a bridged participant added resource with uri " + sipUri);
            }

            return(result);
        }
 public void Add(SipUri uri, string authenticationUserName)
 {
     // using unique user names.
     var reg = new Registration();
     reg.Uri = uri;
     _authenticationIndex.Add(authenticationUserName, reg);
     _registrations.Add(uri.ToString(), reg);
 }
Esempio n. 4
0
        public Contact Find(SipUri uri)
        {
            var contact = (from c in this.contactList
                           where string.Equals(c.Uri.ToString(), uri.ToString(), StringComparison.CurrentCultureIgnoreCase) == true
                           select c).SingleOrDefault();

            return(contact);
        }
Esempio n. 5
0
        public void Add(SipUri uri, string authenticationUserName)
        {
            // using unique user names.
            var reg = new Registration();

            reg.Uri = uri;
            _authenticationIndex.Add(authenticationUserName, reg);
            _registrations.Add(uri.ToString(), reg);
        }
Esempio n. 6
0
        public void SipUri_Headers()
        {
            SipUri uri;

            uri = new SipUri("sip:[email protected]:1234;one=two;three=four?arg1=value1&arg2=value2");
            Assert.AreEqual("sip:[email protected]:1234;one=two;three=four?arg1=value1&arg2=value2", uri.ToString());
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("two", uri.Parameters["ONE"]);
            Assert.AreEqual("four", uri.Parameters["three"]);
            Assert.AreEqual("arg1", uri.Headers[0].Name);
            Assert.AreEqual("value1", uri.Headers[0].FullText);
            Assert.AreEqual("arg2", uri.Headers[1].Name);
            Assert.AreEqual("value2", uri.Headers[1].FullText);

            uri = new SipUri("sip:[email protected]:1234?arg1=value1&arg2=value2");
            Assert.AreEqual("sip:[email protected]:1234?arg1=value1&arg2=value2", uri.ToString());
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("arg1", uri.Headers[0].Name);
            Assert.AreEqual("value1", uri.Headers[0].FullText);
            Assert.AreEqual("arg2", uri.Headers[1].Name);
            Assert.AreEqual("value2", uri.Headers[1].FullText);

            uri = new SipUri("sip:[email protected]?arg1=value1&arg2=value2");
            Assert.AreEqual("sip:[email protected]?arg1=value1&arg2=value2", uri.ToString());
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("arg1", uri.Headers[0].Name);
            Assert.AreEqual("value1", uri.Headers[0].FullText);
            Assert.AreEqual("arg2", uri.Headers[1].Name);
            Assert.AreEqual("value2", uri.Headers[1].FullText);

            uri = new SipUri("sip:lilltek.com?arg1=value1&arg2=value2");
            Assert.AreEqual("sip:lilltek.com?arg1=value1&arg2=value2", uri.ToString());
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("arg1", uri.Headers[0].Name);
            Assert.AreEqual("value1", uri.Headers[0].FullText);
            Assert.AreEqual("arg2", uri.Headers[1].Name);
            Assert.AreEqual("value2", uri.Headers[1].FullText);

            uri = new SipUri("sip:lilltek.com:1234?arg1=value1&arg2=value2");
            Assert.AreEqual("sip:lilltek.com:1234?arg1=value1&arg2=value2", uri.ToString());
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("arg1", uri.Headers[0].Name);
            Assert.AreEqual("value1", uri.Headers[0].FullText);
            Assert.AreEqual("arg2", uri.Headers[1].Name);
            Assert.AreEqual("value2", uri.Headers[1].FullText);
        }
Esempio n. 7
0
 /// <summary>
 /// Update uri used when registering.
 /// </summary>
 /// <param name="uri"></param>
 /// <remarks>
 /// User might use a different domain than the one
 /// added to the database. Update it so that we can find the user.
 /// </remarks>
 public void UpdateUri(Registration registration, SipUri uri)
 {
     if (uri.Equals(registration.Uri))
     {
         return;
     }
     _registrations.Add(uri.ToString(), registration);
     _registrations.Remove(registration.Uri.ToString());
     registration.Uri = uri;
 }
Esempio n. 8
0
        public void SipUri_Clone()
        {
            SipUri uri, clone;

            uri   = new SipUri("sip:[email protected]:1234;p1=one;p2=two?h1=header1&h2=header2");
            clone = uri.Clone();
            Assert.AreEqual(uri.ToString(), clone.ToString());
            Assert.AreEqual(uri.IsSecure, clone.IsSecure);
            Assert.AreEqual(uri.User, clone.User);
            Assert.AreEqual(uri.Host, clone.Host);
            Assert.AreEqual(uri.Port, clone.Port);
        }
Esempio n. 9
0
        public void SipUri_Cast()
        {
            SipUri uri;

            Assert.IsNull((SipUri)(string)null);
            Assert.IsNull((string)(SipUri)null);

            uri = new SipUri(SipTransportType.TCP, new NetworkBinding("lilltek.com", 55));
            Assert.AreEqual("sip:lilltek.com:55;transport=tcp", (string)uri);

            uri = (SipUri)"sip:lilltek.com:55;transport=tcp";
            Assert.AreEqual("sip:lilltek.com:55;transport=tcp", uri.ToString());
        }
Esempio n. 10
0
        /// <summary>
        /// Start messaging
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="to"></param>
        /// <param name="callbackUrl"></param>
        /// <returns></returns>
        public Task <IMessagingInvitation> StartMessagingAsync(string subject, SipUri to, string callbackContext, LoggingContext loggingContext = null)
        {
            Logger.Instance.Information(string.Format("[Communication] calling startMessaging. LoggingContext: {0}",
                                                      loggingContext == null ? string.Empty : loggingContext.ToString()));

            string href = PlatformResource?.StartMessagingLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to start messaging is not available.");
            }

            return(StartMessagingWithIdentityAsync(subject, to.ToString(), callbackContext, null, href, null, null, loggingContext));
        }
Esempio n. 11
0
        /// <exception cref="InvalidOperationException"><c>InvalidOperationException</c>.</exception>
        private static void Test(string uriString)
        {
            var reader = new StringReader();

            reader.Assign(uriString);

            SipUri uri = Parse(reader);

            if (uri == null)
            {
                throw new InvalidOperationException("Failed to parse: " + uriString);
            }

            Assert.Equal(uriString, uri.ToString());
        }
Esempio n. 12
0
        public async void TestSetup()
        {
            m_restfulClient = new MockRestfulClient();
            Logger.RegisterLogger(new ConsoleLogger());
            m_loggingContext = new LoggingContext(Guid.NewGuid());
            TestHelper.InitializeTokenMapper();

            Uri    discoverUri           = TestHelper.DiscoverUri;
            Uri    baseUri               = UriHelper.GetBaseUriFromAbsoluteUri(discoverUri.ToString());
            SipUri ApplicationEndpointId = TestHelper.ApplicationEndpointUri;

            var discover = new Discover(m_restfulClient, baseUri, discoverUri, this);
            await discover.RefreshAndInitializeAsync(ApplicationEndpointId.ToString(), m_loggingContext).ConfigureAwait(false);

            m_application = discover.Application;
        }
Esempio n. 13
0
        /// <summary>
        /// add participant as an asynchronous operation.
        /// </summary>
        /// <param name="targetSip">The target sip.</param>
        /// <param name="loggingContext">The logging context.</param>
        /// <returns>Task&lt;IParticipantInvitation&gt;.</returns>
        /// <exception cref="CapabilityNotAvailableException">Link to add participant is not available.</exception>
        /// <exception cref="RemotePlatformServiceException">
        /// Timeout to get Participant invitation started event from platformservice!
        /// or
        /// Platformservice do not deliver a ParticipantInvitation resource with operationId " + operationId
        /// </exception>
        public async Task <IParticipantInvitation> AddParticipantAsync(SipUri targetSip, LoggingContext loggingContext = null)

        {
            string href = PlatformResource?.AddParticipantResourceLink?.Href;

            if (string.IsNullOrEmpty(href))
            {
                throw new CapabilityNotAvailableException("Link to add participant is not available.");
            }

            var communication = this.Parent as Communication;

            IInvitation invite      = null;
            string      operationId = Guid.NewGuid().ToString();
            TaskCompletionSource <IInvitation> tcs = new TaskCompletionSource <IInvitation>();

            communication.HandleNewInviteOperationKickedOff(operationId, tcs);

            var input = new AddParticipantInvitationInput
            {
                OperationContext = operationId,
                To = targetSip.ToString()
            };

            Uri addparticipantUrl = UriHelper.CreateAbsoluteUri(this.BaseUri, href);

            await this.PostRelatedPlatformResourceAsync(addparticipantUrl, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false);

            try
            {
                invite = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false);
            }
            catch (TimeoutException)
            {
                throw new RemotePlatformServiceException("Timeout to get Participant invitation started event from platformservice!");
            }

            var result = invite as ParticipantInvitation;

            if (result == null)
            {
                throw new RemotePlatformServiceException("Platformservice do not deliver a ParticipantInvitation resource with operationId " + operationId);
            }

            return(result);
        }
Esempio n. 14
0
        public void SipUri_Parameters()
        {
            SipUri uri;

            uri = new SipUri("sip:[email protected];one=two;three=four");
            Assert.AreEqual("sip:[email protected];one=two;three=four", uri.ToString());
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("two", uri.Parameters["ONE"]);
            Assert.AreEqual("four", uri.Parameters["three"]);

            uri = new SipUri("sip:[email protected]:1234;one=two;three=four");
            Assert.AreEqual("sip:[email protected]:1234;one=two;three=four", uri.ToString());
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("two", uri.Parameters["ONE"]);
            Assert.AreEqual("four", uri.Parameters["three"]);

            uri = new SipUri("sip:lilltek.com;one=two;three=four");
            Assert.IsFalse(uri.IsSecure);
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("sip:lilltek.com;one=two;three=four", uri.ToString());

            uri = new SipUri("sip:lilltek.com:1234;one=two;three=four");
            Assert.IsFalse(uri.IsSecure);
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("sip:lilltek.com:1234;one=two;three=four", uri.ToString());

            uri = new SipUri("sip:lilltek.com:1234;one=two;three=four");
            Assert.IsNull(uri["five"]);
            uri["five"] = "six";
            Assert.AreEqual("six", uri["five"]);
            Assert.AreEqual("two", uri["one"]);
            uri["one"] = "xxx";
            Assert.AreEqual("xxx", uri["one"]);
            uri["three"] = null;
            Assert.IsFalse(uri.Parameters.ContainsKey("three"));
        }
Esempio n. 15
0
        public static SipMessage LeaveMsgPacket(SipUri sipUri, string msgContent)
        {
            SipRequest   req          = new SipRequest(SipMethodName.Message, DEFAULT_URI);
            SipHeadField hFrom        = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString());
            SipHeadField hCallID      = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString());
            SipHeadField hCSeq        = new SipHeadField(SipHeadFieldName.CSeq, "2 M");
            SipHeadField hTo          = new SipHeadField(SipHeadFieldName.To, sipUri.ToString());
            SipHeadField hContentType = new SipHeadField(SipHeadFieldName.ContentType, "text/plain");
            SipHeadField hSupported   = new SipHeadField(SipHeadFieldName.Supported, "SaveHistory");

            req.HeadFields.Add(hFrom);
            req.HeadFields.Add(hCallID);
            req.HeadFields.Add(hCSeq);
            req.HeadFields.Add(hTo);
            req.HeadFields.Add(hContentType);
            req.HeadFields.Add(hSupported);
            req.Body = msgContent;
            return(req);
        }
Esempio n. 16
0
        /// <summary>
        /// SMS packet.
        /// </summary>
        /// <param name="sipUri">The sipURI.</param>
        /// <param name="msgContent">Content of the Msg.</param>
        /// <param name="isCatMsg">是否是长短信</param>
        /// <returns></returns>
        public static SipMessage SMSPacket(SipUri sipUri, string msgContent, bool isCatMsg)
        {
            string eventName = (isCatMsg == true ? "SendCatSMS" : "SendSMS");

            SipRequest   req     = new SipRequest(SipMethodName.Message, DEFAULT_URI);
            SipHeadField hFrom   = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString());
            SipHeadField hCallID = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString());
            SipHeadField hCSeq   = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Message);
            SipHeadField hTo     = new SipHeadField(SipHeadFieldName.To, sipUri.ToString());
            SipHeadField hEvent  = new SipHeadField(SipHeadFieldName.Event, eventName);

            req.HeadFields.Add(hFrom);
            req.HeadFields.Add(hCallID);
            req.HeadFields.Add(hCSeq);
            req.HeadFields.Add(hTo);
            req.HeadFields.Add(hEvent);
            req.Body = msgContent;
            return(req);
        }
Esempio n. 17
0
        /// <summary>
        /// Accept the incoming call and set up b2b call with conference or target user
        /// </summary>
        /// <param name="loggingContext"></param>
        /// <param name="meetingUri">the onlinemeeting uri if you want to bridge to a conference</param>
        /// <param name="to">the sip uri if you want to bridge to a single person</param>
        /// <returns></returns>
        private Task AcceptAndBridgeAsync(string meetingUri, SipUri to, LoggingContext loggingContext = null)
        {
            Logger.Instance.Information(string.Format("[AudioVideoInviation] calling AcceptAndBridgeAsync. LoggingContext:{0}", loggingContext == null ? string.Empty : loggingContext.ToString()));

            string href = PlatformResource?.AcceptAndBridgeAudioVideoLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to accept and bridge is not available.");
            }

            var input = new AcceptAndBridgeAudioVideoInput
            {
                MeetingUri = meetingUri,
                ToUri      = to.ToString()
            };

            Uri bridge = UriHelper.CreateAbsoluteUri(this.BaseUri, href);

            return(this.PostRelatedPlatformResourceAsync(bridge, input, new ResourceJsonMediaTypeFormatter(), loggingContext));
        }
Esempio n. 18
0
        public void Shall_stringify_header()
        {
            var uri = new SipUri
            {
                Host       = "1.2.3.4",
                Port       = "1234",
                Username   = "******",
                Password   = "******",
                Parameters =
                {
                    new SipUriParameter("param", "foo")
                },
                Headers =
                {
                    new SipUriParameter("header", "bar")
                }
            };

            Assert.That(
                uri.ToString(),
                Is.EqualTo("sip:admin:[email protected]:1234;param=foo?header=bar"));
        }
Esempio n. 19
0
        /// <summary>
        /// Forwards the <see cref="AudioVideoInvitation"/> asynchronous.
        /// </summary>
        /// <param name="loggingContext">The logging context.</param>
        /// <param name="forwardTarget">The forward target.</param>
        /// <returns>Task&lt;HttpResponseMessage&gt;.</returns>
        /// <exception cref="System.ArgumentNullException">forwardTarget - forwardTarget</exception>
        /// <exception cref="CapabilityNotAvailableException">Link to forward AudioVideoInvitation is not available.</exception>

        public Task <HttpResponseMessage> ForwardAsync(SipUri forwardTarget, LoggingContext loggingContext = null)

        {
            if (forwardTarget == null)
            {
                throw new ArgumentNullException(nameof(forwardTarget));
            }

            string href = PlatformResource?.ForwardLink?.Href;

            if (string.IsNullOrWhiteSpace(href))
            {
                throw new CapabilityNotAvailableException("Link to forward AudioVideoInvitation is not available.");
            }

            Uri forwardLink = UriHelper.CreateAbsoluteUri(BaseUri, href);

            var input = new ForwardInput()
            {
                To = forwardTarget.ToString()
            };

            return(PostRelatedPlatformResourceAsync(forwardLink, input, new ResourceJsonMediaTypeFormatter(), loggingContext));
        }
Esempio n. 20
0
 /// <summary>
 /// Update uri used when registering.
 /// </summary>
 /// <param name="uri"></param>
 /// <remarks>
 /// User might use a different domain than the one
 /// added to the database. Update it so that we can find the user.
 /// </remarks>
 public void UpdateUri(Registration registration, SipUri uri)
 {
     if (uri.Equals(registration.Uri))
         return;
     _registrations.Add(uri.ToString(), registration);
     _registrations.Remove(registration.Uri.ToString());
     registration.Uri = uri;
 }
Esempio n. 21
0
        /// <summary>
        /// Get registration for a user.
        /// </summary>
        /// <param name="uri"></param>
        /// <returns></returns>
        public Registration Get(SipUri uri)
        {
            Registration registration;

            return(_registrations.TryGetValue(uri.ToString(), out registration) ? registration : null);
        }
Esempio n. 22
0
 /// <summary>
 /// Get registration for a user.
 /// </summary>
 /// <param name="uri"></param>
 /// <returns></returns>
 public Registration Get(SipUri uri)
 {
     Registration registration;
     return _registrations.TryGetValue(uri.ToString(), out registration) ? registration : null;
 }
Esempio n. 23
0
        public void SipUri_Basic()
        {
            SipUri uri;

            uri = new SipUri("jeff", "lilltek.com");
            Assert.AreEqual("sip:[email protected]", uri.ToString());

            uri = new SipUri("jeff", "lilltek.com", 5060);
            Assert.AreEqual("sip:[email protected]:5060", uri.ToString());

            uri          = new SipUri("jeff", "lilltek.com", 5060);
            uri.IsSecure = true;
            Assert.AreEqual("sips:[email protected]:5060", uri.ToString());

            uri = new SipUri("sip:[email protected]");
            Assert.IsFalse(uri.IsSecure);
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("sip:[email protected]", uri.ToString());

            uri = new SipUri("sips:[email protected]:1234");
            Assert.IsTrue(uri.IsSecure);
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("sips:[email protected]:1234", uri.ToString());

            uri = (SipUri)"sips:[email protected]:1234";
            Assert.IsTrue(uri.IsSecure);
            Assert.AreEqual("jeff", uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("sips:[email protected]:1234", uri.ToString());

            uri = new SipUri("sip:lilltek.com");
            Assert.IsFalse(uri.IsSecure);
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(NetworkPort.SIP, uri.Port);
            Assert.AreEqual("sip:lilltek.com", uri.ToString());

            uri = new SipUri("sip:lilltek.com:1234");
            Assert.IsFalse(uri.IsSecure);
            Assert.IsNull(uri.User);
            Assert.AreEqual("lilltek.com", uri.Host);
            Assert.AreEqual(1234, uri.Port);
            Assert.AreEqual("sip:lilltek.com:1234", uri.ToString());

            Assert.IsTrue(SipUri.TryParse("sip:lilltek.com:1234", out uri));
            Assert.AreEqual("sip:lilltek.com:1234", uri.ToString());

            uri = new SipUri(SipTransportType.UDP, null, "test.com", 55);
            Assert.AreEqual("sip:test.com:55", uri.ToString());

            uri = new SipUri(SipTransportType.TCP, "jeff", "test.com", 55);
            Assert.AreEqual("sip:[email protected]:55;transport=tcp", uri.ToString());

            uri = new SipUri(SipTransportType.TLS, new NetworkBinding(IPAddress.Parse("127.0.0.1"), 55));
            Assert.AreEqual("sips:127.0.0.1:55", uri.ToString());

            uri = new SipUri(SipTransportType.TCP, new NetworkBinding("lilltek.com", 55));
            Assert.AreEqual("sip:lilltek.com:55;transport=tcp", uri.ToString());
        }
Esempio n. 24
0
        public static SipMessage AddBuddy(SipUri buddyUri, string desc)
        {
            if (string.IsNullOrEmpty(desc))
            {
                desc = Ower.NickName;
            }
            string       msgContent = string.Format("<args><contacts><buddies><buddy uri=\"{0}\" buddy-lists=\"\" desc=\"{1}\" expose-mobile-no=\"1\" expose-name=\"1\" addbuddy-phrase-id=\"0\" /></buddies></contacts></args>", buddyUri.ToString(), desc);
            SipRequest   req        = new SipRequest(SipMethodName.Service, DEFAULT_URI);
            SipHeadField hFrom      = new SipHeadField(SipHeadFieldName.From, Ower.Uri.Sid.ToString());
            SipHeadField hCallID    = new SipHeadField(SipHeadFieldName.CallID, Ower.Conncetion.NextCallID().ToString());
            SipHeadField hCSeq      = new SipHeadField(SipHeadFieldName.CSeq, "1 " + SipMethodName.Service);
            SipHeadField hEvent     = new SipHeadField(SipHeadFieldName.Event, "AddBuddyV4");

            req.HeadFields.Add(hFrom);
            req.HeadFields.Add(hCallID);
            req.HeadFields.Add(hCSeq);
            req.HeadFields.Add(hEvent);
            req.Body = msgContent;
            return(req);
        }