public void when_parse_called_with_valid_sip_uri_with_alfabet_extension_and_pwd_and_domain_as_dns_and_port__should_fill_valid_properties() { var sut = new SipUriParser("sip:test:[email protected]:5080"); Assert.AreEqual("tempuri.org", sut.Domain); Assert.AreEqual("test", sut.Extension); Assert.AreEqual("5080", sut.Port); Assert.AreEqual("test", sut.Password); }
public void when_parse_called_with_valid_sip_uri_with_domain_as_dns__should_fill_valid_properties() { var sut = new SipUriParser("sip:tempuri.org"); Assert.AreEqual("tempuri.org", sut.Domain); Assert.AreEqual("", sut.Extension); Assert.AreEqual("5060", sut.Port); Assert.AreEqual("", sut.Password); }
public void when_parse_called_with_valid_sip_uri_with_alfabet_extension_and_domain_as_dns_with_underscore__should_fill_valid_properties() { var sut = new SipUriParser("sip:[email protected]_i.com"); Assert.AreEqual("temp.ur_i.com", sut.Domain); Assert.AreEqual("sip", sut.Extension); Assert.AreEqual("5060", sut.Port); Assert.AreEqual("", sut.Password); }
public void when_parse_called_with_valid_sip_uri_with_domain_as_IP__should_fill_valid_properties() { var sut = new SipUriParser("<sip:12.25.12.1>"); Assert.AreEqual("12.25.12.1", sut.Domain); Assert.AreEqual("", sut.Extension); Assert.AreEqual("5060", sut.Port); Assert.AreEqual("", sut.Password); }
public ICall MakeCall(IAccount account, string destinationUri) { Helper.GuardNotNull(account); return(MakeCall(x => { var sipUriParser = new SipUriParser(destinationUri); return x.From(account).To(sipUriParser.Extension).At(sipUriParser.Domain).Through(sipUriParser.Port).Call(); })); }
internal ContactInformation(string uri) { Debug.Assert(!string.IsNullOrEmpty(uri)); m_uri = uri; m_contactCards = new List <ContactCard>(); SipUriParser parser = new SipUriParser(uri); m_displayName = parser.User; }
public void Parse_ValidSipUriWithAlfabetDomainAsDnsWithTransportHeaderAndSomaOtherHeader_ValidPropertiesFilled() { var sut = new SipUriParser("sip:tempuri.org;transport=tcp;otherheader"); Assert.AreEqual("tempuri.org", sut.Domain); Assert.AreEqual("", sut.Extension); Assert.AreEqual("5060", sut.Port); Assert.AreEqual("", sut.Password); Assert.AreEqual(2, sut.Headers.Count); Assert.AreEqual(TransportType.Tcp, sut.Transport); }
public void when_parse_called_with_valid_sip_uri_with_alfabet_domain_as_dns_with_transport_header__should_fill_valid_properties() { var sut = new SipUriParser("sip:tempuri.org;transport=tcp"); Assert.AreEqual("tempuri.org", sut.Domain); Assert.AreEqual("", sut.Extension); Assert.AreEqual("5060", sut.Port); Assert.AreEqual("", sut.Password); Assert.AreEqual(1, sut.Headers.Count); Assert.AreEqual(TransportType.Tcp, sut.Transport); }
public void when_parse_called_with_valid_sip_uri_with_alfabet_extension_and_pwd_and_domain_as_dns_and_port_with_transport_header__should_fill_valid_properties() { var sut = new SipUriParser("sip:test:[email protected]:5080;transport=tcp"); Assert.AreEqual("tempuri.org", sut.Domain); Assert.AreEqual("test", sut.Extension); Assert.AreEqual("5080", sut.Port); Assert.AreEqual("test", sut.Password); Assert.AreEqual(1, sut.Headers.Count); Assert.AreEqual(TransportType.Tcp, sut.Transport); }
/// <summary> /// Unsubscribe from a specific uri. /// </summary> /// <param name="sipUri">Sip uri to unsubscribe from. Cannot be null or empty.</param> private void Unsubscribe(string sipUri) { Debug.Assert(!String.IsNullOrEmpty(sipUri), "Sip uri is null or empty"); SipUriParser uriParser; if (SipUriParser.TryParse(sipUri, out uriParser)) { m_remotePresenceView.StartUnsubscribingToPresentities(new List <string> { sipUri }); } }
internal AcdPlatformAnonymousSubscriberUriChangedEventArgs(string anonymousSubscriberUri) { SipUriParser parser; if (SipUriParser.TryParse(anonymousSubscriberUri, out parser)) { _anonymousSubscriberUri = anonymousSubscriberUri; } else { throw new ArgumentException("AcdPlatformAnonymousSubscriberUriChangedEventArgs requires a valid Uri"); } }
/// <summary> /// Subscribe to a specific uri. /// </summary> /// <param name="sipUri">Sip uri to subscribe to. Cannot be null or empty.</param> private void Subscribe(string sipUri) { Debug.Assert(!String.IsNullOrEmpty(sipUri), "Sip uri is null or empty"); SipUriParser uriParser; if (SipUriParser.TryParse(sipUri, out uriParser)) { var subscriptionTargets = new List <RemotePresentitySubscriptionTarget>(); subscriptionTargets.Add(new RemotePresentitySubscriptionTarget(uriParser.ToString())); // Immediately fires NotificationReceived with current presence of targets m_remotePresenceView.StartSubscribingToPresentities(subscriptionTargets); } }
internal bool DisallowParticipant(string participantUri) { SipUriParser parser; bool result = false; if (SipUriParser.TryParse(participantUri, out parser)) { lock (_syncRoot) { result = _listOfAuthorizedParticipants.Remove(participantUri); } } return(result); }
internal bool AuthorizeParticipant(string participantUri) { SipUriParser parser; if (SipUriParser.TryParse(participantUri, out parser)) { lock (_syncRoot) { _listOfAuthorizedParticipants.Add(participantUri); } List <ConversationParticipant> listOfLobbyParticipants = new List <ConversationParticipant>(_conversation.GetLobbyParticipants()); listOfLobbyParticipants.ForEach(cp => { if (SipUriCompare.Equals(cp.Uri, participantUri)) { try { _conversation.ConferenceSession.LobbyManager.BeginAdmitLobbyParticipants(new List <ConversationParticipant>() { cp }, ar => { LobbyManager lobbyMgr = ar.AsyncState as LobbyManager; try { lobbyMgr.EndAdmitLobbyParticipants(ar); } catch (RealTimeException rtex) { _logger.Log("AcdConferenceServices failed to end admit a participant in the lobby", rtex); } }, _conversation.ConferenceSession.LobbyManager); } catch (InvalidOperationException ivoex) { _logger.Log("AcdConferenceServicesAnchor failed to begin admit a participant in the lobby", ivoex); } } }); return(true); } return(false); }
/// <summary> /// This function receives asynchronous one-way /// notification for requests. /// </summary> /// <remarks> /// The request handler's name must be the name of the /// function that is given in the SPL Dispatch function /// for SIP request async calls. /// </remarks> /// <param name="sender">not used</param> /// <param name="e">the arguments for async call</param> public void RequestNotificationHandler(object sender, NotificationReceivedEventArgs e) { object[] parameters = e.Parameters; // First argument from manifest is SIP Method, // use it for statistics statistics.Update(Request.GetStandardMethod((string)parameters[0])); // Next two arguments are From and To user, use it // for statistics statistics.Update(SipUriParser.GetUserAtHost((string)parameters[1])); statistics.Update(SipUriParser.GetUserAtHost((string)parameters[2])); // Raise the event finally this.StateChangeListeners(e); }
/// <summary> /// This function receives asynchronous one-way /// notification for responses. /// </summary> /// <remarks> /// The response handler's name must be the name of the /// function that is given in the SPL Dispatch function /// for SIP request async calls. /// </remarks> /// <param name="sender">not used</param> /// <param name="e">the arguments for async call</param> public void ResponseNotificationHandler(object sender, NotificationReceivedEventArgs e) { object[] parameters = e.Parameters; // First argument from manifest is SIP response code, // use it for statistics statistics.Update(Response.GetStatusClass((int)parameters[0])); // Last two arguments are From and // To user, use it for statistics statistics.Update(SipUriParser.GetUserAtHost((string)parameters[1])); statistics.Update(SipUriParser.GetUserAtHost((string)parameters[2])); // Raise the event finally this.StateChangeListeners(e); }
internal bool ElevateToPresenter(string participantUri) { SipUriParser parser; if (SipUriParser.TryParse(participantUri, out parser)) { lock (_syncRoot) { _listOfPresenters.Add(participantUri); } List <ConversationParticipant> listOfParticipants = new List <ConversationParticipant>(_conversation.RemoteParticipants); listOfParticipants.ForEach(cp => { if (SipUriCompare.Equals(cp.Uri, participantUri)) { if (cp.Role != ConferencingRole.Leader) { _conversation.ConferenceSession.BeginModifyRole(cp, ConferencingRole.Leader, mr => { try { _conversation.ConferenceSession.EndModifyRole(mr); } catch (RealTimeException rtex) { this._logger.Log("ModifyRole failed", rtex); } }, null); } } }); return(true); } return(false); }
private void UpdatePresenceRelationshipWithAnonymousSubsriber(string newAnonymousSubscriberUri, string oldAnonymousSubscriberUri) { SipUriParser parser; Debug.Assert(SipUriParser.TryParse(newAnonymousSubscriberUri, out parser)); ContainerUpdateOperation AddACE = new ContainerUpdateOperation(ContainerIDForWebUsers); AddACE.AddUri(newAnonymousSubscriberUri); if (!String.IsNullOrEmpty(oldAnonymousSubscriberUri)) { Debug.Assert(SipUriParser.TryParse(oldAnonymousSubscriberUri, out parser)); AddACE.DeleteUri(oldAnonymousSubscriberUri); } List <ContainerUpdateOperation> listOfOperations = new List <ContainerUpdateOperation>(); listOfOperations.Add(AddACE); try { _endpoint.LocalOwnerPresence.BeginUpdateContainerMembership(listOfOperations, add => { try { _endpoint.LocalOwnerPresence.EndUpdateContainerMembership(add); } catch (RealTimeException rtex) { _logger.Log("AcdPortal was unable to end update the container membership for Anonymous Subscriber", rtex); } }, null); } catch (InvalidOperationException ivoex) { _logger.Log("AcdPortal was unable to begin update the container membership for Anonymous Subscriber", ivoex); } }
/// <summary> /// This function receives SIP requests, updates /// session state variables, and proxies the request /// to the default request uri /// </summary> /// <remarks> /// The request handler's name must be the name of the /// function that is given in the SPL Dispatch function /// for SIP requests. /// </remarks> /// <param name="sender">not used</param> /// <param name="e">the request state</param> public void RequestHandler(object sender, RequestReceivedEventArgs e) { /* If this is a SIP INVITE, then create an entry * in the session state table for this call-id. * A session is established, when an ACK for this * call-id is received. */ Request request = e.Request; if (request.StandardMethod == Request.StandardMethodType.Invite) { ///extract the call-id and create session state Header callIdHeader = request.AllHeaders.FindFirst("Call-ID"); if (callIdHeader != null) { Session newSession = new Session(); newSession.State = Session.States.Initializing; newSession.CallId = callIdHeader.Value; lock (sessionStateTable.SyncRoot) { sessionStateTable[callIdHeader.Value] = newSession; } } } else if (request.StandardMethod == Request.StandardMethodType.Ack) { ///extract the call-id and update session state, ignore errors Header callIdHeader = request.AllHeaders.FindFirst("Call-ID"); if (callIdHeader != null) { Session session = sessionStateTable[callIdHeader.Value] as Session; if (session != null) { session.State = Session.States.Established; statistics.Update(true /* new session */); } } } ///update other counters statistics.Update(request.StandardMethod); Header fromHeader = request.AllHeaders.FindFirst("From"); Header toHeader = request.AllHeaders.FindFirst("To"); statistics.Update(SipUriParser.GetUserAtHost(fromHeader.Value)); statistics.Update(SipUriParser.GetUserAtHost(toHeader.Value)); ///notify the state change this.StateChangeListeners(e); ///We will not be forking, and marking this explicitly ///allows ServerAgent to optimize message proxying. e.ServerTransaction.EnableForking = false; ///we are done with state management, proxy ClientTransaction ct = e.ServerTransaction.CreateBranch(); if (SimpleProxy) { // Setting SimpleProxy to true will turn on performance // optimizations during message proxying. request.SimpleProxy = true; } ///Add a header if requested by user. if (AddHeader) { Header h = new Header(SipSnoopHeaderName, SipSnoopHeaderValue); request.AllHeaders.Add(h); } ///Modify To header if requested by user by adding a parameter. if (ModifyToHeader) { NameValueCollection toParamColl = toHeader.Parameters; toParamColl.Set(SipSnoopParamName, SipSnoopParamValue); toHeader.Parameters = toParamColl; } ct.SendRequest(e.Request); return; }
public override async Task<AcdActionResult> Execute(LocalEndpoint localEndpoint, AudioVideoCall call, CancellationToken cancellationToken) { if (Endpoint == null) return AcdActionResult.Continue; // extract information from incoming caller var callParticipant = call.RemoteEndpoint.Participant; var callAddress = new RealTimeAddress(callParticipant.Uri, localEndpoint.DefaultDomain, localEndpoint.PhoneContext); var callSipUri = new SipUriParser(callAddress.Uri); callSipUri.RemoveParameter(new SipUriParameter("user", "phone")); var callUri = callSipUri.ToString(); var callPhoneUri = callParticipant.OtherPhoneUri; var callName = callParticipant.DisplayName; // impersonate incoming caller to agent var remoteConversation = new Conversation(localEndpoint); remoteConversation.Impersonate(callUri, callPhoneUri, callName); // establish call to endpoint var remoteCall = new AudioVideoCall(remoteConversation); var remoteOpts = new CallEstablishOptions(); remoteOpts.Transferor = localEndpoint.OwnerUri; remoteOpts.Headers.Add(new SignalingHeader("Ms-Target-Class", "secondary")); // initiate call with duration var destCallT = remoteCall.EstablishAsync(Endpoint.Uri, remoteOpts, cancellationToken); try { // wait for agent call to complete await destCallT; } catch (OperationCanceledException) { // ignore } catch (RealTimeException) { // ignore } // ensure two accepted transfers cannot both complete using (var lck = await call.GetContext<AsyncLock>().LockAsync()) if (call.State == CallState.Established) if (remoteCall.State == CallState.Established) { var participant = remoteConversation.RemoteParticipants.FirstOrDefault(); if (participant != null) { var endpoint = participant.GetEndpoints().FirstOrDefault(i => i.EndpointType == EndpointType.User); if (endpoint != null) { var ctx = new ConversationContextChannel(remoteConversation, endpoint); // establish conversation context with application await ctx.EstablishAsync( new Guid("FA44026B-CC48-42DA-AAA8-B849BCB43A21"), new ConversationContextChannelEstablishOptions()); // send context data await ctx.SendDataAsync( new ContentType("text/plain"), Encoding.UTF8.GetBytes("Id=123")); } } return await TransferAsync(call, remoteCall); } // terminate outbound call if still available if (remoteCall.State != CallState.Terminating && remoteCall.State != CallState.Terminated) await remoteCall.TerminateAsync(); // we could not complete the transfer attempt return AcdActionResult.Continue; }
public ICall MakeCall(IAccount account, string destinationUri) { Helper.GuardNotNull(account); return MakeCall(x => { var sipUriParser = new SipUriParser(destinationUri); return x.From(account).To(sipUriParser.Extension).At(sipUriParser.Domain).Through(sipUriParser.Port).Call(); }); }
internal SipUri Clone() { var p = new SipUriParser(); return(p.Parse(FormatToString())); }