public void SIPProviderDeleted(SIPProvider sipProvider)
        {
            try
            {
                Logger.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.Logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. ->" + excp.Message);
            }
        }
        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 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;
            }
        }
Beispiel #4
0
        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 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);
        }