Exemplo n.º 1
0
        /// <summary>
        /// Given the <paramref name="userAgentStr"/> from an HTTP USER-AGENT header, this method extracts the UPnP version
        /// from the string.
        /// </summary>
        /// <param name="userAgentStr">USER-AGENT header entry of the form "OS/version UPnP/1.1 product/version".</param>
        /// <param name="minorVersion">Returns the minor version number in the specified <paramref name="userAgentStr"/>.</param>
        /// <returns><c>true</c>, if the user agent string could successfully be parsed and denotes a UPnP major version of 1.</returns>
        /// <exception cref="MediaPortal.Utilities.Exceptions.InvalidDataException">If the specified header value is malformed.</exception>
        public static bool ParseUserAgentUPnP1MinorVersion(string userAgentStr, out int minorVersion)
        {
            if (string.IsNullOrEmpty(userAgentStr))
            {
                minorVersion = 0;
                return(false);
            }
            UPnPVersion ver;

            if (!UPnPVersion.TryParseFromUserAgent(userAgentStr, out ver))
            {
                if (UPnPConfiguration.LAX_USER_AGENT_PARSING)
                {
                    // If a client sent a malformed USER-AGENT, we'll assume UPnP Version 1.0
                    minorVersion = 0;
                    return(true);
                }
                throw new UnsupportedRequestException(string.Format("Unsupported USER-AGENT header entry '{0}'", userAgentStr));
            }
            minorVersion = 0;
            if (ver.VerMax != 1)
            {
                return(false);
            }
            minorVersion = ver.VerMin;
            return(true);
        }