Inheritance: INotifyPropertyChanged, ISIPAsset
        public void SIPProviderDeleted(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderDeleted for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                SIPProviderBinding existingBinding = m_bindingPersistor.Get(b => b.ProviderId == sipProvider.Id);
                if (existingBinding != null)
                {
                    if (existingBinding.IsRegistered)
                    {
                        // Let the registration agent know the existing binding should be expired.
                        existingBinding.BindingExpiry        = 0;
                        existingBinding.NextRegistrationTime = DateTime.UtcNow;
                        m_bindingPersistor.Update(existingBinding);
                    }
                    else
                    {
                        m_bindingPersistor.Delete(existingBinding);
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. " + excp.Message);
            }
        }
        public void SIPProviderDeleted(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderDeleted for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                SIPProviderBinding existingBinding = m_bindingPersistor.Get(b => b.ProviderId == sipProvider.Id);
                if (existingBinding != null)
                {
                    if (existingBinding.IsRegistered)
                    {
                        // Let the registration agent know the existing binding should be expired.
                        existingBinding.BindingExpiry = 0;
                        existingBinding.NextRegistrationTime = DateTime.UtcNow;
                        m_bindingPersistor.Update(existingBinding);
                    }
                    else
                    {
                        m_bindingPersistor.Delete(existingBinding);
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. " + excp.Message);
            }
        }
Ejemplo n.º 3
0
        public SIPProviderBinding(SIPProvider sipProvider)
        {
            SetProviderFields(sipProvider);

            m_id = Guid.NewGuid();

            // All set, let the Registration Agent know the binding is ready to be processed.
            NextRegistrationTime = DateTimeOffset.UtcNow;
        }
        public void SIPProviderAdded(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderAdded for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                if (sipProvider.RegisterEnabled)
                {
                    SIPProviderBinding binding = new SIPProviderBinding(sipProvider);
                    m_bindingPersistor.Add(binding);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderAdded. " + excp.Message);
            }
        }
        public void SIPProviderAdded(SIPProvider sipProvider)
        {
            try
            {
                logger.Debug("SIPProviderBindingSynchroniser SIPProviderAdded for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");

                if (sipProvider.RegisterEnabled)
                {
                    SIPProviderBinding binding = new SIPProviderBinding(sipProvider);
                    m_bindingPersistor.Add(binding);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderAdded. " + excp.Message);
            }
        }
Ejemplo n.º 6
0
        //public Dictionary<Guid, object> Load(XmlDocument dom)
        //{
        //    return SIPAssetXMLPersistor<SIPProviderBinding>.LoadAssetsFromXMLRecordSet(dom);
        //}
#endif

        public void SetProviderFields(SIPProvider sipProvider)
        {
            m_providerId          = sipProvider.Id;
            m_owner               = sipProvider.Owner;
            AdminMemberId         = sipProvider.AdminMemberId;
            ProviderName          = sipProvider.ProviderName;
            ProviderAuthUsername  = (!sipProvider.ProviderAuthUsername.IsNullOrBlank()) ? sipProvider.ProviderAuthUsername : sipProvider.ProviderUsername;
            ProviderPassword      = sipProvider.ProviderPassword;
            RegistrarServer       = sipProvider.Registrar.CopyOf();
            RegistrarRealm        = (!sipProvider.RegisterRealm.IsNullOrBlank()) ? sipProvider.RegisterRealm : RegistrarServer.Host;
            ProviderOutboundProxy = sipProvider.ProviderOutboundProxy;
            SendMWISubscribe      = sipProvider.SendMWISubscribe;

            if (sipProvider.RegisterEnabled)
            {
                BindingExpiry = sipProvider.RegisterExpiry;
            }
            else
            {
                BindingExpiry = 0;
            }

            string bindingId = null;

            if (m_bindingURI != null && m_bindingURI.Parameters.Has(REGAGENT_CONTACT_ID_KEY))
            {
                bindingId = m_bindingURI.Parameters.Get(REGAGENT_CONTACT_ID_KEY);
            }

            if (!sipProvider.RegisterContact.IsNullOrBlank())
            {
                m_bindingURI = SIPURI.ParseSIPURI(sipProvider.RegisterContact);
                if (!bindingId.IsNullOrBlank())
                {
                    m_bindingURI.Parameters.Set(REGAGENT_CONTACT_ID_KEY, bindingId);
                }
            }
            else
            {
                // The register contact field on the SIP Provider is empty.
                // This condition needs to be trearted as the binding being disabled and it needs to be removed.
                BindingExpiry = 0;
            }
        }
        public SIPProviderDetailsControl(
            DetailsControlModesEnum mode,
            SIPProvider sipProvider,
            string owner,
            SIPProviderUpdateDelegate sipProviderAdd,
            SIPProviderUpdateDelegate sipProviderUpdate,
            ControlClosedDelegate closed)
        {
            InitializeComponent();

            m_advancedProviderSettings.Visibility = Visibility.Collapsed;
            m_detailsMode = mode;
            m_sipProvider = sipProvider;
            m_owner = owner;
            SIPProviderAdd_External = sipProviderAdd;
            SIPProviderUpdate_External = sipProviderUpdate;
            ControlClosed_External = closed;

            if (m_disableProviderRegistrations)
            {
                m_providerRegister.IsEnabled = false;
                m_providerRegisterContact.IsEnabled = false;
                m_providerRegisterExpiry.IsEnabled = false;
                m_providerRegisterServer.IsEnabled = false;
            }

            if (mode == DetailsControlModesEnum.Edit)
            {
                m_providerTypeCanvas.Visibility = Visibility.Collapsed;
                m_gvSettingsPanel.Visibility = System.Windows.Visibility.Collapsed;
                m_applyButton.Content = "Update";
                PopulateDataFields(m_sipProvider);
            }
            else
            {
                m_providerIdCanvas.Visibility = Visibility.Collapsed;
                m_providerTypeNameCanvas.Visibility = Visibility.Collapsed;
                m_gvSettingsPanel.Visibility = System.Windows.Visibility.Collapsed;
                m_applyButton.Content = "Add";
            }
        }
        private void SendInitialRegister(SIPProvider sipProvider, SIPProviderBinding binding, SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, int expirySeconds)
        {
            try
            {
                m_inTransitBindings.AddOrUpdate(binding.Id, binding, (s, i) => binding);

                binding.CSeq++;

                FireProxyLogEvent(new SIPMonitorConsoleEvent(SIPMonitorServerTypesEnum.RegisterAgent, SIPMonitorEventTypesEnum.ContactRegisterInProgress, "Initiating registration for " + binding.Owner + " on " + binding.RegistrarServer.ToString() + ".", binding.Owner));
                SIPRequest regRequest = GetRegistrationRequest(sipProvider, binding, localSIPEndPoint, expirySeconds, remoteEndPoint);

                SIPNonInviteTransaction regTransaction = m_sipTransport.CreateNonInviteTransaction(regRequest, binding.RegistrarSIPEndPoint, localSIPEndPoint, m_outboundProxy);
                regTransaction.NonInviteTransactionFinalResponseReceived += (lep, rep, tn, rsp) => { ThreadPool.QueueUserWorkItem(delegate { ServerResponseReceived(lep, rep, tn, rsp); }); };
                regTransaction.NonInviteTransactionTimedOut += (tn) => { ThreadPool.QueueUserWorkItem(delegate { RegistrationTimedOut(tn); }); };

                m_sipTransport.SendSIPReliable(regTransaction);

                SIPSorceryPerformanceMonitor.IncrementCounter(SIPSorceryPerformanceMonitor.REGISTRATION_AGENT_REGISTRATIONS_PER_SECOND);
            }
            catch (Exception excp)
            {
                logger.Error("Exception SendInitialRegister for " + binding.Owner + " and " + binding.RegistrarServer.ToString() + ". " + excp.Message);
                RemoveCachedBinding(binding.Id);
            }
        }
        private void PopulateDataFields(SIPProvider sipProvider)
        {
            m_providerId.Text = sipProvider.Id.ToString();
            m_providerTypeName.Text = sipProvider.ProviderType.ToString();
            m_providerName.Text = sipProvider.ProviderName;
            m_providerUsername.Text = sipProvider.ProviderUsername;
            m_providerPassword.Text = sipProvider.ProviderPassword;

            if (sipProvider.ProviderType == ProviderTypes.SIP)
            {
                m_providerServer.Text = sipProvider.ProviderServer.ToString();
                m_providerAuthUsername.Text = (sipProvider.ProviderAuthUsername != null) ? sipProvider.ProviderAuthUsername : String.Empty;
                m_providerFromHeader.Text = (sipProvider.ProviderFrom != null) ? sipProvider.ProviderFrom : String.Empty;
                m_providerRegisterRealm.Text = (sipProvider.RegisterRealm != null) ? sipProvider.RegisterRealm : String.Empty;

                if (!m_disableProviderRegistrations)
                {
                    m_providerRegister.IsChecked = sipProvider.RegisterEnabled;
                    m_providerRegisterContact.Text = (sipProvider.RegisterContact != null) ? sipProvider.RegisterContact.ToString() : String.Empty;
                    m_providerRegisterExpiry.Text = sipProvider.RegisterExpiry.ToString();
                    m_providerRegisterServer.Text = (sipProvider.RegisterServer != null) ? sipProvider.RegisterServer.ToString() : String.Empty;

                    m_providerRegisterContact.IsEnabled = m_providerRegister.IsChecked.Value;
                    m_providerRegisterExpiry.IsEnabled = m_providerRegister.IsChecked.Value;
                    m_providerRegisterServer.IsEnabled = m_providerRegister.IsChecked.Value;
                }

                if (sipProvider.CustomHeaders != null && sipProvider.CustomHeaders.Trim().Length > 0)
                {
                    string[] customHeaders = sipProvider.CustomHeaders.Split(m_customHeadersSeparator);

                    if (customHeaders != null && customHeaders.Length > 0)
                    {
                        foreach (string customHeader in customHeaders)
                        {
                            if (customHeader != null && customHeader.Trim().Length > 0)
                            {
                                m_providerCustomHeaders.Items.Add(customHeader.Trim());
                            }
                        }
                    }
                }
            }
            else
            {
                GoogleVoiceTypeClicked(null, null);

                m_gvCallbackNumber.Text = sipProvider.GVCallbackNumber;
                m_gvCallbackPattern.Text = sipProvider.GVCallbackPattern;

                if (sipProvider.GVCallbackType != null)
                {
                    for (int index = 0; index < m_gvCallbackType.Items.Count; index++)
                    {
                        if (((TextBlock)m_gvCallbackType.Items[index]).Text == sipProvider.GVCallbackType.Value.ToString())
                        {
                            m_gvCallbackType.SelectedIndex = index;
                            break;
                        }
                    }
                }
            }
        }
        private void Add()
        {
            try
            {
                SIPProvider sipProvider = null;

                ProviderTypes providerType = (m_providerTypeSIPRadio.IsChecked != null && m_providerTypeSIPRadio.IsChecked.Value) ? ProviderTypes.SIP : ProviderTypes.GoogleVoice;
                string providerName = m_providerName.Text.Trim();
                string providerUsername = m_providerUsername.Text.Trim();
                string providerPassword = m_providerPassword.Text.Trim();

                if (providerType == ProviderTypes.SIP)
                {
                    SIPURI providerServer = (!m_providerServer.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerServer.Text.Trim()) : null;
                    bool registerEnabled = m_providerRegister.IsChecked.Value;
                    SIPURI registerContact = (!m_providerRegisterContact.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerRegisterContact.Text.Trim()) : null;
                    string authUsername = m_providerAuthUsername.Text.Trim();
                    string providerFrom = m_providerFromHeader.Text.Trim();
                    string registerRealm = m_providerRegisterRealm.Text.Trim();
                    SIPURI registerServer = (!m_providerRegisterServer.Text.IsNullOrBlank()) ? SIPURI.ParseSIPURIRelaxed(m_providerRegisterServer.Text.Trim()) : null;

                    int registerExpiry = m_defaultRegisterExpiry;
                    Int32.TryParse(m_providerRegisterExpiry.Text, out registerExpiry);

                    string customHeaders = null;
                    if (m_providerCustomHeaders.Items.Count > 0)
                    {
                        foreach (string customHeader in m_providerCustomHeaders.Items)
                        {
                            customHeaders += (m_sipProvider.CustomHeaders != null && m_sipProvider.CustomHeaders.Trim().Length > 0) ? m_customHeadersSeparator.ToString() : null;
                            customHeaders += customHeader;
                        }
                    }

                    sipProvider = new SIPProvider(ProviderTypes.SIP, m_owner, providerName, providerUsername, providerPassword, providerServer, null, providerFrom, customHeaders,
                            registerContact, registerExpiry, registerServer, authUsername, registerRealm, registerEnabled, true, null, null, null);
                }
                else
                {
                    string gvCallbackNumber = m_gvCallbackNumber.Text;
                    string gvCallbackPattern = m_gvCallbackPattern.Text;
                    GoogleVoiceCallbackTypes callbackType = (GoogleVoiceCallbackTypes)Enum.Parse(typeof(GoogleVoiceCallbackTypes), ((TextBlock)m_gvCallbackType.SelectedValue).Text, true);

                    sipProvider = new SIPProvider(ProviderTypes.GoogleVoice, m_owner, providerName, providerUsername, providerPassword, null, null, null, null,
                        null, 0, null, null, null, false, true, gvCallbackNumber, gvCallbackPattern, callbackType);
                }

                sipProvider.Inserted = DateTime.UtcNow;
                sipProvider.LastUpdate = DateTime.UtcNow;

                string validationError = SIPProvider.ValidateAndClean(sipProvider);
                if (validationError != null)
                {
                    WriteStatusMessage(MessageLevelsEnum.Warn, validationError);
                }
                else
                {
                    WriteStatusMessage(MessageLevelsEnum.Info, "Adding SIP Provider please wait...");
                    SIPProviderAdd_External(sipProvider);
                }
            }
            catch (Exception excp)
            {
                WriteStatusMessage(MessageLevelsEnum.Error, "Add SIPProvider Exception. " + excp.Message);
            }
        }
        public SIPProvider DeleteSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername) {
                throw new ApplicationException("You are not authorised to delete the SIP Provider.");
            }

            //logger.Debug("DeleteSIPProvider, owner=" + sipProvider.Owner + ", providername=" + sipProvider.ProviderName + ".");
            SIPProviderPersistor.Delete(sipProvider);

            // Enables the caller to see which SIP Provider has been deleted.
            return sipProvider;
        }
 private void UpdateSIPProvider(SIPProvider sipProvider)
 {
     //LogActivityMessage_External(MessageLevelsEnum.Info, "Attempting to update SIP Provider " + sipProvider.ProviderName + ".");
     m_persistor.UpdateSIPProviderAsync(sipProvider);
 }
 public abstract void AddSIPProviderAsync(SIPProvider sipProvider);
            public void NoMatchingProviderUnitTest()
            {
                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("test", "blueface", "test", "password", SIPURI.ParseSIPURIRelaxed("sip.blueface.ie"), null, null, null, null, 3600, null, null, null, false, false);
                providers.Add(provider);

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

                Assert.IsNotNull(callQueue, "The call list should be returned.");
                Assert.IsTrue(callQueue.Count == 1, "The call queue list should not 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 == DialStringParser.m_anonymousUsername, "The username for the first call leg was not correct.");
                Assert.IsTrue(firstLeg[0].Uri.ToString() == "sip:303@noprovider", "The destination URI for the first call leg was not correct.");

                Console.WriteLine("---------------------------------");
            }
 public abstract void DeleteSIPProviderAsync(SIPProvider sipProvider);
 public abstract void UpdateSIPProviderAsync(SIPProvider sipProvider);
 private void DetailsControlClosed()
 {
     m_sipProvidersPanel.CloseDetailsPane();
     m_selectedSIPProvider = null;
 }
 private void SIPProviderAdd(SIPProvider sipProvider)
 {
     m_persistor.AddSIPProviderAsync(sipProvider);
 }
        private void SIPProvidersDataGrid_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            try
            {
                if (m_initialLoadComplete && !m_sipProvidersLoadInProgress && m_sipProviders.Count > 0)
                {
                     DataGrid dataGrid = (DataGrid)sender;
                     if (dataGrid.CurrentColumn.Header as string != "Delete")
                     {
                         SIPProvider sipProvider = (SIPProvider)m_sipProvidersDataGrid.SelectedItem;

                         if (m_selectedSIPProvider == null || m_selectedSIPProvider != sipProvider)
                         {
                             m_selectedSIPProvider = sipProvider;
                             m_editControl = new SIPProviderDetailsControl(DetailsControlModesEnum.Edit, m_selectedSIPProvider, m_owner, null, UpdateSIPProvider, DetailsControlClosed);
                             m_sipProvidersPanel.SetDetailsElement(m_editControl);
                         }
                     }
                }
            }
            catch (Exception excp)
            {
                string excpMessage = (excp.InnerException != null) ? excp.InnerException.Message : excp.Message;
                LogActivityMessage_External(MessageLevelsEnum.Error, "Exception showing SIP Provider details. " + excpMessage);
                m_selectedSIPProvider = null;
            }
        }
        private SIPRequest GetRegistrationRequest(SIPProvider sipProvider, SIPProviderBinding binding, SIPEndPoint localSIPEndPoint, int expiry, SIPEndPoint registrarEndPoint)
        {
            try
            {
                if (!binding.BindingSIPURI.Parameters.Has(m_regAgentContactId))
                {
                    binding.BindingSIPURI.Parameters.Set(m_regAgentContactId, Crypto.GetRandomString(6));
                }

                string realm = binding.RegistrarRealm;

                SIPURI registerURI = SIPURI.ParseSIPURIRelaxed(realm);
                SIPURI regUserURI = SIPURI.ParseSIPURIRelaxed(sipProvider.ProviderUsername + "@" + realm);

                SIPFromHeader fromHeader = new SIPFromHeader(null, regUserURI, CallProperties.CreateNewTag());
                SIPToHeader toHeader = new SIPToHeader(null, regUserURI, null);
                SIPContactHeader contactHeader = new SIPContactHeader(null, binding.BindingSIPURI);
                //contactHeader.Expires = binding.BindingExpiry;
                string callId = binding.Id.ToString();
                int cseq = ++binding.CSeq;

                SIPRequest registerRequest = new SIPRequest(SIPMethodsEnum.REGISTER, registerURI);
                registerRequest.LocalSIPEndPoint = localSIPEndPoint;
                SIPHeader header = new SIPHeader(contactHeader, fromHeader, toHeader, cseq, callId);
                header.CSeqMethod = SIPMethodsEnum.REGISTER;
                header.UserAgent = m_userAgentString;
                header.Expires = binding.BindingExpiry;

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

                SIPRoute registrarRoute = new SIPRoute(new SIPURI(binding.RegistrarServer.Scheme, registrarEndPoint), true);
                header.Routes.PushRoute(registrarRoute);

                if (sipProvider != null && !sipProvider.CustomHeaders.IsNullOrBlank())
                {
                    string[] customerHeadersList = sipProvider.CustomHeaders.Split(SIPProvider.CUSTOM_HEADERS_SEPARATOR);

                    if (customerHeadersList != null && customerHeadersList.Length > 0)
                    {
                        foreach (string customHeader in customerHeadersList)
                        {
                            if (customHeader.IndexOf(':') == -1)
                            {
                                logger.Debug("Skipping custom header due to missing colon, " + customHeader + ".");
                                continue;
                            }
                            else
                            {
                                string headerName = customHeader.Substring(0, customHeader.IndexOf(':'));
                                if (headerName != null && Regex.Match(headerName.Trim(), "(Via|From|To|Contact|CSeq|Call-ID|Max-Forwards|Content)", RegexOptions.IgnoreCase).Success)
                                {
                                    logger.Debug("Skipping custom header due to an non-permitted string in header name, " + customHeader + ".");
                                    continue;
                                }
                                else
                                {
                                    if (headerName == SIPConstants.SIP_USERAGENT_STRING)
                                    {
                                        header.UserAgent = customHeader.Substring(customHeader.IndexOf(':') + 1);
                                    }
                                    else
                                    {
                                        header.UnknownHeaders.Add(customHeader.Trim());
                                    }
                                }
                            }
                        }
                    }
                }

                registerRequest.Header = header;
                return registerRequest;
            }
            catch (Exception excp)
            {
                logger.Error("Exception GetRegistrationRequest. " + excp.Message);
                throw excp;
            }
        }
Ejemplo n.º 21
0
        public static string ValidateAndClean(SIPProvider sipProvider)
        {
            if (sipProvider.ProviderName.IsNullOrBlank())
            {
                return "A value for Provider Name must be specified.";
            }
            else if (sipProvider.ProviderName.Contains("."))
            {
                return "The Provider Name cannot contain a full stop '.' in order to avoid ambiguity with DNS host names, please remove the '.'.";
            }

            if (sipProvider.ProviderType == ProviderTypes.SIP)
            {
                if (sipProvider.ProviderServer.IsNullOrBlank())
                {
                    return "A value for Server must be specified.";
                }
                if (sipProvider.RegisterEnabled && sipProvider.m_registerContact == null)
                {
                    return "A valid contact must be supplied to enable a provider registration.";
                }
                else if (sipProvider.m_providerServer.Host.IndexOf('.') == -1)
                {
                    return "Your provider server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                }
                else if (sipProvider.m_registerServer != null && sipProvider.m_registerServer.Host.IndexOf('.') == -1)
                {
                    return "Your register server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                }
                else if (sipProvider.m_registerContact != null && sipProvider.m_registerContact.Host.IndexOf('.') == -1)
                {
                    return "Your register contact entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.";
                }
                else if (sipProvider.m_registerContact != null && sipProvider.m_registerContact.User.IsNullOrBlank())
                {
                    return "Your register contact entry appears to be invalid, the user portion was missing. Contacts must be of the form [email protected], e.g. [email protected].";
                }
                else if (DisallowedServerPatterns != null && Regex.Match(sipProvider.m_providerServer.Host, DisallowedServerPatterns).Success)
                {
                    return "The Provider Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.";
                }
                else if (DisallowedServerPatterns != null && sipProvider.m_registerServer != null && Regex.Match(sipProvider.m_registerServer.Host, DisallowedServerPatterns).Success)
                {
                    return "The Provider Register Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.";
                }
            }
            else
            {
                if (sipProvider.ProviderUsername.IsNullOrBlank())
                {
                    return "A username is required for Google Voice entries.";
                }
                else if (sipProvider.ProviderPassword.IsNullOrBlank())
                {
                    return "A password is required for Google Voice entries.";
                }
                else if (sipProvider.GVCallbackNumber.IsNullOrBlank())
                {
                    return "A callback number is required for Google Voice entries.";
                }
                else if (Regex.Match(sipProvider.GVCallbackNumber, @"\D").Success)
                {
                    return "The callback number contains an invalid character. Only digits are permitted.";
                }
            }

            return null;
        }
            public void MultipleForwardsWithLocalUnitTest()
            {
                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("test", "provider1", "user", "password", SIPURI.ParseSIPURIRelaxed("sip.blueface.ie"), null, null, null, null, 3600, null, null, null, false, false);
                SIPProvider provider2 = new SIPProvider("test", "provider2", "user", "password", SIPURI.ParseSIPURIRelaxed("sip.blueface.ie"), null, null, null, null, 3600, null, null, null, false, false);
                providers.Add(provider);
                providers.Add(provider2);

                DialStringParser dialStringParser = new DialStringParser(null, "test", null, providers, (where) => { return null; }, (where, offset, count, orderby) => { return null; }, (host, wildcard) => { return null; }, null);
                Queue<List<SIPCallDescriptor>> callQueue = dialStringParser.ParseDialString(DialPlanContextsEnum.Script, inviteRequest, "local&1234@provider2", null, null, null, null, null);

                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 == 2, "The first call leg should have had two switch calls.");

                Console.WriteLine("First destination uri=" + firstLeg[0].Uri.ToString());
                Console.WriteLine("Second destination uri=" + firstLeg[1].Uri.ToString());

                Console.WriteLine("---------------------------------");
            }
Ejemplo n.º 23
0
        public static string ValidateAndClean(SIPProvider sipProvider)
        {
            if (sipProvider.ProviderName.IsNullOrBlank())
            {
                return("A value for Provider Name must be specified.");
            }
            else if (sipProvider.ProviderName.Contains("."))
            {
                return("The Provider Name cannot contain a full stop '.' in order to avoid ambiguity with DNS host names, please remove the '.'.");
            }

            if (sipProvider.ProviderType == ProviderTypes.SIP)
            {
                if (sipProvider.ProviderServer.IsNullOrBlank())
                {
                    return("A value for Server must be specified.");
                }
                if (sipProvider.RegisterEnabled && sipProvider.m_registerContact == null)
                {
                    return("A valid contact must be supplied to enable a provider registration.");
                }
                else if (sipProvider.m_providerServer.Host.IndexOf('.') == -1)
                {
                    return("Your provider server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.");
                }
                else if (sipProvider.m_registerServer != null && sipProvider.m_registerServer.Host.IndexOf('.') == -1)
                {
                    return("Your register server entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.");
                }
                else if (sipProvider.m_registerContact != null && sipProvider.m_registerContact.Host.IndexOf('.') == -1)
                {
                    return("Your register contact entry appears to be invalid. A valid hostname or IP address should contain at least one '.'.");
                }
                else if (sipProvider.m_registerContact != null && sipProvider.m_registerContact.User.IsNullOrBlank())
                {
                    return("Your register contact entry appears to be invalid, the user portion was missing. Contacts must be of the form [email protected], e.g. [email protected].");
                }
                else if (DisallowedServerPatterns != null && Regex.Match(sipProvider.m_providerServer.Host, DisallowedServerPatterns).Success)
                {
                    return("The Provider Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.");
                }
                else if (DisallowedServerPatterns != null && sipProvider.m_registerServer != null && Regex.Match(sipProvider.m_registerServer.Host, DisallowedServerPatterns).Success)
                {
                    return("The Provider Register Server contains a disallowed string. If you are trying to create a Provider entry pointing to sipsorcery.com it is not permitted.");
                }
            }
            else
            {
                if (sipProvider.ProviderUsername.IsNullOrBlank())
                {
                    return("A username is required for Google Voice entries.");
                }
                else if (sipProvider.ProviderPassword.IsNullOrBlank())
                {
                    return("A password is required for Google Voice entries.");
                }
                else if (sipProvider.GVCallbackNumber.IsNullOrBlank())
                {
                    return("A callback number is required for Google Voice entries.");
                }
                else if (Regex.Match(sipProvider.GVCallbackNumber, @"\D").Success)
                {
                    return("The callback number contains an invalid character. Only digits are permitted.");
                }
            }

            return(null);
        }
        public SIPProvider AddSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();
            sipProvider.Owner = customer.CustomerUsername;

            string validationError = SIPProvider.ValidateAndClean(sipProvider);
            if (validationError != null) {
                logger.Warn("Validation error in AddSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else {
                return SIPProviderPersistor.Add(sipProvider);
            }
        }
        public SIPProvider AddSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (!customer.ServiceLevel.IsNullOrBlank() && customer.ServiceLevel.ToLower() == "free")
            {
                // Check the number of SIP Provider is within limits.
                if (GetSIPProvidersCount(null) >= 1)
                {
                    throw new ApplicationException("The SIP Provider cannot be added as your existing SIP Provider count has reached the allowed limit for your service level.");
                }
            }

            sipProvider.Owner = customer.CustomerUsername;

            string validationError = SIPProvider.ValidateAndClean(sipProvider);
            if (validationError != null)
            {
                logger.Warn("Validation error in AddSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                return SIPProviderPersistor.Add(sipProvider);
            }
        }
        public SIPProvider UpdateSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername) {
                throw new ApplicationException("You are not authorised to update the SIP Provider.");
            }

            string validationError = SIPProvider.ValidateAndClean(sipProvider);
            if (validationError != null) {
                logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else {
                return SIPProviderPersistor.Update(sipProvider);
            }
        }
 private void SIPProvidersPanel_Add()
 {
     m_selectedSIPProvider = null;
     m_addControl = new SIPProviderDetailsControl(DetailsControlModesEnum.Add, m_selectedSIPProvider, m_owner, SIPProviderAdd, null, DetailsControlClosed);
     m_sipProvidersPanel.SetDetailsElement(m_addControl);
 }
Ejemplo n.º 28
0
        public SIPProviderBinding(SIPProvider sipProvider)
        {
            SetProviderFields(sipProvider);

            m_id = Guid.NewGuid();

            // All set, let the Registration Agent know the binding is ready to be processed.
            NextRegistrationTime = DateTimeOffset.UtcNow;
        }
 public override void AddSIPProviderAsync(SIPProvider sipProvider) {
     m_provisioningServiceProxy.AddSIPProviderAsync(sipProvider);
 }
Ejemplo n.º 30
0
        public void SetProviderFields(SIPProvider sipProvider)
        {
            m_providerId = sipProvider.Id;
            m_owner = sipProvider.Owner;
            AdminMemberId = sipProvider.AdminMemberId;
            ProviderName = sipProvider.ProviderName;
            ProviderAuthUsername = (!sipProvider.ProviderAuthUsername.IsNullOrBlank()) ? sipProvider.ProviderAuthUsername : sipProvider.ProviderUsername;
            ProviderPassword = sipProvider.ProviderPassword;
            RegistrarServer = sipProvider.Registrar.CopyOf();
            RegistrarRealm = (!sipProvider.RegisterRealm.IsNullOrBlank()) ? sipProvider.RegisterRealm : RegistrarServer.Host;
            ProviderOutboundProxy = sipProvider.ProviderOutboundProxy;
            SendMWISubscribe = sipProvider.SendMWISubscribe;

            if (sipProvider.RegisterEnabled) {
                BindingExpiry = sipProvider.RegisterExpiry;
            }
            else {
                BindingExpiry = 0;
            }

            string bindingId = null;
            if (m_bindingURI != null && m_bindingURI.Parameters.Has(REGAGENT_CONTACT_ID_KEY)) {
                bindingId = m_bindingURI.Parameters.Get(REGAGENT_CONTACT_ID_KEY);
            }

            if (!sipProvider.RegisterContact.IsNullOrBlank()) {
                m_bindingURI = SIPURI.ParseSIPURI(sipProvider.RegisterContact);
                if (!bindingId.IsNullOrBlank()) {
                    m_bindingURI.Parameters.Set(REGAGENT_CONTACT_ID_KEY, bindingId);
                }
            }
            else {
                // The register contact field on the SIP Provider is empty.
                // This condition needs to be trearted as the binding being disabled and it needs to be removed.
                BindingExpiry = 0;
            }
        }
        public SIPProvider UpdateSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername)
            {
                throw new ApplicationException("You are not authorised to update the SIP Provider.");
            }

            string validationError = SIPProvider.ValidateAndClean(sipProvider);
            if (validationError != null)
            {
                logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                if (m_providerRegDisabled && sipProvider.RegisterEnabled)
                {
                    logger.Warn("A SIP provider for customer " + customer.CustomerUsername + " had registrations enabled on a disabled registrations service.");
                    throw new ApplicationException("SIP provider registrations are disabled on this system.");
                }
                else
                {
                    return SIPProviderPersistor.Update(sipProvider);
                }
            }
        }
 public override void AddSIPProviderAsync(SIPProvider sipProvider) {
     if (AddSIPProviderComplete != null) {
         AddSIPProviderComplete(new AddSIPProviderCompletedEventArgs(new object[] { sipProvider }, null, false, null));
     }
 }
 public override void UpdateSIPProviderAsync(SIPProvider sipProvider) {
     m_provisioningServiceProxy.UpdateSIPProviderAsync(sipProvider);
 }