Beispiel #1
0
        public object Create(object parent, object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            // unwrap the parent object
            NameValueCollection nvcParent = null;

            if (parent != null)
            {
                nvcParent = ((ClientTargetConfiguration)parent).Configuration;
            }

            // deleage the real work to NameValueSectionHandler
            ClientTargetNameValueHandler nvcHandler = new ClientTargetNameValueHandler();
            NameValueCollection          nvcResult  = (NameValueCollection)nvcHandler.Create(nvcParent, configContextObj, section);

            if (nvcResult == null)
            {
                return(null);
            }

            //
            // Return config data wrapped in an internal class, so
            // semi-trusted code cannot leak configuration data.
            //
            ClientTargetConfiguration clientTargetResult = new ClientTargetConfiguration();

            clientTargetResult.Configuration = nvcResult;

            return(clientTargetResult);
        }
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }


            HttpConfigurationContext configContext = configContextObj as HttpConfigurationContext;

            // section handlers can run in client mode with ConfigurationSettings.GetConfig("sectionName")
            // detect this case and return null to be ensure no exploits from secure client scenarios
            // see ASURT 123738
            if (configContext == null)
            {
                return(null);
            }

            if (HandlerBase.IsPathAtAppLevel(configContext.VirtualPath) == PathLevel.BelowApp)
            {
                throw new ConfigurationException(
                          HttpRuntime.FormatResourceString(SR.Cannot_specify_below_app_level, section.Name),
                          section);
            }

            return(new SecurityPolicyConfig((SecurityPolicyConfig)parent, section, ConfigurationException.GetXmlNodeFilename(section)));
        }
Beispiel #3
0
        internal void CheckAndUpdate(XmlNode section, string [] lockableAttrList)
        {
            // verify the attributes at this level have not been locked
            CheckForLocked(section);


            string  stringlockList = null;
            XmlNode attr           = HandlerBase.GetAndRemoveStringAttribute(section, "lockAttributes", ref stringlockList);

            if (stringlockList == null)
            {
                return;
            }

            // comma-delimited list of attributes
            string [] attributesToLock = stringlockList.Split(new char [] { ',', ';' });
            foreach (string s in attributesToLock)
            {
                string attributeToLock = s.Trim(' ');

                if (HandlerBase.IndexOfCultureInvariant(lockableAttrList, attributeToLock) == -1)
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_lockAttributes, attributeToLock, HandlerBase.CombineStrings(lockableAttrList)),
                              attr);
                }

                _lockedAttributes[attributeToLock] = "";
            }
        }
Beispiel #4
0
        void InitCustomEvaluator(RuleInfo ruleInfo)
        {
            string customEvaluator = ruleInfo._customEvaluator;

            if (customEvaluator == null ||
                customEvaluator.Trim().Length == 0)
            {
                ruleInfo._customEvaluatorType = null;
                return;
            }

            ruleInfo._customEvaluatorType = ConfigUtil.GetType(ruleInfo._customEvaluator,
                                                               "custom", ruleInfo._customEvaluatorConfig);

            // Make sure the type support WebBaseEvent
            HandlerBase.CheckAssignableType(ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].Source,
                                            ruleInfo._customEvaluatorConfig.ElementInformation.Properties["custom"].LineNumber,
                                            typeof(System.Web.Management.IWebEventCustomEvaluator), ruleInfo._customEvaluatorType);

            // Create a public instance of the custom evaluator
            if (_customEvaluatorInstances[ruleInfo._customEvaluatorType] == null)
            {
                _customEvaluatorInstances[ruleInfo._customEvaluatorType] = HttpRuntime.CreatePublicInstance(ruleInfo._customEvaluatorType);
            }
        }
        static XmlNode GetAndRemoveIntegerOrInfiniteAttribute(XmlNode node, string attrib, ref int val)
        {
            string  sValue = null;
            XmlNode a      = HandlerBase.GetAndRemoveStringAttribute(node, attrib, ref sValue);

            if (a != null)
            {
                if (sValue == "Infinite")
                {
                    val = int.MaxValue;
                }
                else
                {
                    try {
                        val = int.Parse(sValue, NumberStyles.None, CultureInfo.InvariantCulture);
                    }
                    catch (Exception e) {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Invalid_integer_attribute, a.Name),
                                  e, a);
                    }
                }
            }

            return(a);
        }
        /*
         * <controlAdapters>
         *   <adapter controlType="System.Web.UI.WebControls.Image"
         *            adapterType="System.Web.UI.WebControls.Adapters.Html32ImageAdapter" />
         * </controlAdapters>
         */
        internal void ProcessControlAdaptersNode(XmlNode node)
        {
            HandlerBase.GetAndRemoveStringAttribute(node, "markupTextWriterType", ref _htmlTextWriterString);
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                if (child.Name != "adapter")
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_element), child);
                }
                XmlAttributeCollection nodeAttributes = child.Attributes;
                string controlString = null;
                string adapterString = null;
                HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "controlType", ref controlString);
                HandlerBase.GetAndRemoveRequiredStringAttribute(child, "adapterType", ref adapterString);

                Type type = CheckType(controlString, typeof(Control), child);

                // Normalize control type name
                controlString = type.AssemblyQualifiedName;

                if (!String.IsNullOrEmpty(adapterString))
                {
                    CheckType(adapterString, typeof(System.Web.UI.Adapters.ControlAdapter), child);
                }

                _adapters[controlString] = adapterString;
            }
            return;
        }
Beispiel #7
0
        //
        // Create a rulelist from an element's children
        //
        static ArrayList RuleListFromElement(ParseState parseState, XmlNode node, bool top)
        {
            ArrayList result = new ArrayList();

            foreach (XmlNode child in node.ChildNodes)
            {
                switch (child.NodeType)
                {
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                    top = false;
                    AppendLines(result, child.Value, node);
                    break;

                case XmlNodeType.Element:
                    switch (child.Name)
                    {
                    case "result":
                        if (top)
                        {
                            ProcessResult(parseState.Evaluator, child);
                        }
                        else
                        {
                            throw new ConfigurationErrorsException(
                                      SR.GetString(SR.Result_must_be_at_the_top_browser_section),
                                      child);
                        }
                        break;

                    case "file":
                        if (parseState.IsExternalFile)
                        {
                            throw new ConfigurationErrorsException(
                                      SR.GetString(SR.File_element_only_valid_in_config),
                                      child);
                        }
                        ProcessFile(parseState.FileList, child);
                        break;

                    default:
                        result.Add(RuleFromElement(parseState, child));
                        break;
                    }
                    top = false;
                    break;

                case XmlNodeType.Comment:
                case XmlNodeType.Whitespace:
                    break;

                default:
                    HandlerBase.ThrowUnrecognizedElement(child);
                    break;
                }
            }

            return(result);
        }
        internal ProtocolsConfiguration(XmlNode section)
        {
            // process XML section in order and apply the directives

            HandlerBase.CheckForUnrecognizedAttributes(section);

            foreach (XmlNode child in section.ChildNodes)
            {
                // skip whitespace and comments
                if (IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> elements

                if (child.Name == "add")
                {
                    String id     = HandlerBase.RemoveRequiredAttribute(child, "id");
                    String phType = HandlerBase.RemoveRequiredAttribute(child, "processHandlerType");
                    String ahType = HandlerBase.RemoveRequiredAttribute(child, "appDomainHandlerType");

                    bool validate = true;
                    HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForNonCommentChildNodes(child);

                    // check duplicate Id

                    /* TEMPORARY allow duplicates for easy Indigo machine.config update
                     * if (_protocolEntries[id] != null) {
                     *  throw new ConfigurationErrorsException(
                     *                  SR.GetString(SR.Dup_protocol_id, id),
                     *                  child);
                     * }
                     */

                    // add entry

                    /* TEMPORARY hide errors and ignore bad <add> tags
                     * to let breaking changes through */
                    try {
                        _protocolEntries[id] = new ProtocolsConfigurationEntry(
                            id, phType, ahType, validate,
                            ConfigurationErrorsException.GetFilename(child),
                            ConfigurationErrorsException.GetLineNumber(child));
                    }
                    catch {
                    }
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }
        }
Beispiel #9
0
 internal static void GetRegistryStringAttribute(ref string val, ConfigurationElement config, string propName)
 {
     if (HandlerBase.CheckAndReadRegistryValue(ref val, false) == false)
     {
         throw new ConfigurationErrorsException(
                   SR.GetString(SR.Invalid_registry_config),
                   config.ElementInformation.Properties[propName].Source, config.ElementInformation.Properties[propName].LineNumber);
     }
 }
Beispiel #10
0
        private void ValidateCredentials()
        {
            _username = UserName;
            _password = Password;

            if (HandlerBase.CheckAndReadRegistryValue(ref _username, false) == false)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_registry_config),
                          ElementInformation.Source, ElementInformation.LineNumber);
            }
            if (HandlerBase.CheckAndReadRegistryValue(ref _password, false) == false)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_registry_config),
                          ElementInformation.Source,
                          ElementInformation.LineNumber);
            }

            if (_username != null && _username.Length < 1)
            {
                _username = null;
            }

            if (_username != null && Impersonate)
            {
                if (_password == null)
                {
                    _password = String.Empty;
                }
            }
            else if (_password != null && _username == null && _password.Length > 0 && Impersonate)
            {
                throw new ConfigurationErrorsException(
                          SR.GetString(SR.Invalid_credentials),
                          ElementInformation.Properties["password"].Source,
                          ElementInformation.Properties["password"].LineNumber);
            }
            if (Impersonate && ImpersonateToken == IntPtr.Zero && _username != null)
            {
                if (error.Length > 0)
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials_2, error),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
                else
                {
                    throw new ConfigurationErrorsException(
                              SR.GetString(SR.Invalid_credentials),
                              ElementInformation.Properties["userName"].Source,
                              ElementInformation.Properties["userName"].LineNumber);
                }
            }
        }
        internal void LoadValuesFromConfigurationXml(XmlNode node)
        {
            // DO NOT SILENTLY IGNORE BOGUS XML IN THE SECTION!
            HandlerBase.CheckForChildNodes(node);

            foreach (XmlAttribute attribute in node.Attributes)
            {
                String name = attribute.Name;
                String text = attribute.Value;

                try {
                    if (name == "culture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _culture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "uiCulture")
                    {
                        if (text.Length == 0)
                        {
                            throw new ArgumentException();  // don't allow empty culture string
                        }
                        _uiCulture = HttpServerUtility.CreateReadOnlyCultureInfo(text);
                    }
                    else if (name == "fileEncoding")
                    {
                        _fileEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "requestEncoding")
                    {
                        _requestEncoding = Encoding.GetEncoding(text);
                    }
                    else if (name == "responseEncoding")
                    {
                        _responseEncoding = Encoding.GetEncoding(text);
                    }
                    else
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Unknown_globalization_attr, name),
                                  attribute);
                    }
                }
                catch (ConfigurationException) {
                    throw;
                }
                catch (Exception e) {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_value_for_globalization_attr, name),
                              e, attribute);
                }
            }
        }
Beispiel #12
0
        //
        // Handle <file src=""/> elements
        //
        static void ProcessFile(ArrayList fileList, XmlNode node)
        {
            string  filename = null;
            XmlNode attr     = HandlerBase.GetAndRemoveRequiredStringAttribute(node, "src", ref filename);

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForNonCommentChildNodes(node);

            fileList.Add(new Pair(filename, attr));
        }
Beispiel #13
0
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            return(MachineKey.CreateConfig(parent, configContextObj, section));
        }
        private void DisallowNonMatchAttribute(XmlNode node)
        {
            string check = null;

            HandlerBase.GetAndRemoveStringAttribute(node, "nonMatch", ref check);
            if (check != null)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Browser_mutually_exclusive_attributes, "match", "nonMatch"), node);
            }
        }
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            bool   impersonation = false;
            String username      = null;
            String password      = null;

            HandlerBase.CheckForChildNodes(section);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "impersonate", ref impersonation);
            HandlerBase.GetAndRemoveStringAttribute(section, "userName", ref username);
            HandlerBase.GetAndRemoveStringAttribute(section, "password", ref password);

            HandlerBase.CheckForUnrecognizedAttributes(section);
            HandlerBase.CheckForChildNodes(section);
            if (username != null && username.Length < 1)
            {
                username = null;
            }
            if (password != null && (password.StartsWith("registry:") || password.StartsWith("Registry:")))
            {
                StringBuilder str  = new StringBuilder(100);
                int           iRet = UnsafeNativeMethods.GetCredentialFromRegistry(password, str, 100);
                if (iRet == 0)
                {
                    password = str.ToString();
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_credentials_pass),
                              section);
                }
            }
            if (username != null && (username.StartsWith("registry:") || username.StartsWith("Registry:")))
            {
                StringBuilder str  = new StringBuilder(100);
                int           iRet = UnsafeNativeMethods.GetCredentialFromRegistry(username, str, 100);
                if (iRet == 0)
                {
                    username = str.ToString();
                }
                else
                {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_credentials_name),
                              section);
                }
            }
            return(new IdentityConfig((IdentityConfig)parent, impersonation, username, password, section));
        }
Beispiel #16
0
        public virtual object Create(Object parent, Object configContextObj, Xml.XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            HttpConfigurationContext httpConfigContext = (HttpConfigurationContext)configContextObj;

            return(new CustomErrors(section, httpConfigContext.VirtualPath, (CustomErrors)parent));
        }
        public virtual object Create(Object parent, object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            bool   bTemp                    = false;
            int    iTemp                    = 0;
            uint   uiTemp                   = 0;
            string sTemp                    = null;
            int    maxWorkerThreads         = 0;
            int    maxIoThreads             = 0;
            int    minWorkerThreads         = 0;
            int    minIoThreads             = 0;
            int    responseDeadlockInterval = 0;

            HandlerBase.GetAndRemoveBooleanAttribute(section, "enable", ref bTemp);
            GetAndRemoveProcessModelTimeout(section, "timeout", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "idleTimeout", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "shutdownTimeout", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestLimit", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestQueueLimit", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "restartQueueLimit", ref iTemp);
            HandlerBase.GetAndRemoveIntegerAttribute(section, "memoryLimit", ref iTemp);
            GetAndRemoveUnsignedIntegerAttribute(section, "cpuMask", ref uiTemp);
            HandlerBase.GetAndRemoveEnumAttribute(section, "logLevel", typeof(LogLevelEnum), ref iTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "userName", ref sTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "password", ref sTemp);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "webGarden", ref bTemp);
            GetAndRemoveProcessModelTimeout(section, "clientConnectedCheck", ref iTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "comImpersonationLevel", ref sTemp);
            HandlerBase.GetAndRemoveStringAttribute(section, "comAuthenticationLevel", ref sTemp);
            GetAndRemoveProcessModelTimeout(section, "responseDeadlockInterval", ref responseDeadlockInterval);
            GetAndRemoveProcessModelTimeout(section, "responseRestartDeadlockInterval", ref iTemp);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "maxWorkerThreads", ref maxWorkerThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "maxIoThreads", ref maxIoThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "minWorkerThreads", ref minWorkerThreads);
            HandlerBase.GetAndRemovePositiveIntegerAttribute(section, "minIoThreads", ref minIoThreads);
            HandlerBase.GetAndRemoveStringAttribute(section, "serverErrorMessageFile", ref sTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "requestAcks", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "pingFrequency", ref iTemp);
            GetAndRemoveProcessModelTimeout(section, "pingTimeout", ref iTemp);
            GetAndRemoveIntegerOrInfiniteAttribute(section, "asyncOption", ref iTemp);


            HandlerBase.CheckForUnrecognizedAttributes(section);
            HandlerBase.CheckForChildNodes(section);

            return(new ProcessModelConfig(maxWorkerThreads, maxIoThreads, minWorkerThreads, minIoThreads, responseDeadlockInterval));
        }
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            GlobalizationConfig config = new GlobalizationConfig((GlobalizationConfig)parent);

            config.LoadValuesFromConfigurationXml(section);

            return(config);
        }
        public object Create(object parent, object configContextObj, XmlNode section)
        {
            // This line allows us to continue to return a config object of a public type
            // like we did in the first release.  Third parties rely on this to get the
            // client script location.  But if the section handler is run in client code
            // we will return null, so we aren't exposing information through the
            // client configuration system.
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            // delegate to SingleTagSectionHandler to do the real work
            SingleTagSectionHandler singleTagSectionHandler = new SingleTagSectionHandler();

            return(singleTagSectionHandler.Create(parent, configContextObj, section));
        }
        //
        // As required by IConfigurationSectionHandler
        //
        public object Create(object parent, object configurationContext, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configurationContext))
            {
                return(null);
            }

            ParseState parseState = new ParseState();

            parseState.SectionName = section.Name;

            // the rule is going to be the previous rule followed by a list containing the new rules
            parseState.Evaluator = new HttpCapabilitiesEvaluator((HttpCapabilitiesEvaluator)parent);
            ArrayList rulelist = new ArrayList();

            // check for random attributes

            HandlerBase.CheckForUnrecognizedAttributes(section);


            // iterate through XML section in order and apply the directives

            ArrayList sublist;

            sublist = RuleListFromElement(parseState, section, true);

            if (sublist.Count > 0)
            {
                parseState.RuleList.Add(new CapabilitiesSection(CapabilitiesRule.Filter, null, null, sublist));
            }

            if (parseState.FileList.Count > 0)
            {
                parseState.IsExternalFile = true;
                ResolveFiles(parseState, configurationContext);
            }

            // Add the new rules

            parseState.Evaluator.AddRuleList(parseState.RuleList);

            return(parseState.Evaluator);
        }
        static XmlNode GetAndRemoveUnsignedIntegerAttribute(XmlNode node, string attrib, ref uint val)
        {
            string  sValue = null;
            XmlNode a      = HandlerBase.GetAndRemoveStringAttribute(node, attrib, ref sValue);

            if (a != null)
            {
                try {
                    val = ParseHexOrDecUInt(sValue);
                }
                catch (Exception e) {
                    throw new ConfigurationException(
                              HttpRuntime.FormatResourceString(SR.Invalid_integer_attribute, a.Name),
                              e, a);
                }
            }

            return(a);
        }
Beispiel #22
0
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            HttpConfigurationContext configContext = configContextObj as HttpConfigurationContext;

            if (HandlerBase.IsPathAtAppLevel(configContext.VirtualPath) == PathLevel.BelowApp)
            {
                throw new ConfigurationException(
                          HttpRuntime.FormatResourceString(SR.Cannot_specify_below_app_level, "Authentication"),
                          section);
            }

            return(new AuthenticationConfig((AuthenticationConfig)parent, section));
        }
        /*
         * <capabilities>
         *   <capability name="mobileDeviceManufacturer" value="OpenWave"</capability>
         *   <capability name="numberOfSoftKeys" value="$(softkeys)"</capability>
         * </capabilities>
         */

        internal void ProcessCapabilitiesNode(XmlNode node)
        {
            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                if (child.Name != "capability")
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_unrecognized_element), child);
                }
                string capabilityName  = null;
                string capabilityValue = null;
                HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "name", ref capabilityName);
                HandlerBase.GetAndRemoveRequiredStringAttribute(child, "value", ref capabilityValue);
                _capabilities[capabilityName] = capabilityValue;
            }
            return;
        }
        static XmlNode GetAndRemoveProcessModelTimeout(XmlNode section, string attrName, ref int val)
        {
            string  sValue = null;
            XmlNode a      = HandlerBase.GetAndRemoveStringAttribute(section, attrName, ref sValue);

            if (sValue != null)
            {
                try {
                    if (sValue == "Infinite")
                    {
                        val = int.MaxValue;
                    }
                    else if (sValue.IndexOf(':') == -1)
                    {
                        val = 60 * int.Parse(sValue, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        string [] times = sValue.Split(new char [] { ':' });

                        if (times.Length > 3)
                        {
                            throw new ConfigurationException(SR.GetString(SR.Config_Process_model_time_invalid), a);
                        }

                        int timeInSeconds = 0;
                        foreach (string time in times)
                        {
                            timeInSeconds = timeInSeconds * 60 + int.Parse(time, NumberStyles.None, CultureInfo.InvariantCulture);
                        }
                        val = timeInSeconds;
                    }
                }
                catch (Exception e) {
                    throw new ConfigurationException(SR.GetString(SR.Config_Process_model_time_invalid), e, a);
                }
            }
            return(a);
        }
        internal void ProcessCaptureNode(XmlNode node, BrowserCapsElementType elementType)
        {
            string match  = null;
            string header = null;

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (child.Name)
                {
                case "userAgent":
                    //match the user agent
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "match", ref match);
                    _captureHeaderChecks.Add(new CheckPair("User-Agent", match));
                    break;

                case "header":
                    //match some arbitrary header
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "name", ref header);
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "match", ref match);
                    _captureHeaderChecks.Add(new CheckPair(header, match));
                    break;

                case "capability":
                    //match against an already set capability
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "name", ref header);
                    HandlerBase.GetAndRemoveRequiredNonEmptyStringAttribute(child, "match", ref match);
                    _captureCapabilityChecks.Add(new CheckPair(header, match));
                    break;

                default:
                    throw new ConfigurationErrorsException(SR.GetString(SR.Config_invalid_element, child.ToString()), child);
                }
            }
            return;
        }
        internal void LoadValuesFromConfigurationXml(XmlNode section)
        {
            HandlerBase.GetAndRemoveBooleanAttribute(section, "enabled", ref _isEnabled);
            HandlerBase.GetAndRemoveNonNegativeIntegerAttribute(section, "requestLimit", ref _requestLimit);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "pageOutput", ref _pageOutput);
            HandlerBase.GetAndRemoveBooleanAttribute(section, "localOnly", ref _localOnly);

            string [] values = { "SortByTime", "SortByCategory" };
            // TraceMode is in another file in a different namespace ... so lets have some protection if they change
            Debug.Assert(TraceMode.SortByTime == (TraceMode)0);
            Debug.Assert(TraceMode.SortByCategory == (TraceMode)1);
            int     iMode     = 0;
            XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(section, "traceMode", values, ref iMode);

            if (attribute != null)
            {
                _outputMode = (TraceMode)iMode;
            }

            HandlerBase.CheckForUnrecognizedAttributes(section);
            // section can have no content
            HandlerBase.CheckForChildNodes(section);
        }
        private void ValidateTypes()
        {
            if (_typesValidated)
            {
                return;
            }

            // check process protocol handler

            Type processHandlerType;

            try {
                processHandlerType = Type.GetType(_processHandlerTypeName, true /*throwOnError*/);
            }
            catch (Exception e) {
                throw new ConfigurationErrorsException(e.Message, e, _configFileName, _configFileLine);
            }
            HandlerBase.CheckAssignableType(_configFileName, _configFileLine, typeof(ProcessProtocolHandler), processHandlerType);

            // check app domain protocol handler

            Type appDomainHandlerType;

            try {
                appDomainHandlerType = Type.GetType(_appDomainHandlerTypeName, true /*throwOnError*/);
            }
            catch (Exception e) {
                throw new ConfigurationErrorsException(e.Message, e, _configFileName, _configFileLine);
            }
            HandlerBase.CheckAssignableType(_configFileName, _configFileLine, typeof(AppDomainProtocolHandler), appDomainHandlerType);

            // remember types

            _processHandlerType   = processHandlerType;
            _appDomainHandlerType = appDomainHandlerType;
            _typesValidated       = true;
        }
Beispiel #28
0
        //
        // Handle the <result> tag
        //
        static void ProcessResult(HttpCapabilitiesDefaultProvider capabilitiesEvaluator, XmlNode node)
        {
            bool inherit = true;

            HandlerBase.GetAndRemoveBooleanAttribute(node, "inherit", ref inherit);
            if (inherit == false)
            {
                capabilitiesEvaluator.ClearParent();
            }

            Type    resultType = null;
            XmlNode attribute  = HandlerBase.GetAndRemoveTypeAttribute(node, "type", ref resultType);

            if (attribute != null)
            {
                if (resultType.Equals(capabilitiesEvaluator._resultType) == false)
                {
                    // be sure the new type is assignable to the parent type
                    HandlerBase.CheckAssignableType(attribute, capabilitiesEvaluator._resultType, resultType);
                    capabilitiesEvaluator._resultType = resultType;
                }
            }

            int cacheTime = 0;

            attribute = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "cacheTime", ref cacheTime);
            //NOTE: we continue to parse the cacheTime for backwards compat
            // it has never been used.  Customer scenarios don't require this support.
            if (attribute != null)
            {
                capabilitiesEvaluator.CacheTime = TimeSpan.FromSeconds(cacheTime);
            }

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForNonCommentChildNodes(node);
        }
        //
        // Handle the <result> tag
        //
        static void ProcessResult(HttpCapabilitiesEvaluator capabilitiesEvaluator, XmlNode node)
        {
            bool inherit = true;

            HandlerBase.GetAndRemoveBooleanAttribute(node, "inherit", ref inherit);
            if (inherit == false)
            {
                capabilitiesEvaluator.ClearParent();
            }

            Type    resultType = null;
            XmlNode attribute  = HandlerBase.GetAndRemoveTypeAttribute(node, "type", ref resultType);

            if (attribute != null)
            {
                if (resultType.Equals(capabilitiesEvaluator._resultType) == false)
                {
                    // be sure the new type is assignable to the parent type
                    HandlerBase.CheckAssignableType(attribute, capabilitiesEvaluator._resultType, resultType);
                    capabilitiesEvaluator._resultType = resultType;
                }
            }

            int cacheTime = 0;

            attribute = HandlerBase.GetAndRemovePositiveIntegerAttribute(node, "cacheTime", ref cacheTime);
            if (attribute != null)
            {
                capabilitiesEvaluator.SetCacheTime(cacheTime);
            }

            HandlerBase.GetAndRemoveBooleanAttribute(node, "cache", ref capabilitiesEvaluator._useCache);

            HandlerBase.CheckForUnrecognizedAttributes(node);
            HandlerBase.CheckForChildNodes(node);
        }
        /*
         * Create
         *
         * Given a partially composed config object (possibly null)
         * and some input from the config system, return a
         * further partially composed config object
         */
        public virtual object Create(Object parent, Object configContextObj, XmlNode section)
        {
            // if called through client config don't even load HttpRuntime
            if (!HandlerBase.IsServerConfiguration(configContextObj))
            {
                return(null);
            }

            HttpModulesConfiguration appConfig;

            // start list as shallow clone of parent

            if (parent == null)
            {
                appConfig = new HttpModulesConfiguration();
            }
            else
            {
                appConfig = new HttpModulesConfiguration((HttpModulesConfiguration)parent);
            }

            // process XML section in order and apply the directives

            HandlerBase.CheckForUnrecognizedAttributes(section);
            foreach (XmlNode child in section.ChildNodes)
            {
                // skip whitespace and comments
                if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
                {
                    continue;
                }

                // process <add> and <clear> elements

                if (child.Name == "add")
                {
                    String name      = HandlerBase.RemoveRequiredAttribute(child, "name");
                    String classname = HandlerBase.RemoveRequiredAttribute(child, "type");
                    bool   insert    = false;

                    /* position and validate removed  See ASURT 96814
                     * int iTemp = 0;
                     * XmlNode attribute = HandlerBase.GetAndRemoveEnumAttribute(child, "position", typeof(HttpModulesConfigurationPosition), ref iTemp);
                     * if (attribute != null) {
                     *  HttpModulesConfigurationPosition pos = (HttpModulesConfigurationPosition)iTemp;
                     *  if (pos == HttpModulesConfigurationPosition.Start) {
                     *      insert = true;
                     *  }
                     * }
                     *
                     * bool validate = true;
                     * HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);
                     */

                    if (IsSpecialModule(classname))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_added_manually, classname),
                                  child);
                    }

                    if (IsSpecialModuleName(name))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_added_manually, name),
                                  child);
                    }

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (appConfig.ContainsEntry(name))
                    {
                        throw new ConfigurationException(
                                  HttpRuntime.FormatResourceString(SR.Module_already_in_app, name),
                                  child);
                    }
                    else
                    {
                        try {
                            appConfig.Add(name, classname, insert);
                        }
                        catch (Exception e) {
                            throw new ConfigurationException(e.Message, e, child);
                        }
                    }
                }
                else if (child.Name == "remove")
                {
                    String name = HandlerBase.RemoveRequiredAttribute(child, "name");

                    /*
                     * bool validate = true;
                     * HandlerBase.GetAndRemoveBooleanAttribute(child, "validate", ref validate);
                     */

                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);

                    if (!appConfig.RemoveEntry(name))
                    {
                        if (IsSpecialModuleName(name))
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Special_module_cannot_be_removed_manually, name),
                                      child);
                        }
                        else
                        {
                            throw new ConfigurationException(
                                      HttpRuntime.FormatResourceString(SR.Module_not_in_app, name),
                                      child);
                        }
                    }
                }
                else if (child.Name == "clear")
                {
                    HandlerBase.CheckForUnrecognizedAttributes(child);
                    HandlerBase.CheckForChildNodes(child);
                    appConfig.RemoveRange(0, appConfig.Count);
                }
                else
                {
                    HandlerBase.ThrowUnrecognizedElement(child);
                }
            }

            // inheritance rule for modules config:
            // machine-level and site-level config allows inheritance, dir- (app-) level does not.

            return(appConfig);
        }