コード例 #1
0
        private Dictionary <string, SIPUserAgentConfiguration> ParseSIPUserAgentConfigurations(XmlNode userAgentConifgNode)
        {
            try {
                Dictionary <string, SIPUserAgentConfiguration> userAgentConfigs = new Dictionary <string, SIPUserAgentConfiguration>();

                if (userAgentConifgNode != null && userAgentConifgNode.ChildNodes.Count != 0)
                {
                    foreach (XmlNode userAgentNode in userAgentConifgNode.SelectNodes("useragent"))
                    {
                        if (userAgentNode.InnerText != null && userAgentNode.InnerText.Trim().Length > 0)
                        {
                            int  expiry = Convert.ToInt32(userAgentNode.Attributes.GetNamedItem("expiry").Value);
                            bool contactListSupported = (userAgentNode.Attributes.GetNamedItem("contactlists") != null) ? Convert.ToBoolean(userAgentNode.Attributes.GetNamedItem("contactlists").Value) : true;
                            SIPUserAgentConfiguration userAgentConfig = new SIPUserAgentConfiguration(expiry, contactListSupported, userAgentNode.InnerText);

                            if (userAgentConfig.UserAgentRegex != null && userAgentConfig.UserAgentRegex.Trim().Length > 0 && !userAgentConfigs.ContainsKey(userAgentConfig.UserAgentRegex))
                            {
                                logger.Debug("Added useragent config, useragent=" + userAgentConfig.UserAgentRegex + ", expiry=" + userAgentConfig.MaxAllowedExpiryTime + "s, contact lists=" + userAgentConfig.ContactListSupported + ".");
                                userAgentConfigs.Add(userAgentConfig.UserAgentRegex, userAgentConfig);
                            }
                        }
                    }
                }

                return(userAgentConfigs);
            }
            catch (Exception excp) {
                logger.Error("Exception ParseSIPUserAgentConfigurations. " + excp.Message);
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Makes a decision on what the maximum allowed expiry is for a REGISTER request. Allows different expiry values to be accepted from different user agents.
        /// This is useful as some user agents ignore the expiry value set by the server and setting a higher value for that user agent can stop the registrar
        /// expiring it.
        /// </summary>
        /// <param name="userAgent">The useragent to get the maximum expiry for.</param>
        /// <returns>The maximum expiry value that will be accepted.</returns>
        private SIPUserAgentConfiguration GetUserAgentConfig(string userAgent)
        {
            SIPUserAgentConfiguration matchingUAConfig = null;

            try {
                if (m_userAgentConfigs != null && m_userAgentConfigs.Count > 0)
                {
                    if (userAgent != null && userAgent.Trim().Length > 0)
                    {
                        foreach (string userAgentPattern in m_userAgentConfigs.Keys)
                        {
                            if (Regex.Match(userAgent, userAgentPattern, RegexOptions.IgnoreCase).Success)
                            {
                                matchingUAConfig = m_userAgentConfigs[userAgentPattern];
                                break;
                            }
                        }
                    }
                }

                return(matchingUAConfig);
            }
            catch (Exception excp) {
                logger.Error("Exception GetUserAgentConfig. " + excp);
                return(null);
            }
        }
コード例 #3
0
            public void GetCiscoExpiryUnitTest()
            {
                Console.WriteLine("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);

                string registrarExpiryNode =
                    "<useragentconfigs>" +
                    "  <useragent expiry='3600'>fring</useragent>" +
                    "  <useragent expiry='300'>Cisco-CP7960G/8.0</useragent>" +
                    "  <useragent expiry='113'>*</useragent>" +
                    " </useragentconfigs>";
                XmlDocument regExpiryDom = new XmlDocument();

                regExpiryDom.LoadXml(registrarExpiryNode);

                SIPUserAgentConfigurationManager uaConfigManager = new SIPUserAgentConfigurationManager(regExpiryDom.DocumentElement);
                SIPUserAgentConfiguration        matchingUA      = uaConfigManager.GetUserAgentConfig("Cisco-CP7960G/8.0");

                Assert.IsNotNull(matchingUA, "A matching user agent entry was not found.");
                Assert.IsTrue(matchingUA.MaxAllowedExpiryTime == 300, "The expiry value for the Cisco ua was incorrect.");

                Console.WriteLine("---------------------------------");
            }
コード例 #4
0
        public bool GetUserAgentContactListSupport(string userAgent)
        {
            SIPUserAgentConfiguration matchingConfig = GetUserAgentConfig(userAgent);

            return((matchingConfig != null) ? matchingConfig.ContactListSupported : m_defaultContactListSupported);
        }
コード例 #5
0
        public int GetMaxAllowedExpiry(string userAgent)
        {
            SIPUserAgentConfiguration matchingConfig = GetUserAgentConfig(userAgent);

            return((matchingConfig != null) ? matchingConfig.MaxAllowedExpiryTime : m_defaultMaxExpiry);
        }
コード例 #6
0
        private Dictionary<string, SIPUserAgentConfiguration> ParseSIPUserAgentConfigurations(XmlNode userAgentConifgNode) {
            try {
                Dictionary<string, SIPUserAgentConfiguration> userAgentConfigs = new Dictionary<string, SIPUserAgentConfiguration>();

                if (userAgentConifgNode != null && userAgentConifgNode.ChildNodes.Count != 0) {
                    foreach (XmlNode userAgentNode in userAgentConifgNode.SelectNodes("useragent")) {
                        if (userAgentNode.InnerText != null && userAgentNode.InnerText.Trim().Length > 0) {
                            int expiry = Convert.ToInt32(userAgentNode.Attributes.GetNamedItem("expiry").Value);
                            bool contactListSupported = (userAgentNode.Attributes.GetNamedItem("contactlists") != null) ? Convert.ToBoolean(userAgentNode.Attributes.GetNamedItem("contactlists").Value) : true;
                            SIPUserAgentConfiguration userAgentConfig = new SIPUserAgentConfiguration(expiry, contactListSupported, userAgentNode.InnerText);

                            if (userAgentConfig.UserAgentRegex != null && userAgentConfig.UserAgentRegex.Trim().Length > 0 && !userAgentConfigs.ContainsKey(userAgentConfig.UserAgentRegex)) {
                                logger.Debug("Added useragent config, useragent=" + userAgentConfig.UserAgentRegex + ", expiry=" + userAgentConfig.MaxAllowedExpiryTime + "s, contact lists=" + userAgentConfig.ContactListSupported + ".");
                                userAgentConfigs.Add(userAgentConfig.UserAgentRegex, userAgentConfig);
                            }
                        }
                    }
                }

                return userAgentConfigs;
            }
            catch (Exception excp) {
                logger.Error("Exception ParseSIPUserAgentConfigurations. " + excp.Message);
                return null;
            }
        }