BaseConfigurationRecord
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration.Internal;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Xml;
namespace System.Configuration
{
[DebuggerDisplay("ConfigPath = {ConfigPath}")]
internal abstract class BaseConfigurationRecord : IInternalConfigRecord
{
protected sealed class ConfigRecordStreamInfo
{
private HybridDictionary _streamInfos;
internal bool HasStream { get; set; }
internal string StreamName { get; set; }
internal object StreamVersion { get; set; }
internal Encoding StreamEncoding { get; set; }
internal StreamChangeCallback CallbackDelegate { get; set; }
internal HybridDictionary StreamInfos => _streamInfos ?? (_streamInfos = new HybridDictionary(true));
internal bool HasStreamInfos => _streamInfos != null;
internal ConfigRecordStreamInfo()
{
StreamEncoding = Encoding.UTF8;
}
internal void ClearStreamInfos()
{
_streamInfos = null;
}
}
private sealed class IndirectLocationInputComparer : IComparer<SectionInput>
{
public int Compare(SectionInput x, SectionInput y)
{
if (x == y)
return 0;
string targetConfigPath = x.SectionXmlInfo.TargetConfigPath;
string targetConfigPath2 = y.SectionXmlInfo.TargetConfigPath;
if (UrlPath.IsSubpath(targetConfigPath, targetConfigPath2))
return 1;
if (UrlPath.IsSubpath(targetConfigPath2, targetConfigPath))
return -1;
string definitionConfigPath = x.SectionXmlInfo.DefinitionConfigPath;
string definitionConfigPath2 = y.SectionXmlInfo.DefinitionConfigPath;
if (UrlPath.IsSubpath(definitionConfigPath, definitionConfigPath2))
return 1;
if (UrlPath.IsSubpath(definitionConfigPath2, definitionConfigPath))
return -1;
return 0;
}
}
protected const string NewLine = "\r\n";
internal const string KeywordTrue = "true";
internal const string KeywordFalse = "false";
protected const string ConfigurationTag = "configuration";
protected const string XmlnsAttribute = "xmlns";
protected const string ConfigurationNamespace = "http://schemas.microsoft.com/.NetConfiguration/v2.0";
protected const string ConfigSectionsTag = "configSections";
protected const string SectionTag = "section";
protected const string SectionNameAttribute = "name";
protected const string SectionTypeAttribute = "type";
protected const string SectionAllowLocationAttribute = "allowLocation";
protected const string SectionAllowDefinitionAttribute = "allowDefinition";
protected const string AllowDefinitionEverywhere = "Everywhere";
protected const string AllowDefinitionMachineOnly = "MachineOnly";
protected const string AllowDefinitionMachineToApplication = "MachineToApplication";
protected const string AllowDefinitionMachineToWebRoot = "MachineToWebRoot";
protected const string SectionAllowExeDefinitionAttribute = "allowExeDefinition";
protected const string AllowExeDefinitionMachineToRoaming = "MachineToRoamingUser";
protected const string AllowExeDefinitionMachineToLocal = "MachineToLocalUser";
protected const string SectionRestartonExternalChangesAttribute = "restartOnExternalChanges";
protected const string SectionRequirePermissionAttribute = "requirePermission";
internal const string SectionOverrideModeDefaultAttribute = "overrideModeDefault";
internal const string OverrideModeInherit = "Inherit";
internal const string OverrideModeAllow = "Allow";
internal const string OverrideModeDeny = "Deny";
protected const string SectionGroupTag = "sectionGroup";
protected const string SectionGroupNameAttribute = "name";
protected const string SectionGroupTypeAttribute = "type";
protected const string RemoveTag = "remove";
protected const string ClearTag = "clear";
protected const string LocationTag = "location";
protected const string LocationPathAttribute = "path";
internal const string LocationAllowOverrideAttribute = "allowOverride";
internal const string LocationOverrideModeAttribute = "overrideMode";
protected const string LocationInheritInChildApplicationsAttribute = "inheritInChildApplications";
protected const string ConfigSourceAttribute = "configSource";
internal const string ProtectionProviderAttribute = "configProtectionProvider";
protected const string FormatNewConfigFile = "<?xml version=\"1.0\" encoding=\"{0}\"?>\r\n";
protected const string FormatConfiguration = "<configuration>\r\n";
protected const string FormatConfigurationNamespace = "<configuration xmlns=\"{0}\">\r\n";
protected const string FormatConfigurationEndElement = "</configuration>";
protected const string FormatLocationNoPath = "<location {0} inheritInChildApplications=\"{1}\">\r\n";
protected const string FormatLocationPath = "<location path=\"{2}\" {0} inheritInChildApplications=\"{1}\">\r\n";
protected const string FormatLocationEndElement = "</location>";
internal const string KeywordLocationOverrideModeString = "{0}=\"{1}\"";
protected const string FormatSectionConfigSource = "<{0} configSource=\"{1}\" />";
protected const string FormatConfigSourceFile = "<?xml version=\"1.0\" encoding=\"{0}\"?>\r\n";
protected const string FormatSectionGroupEndElement = "</sectionGroup>";
protected const int ClassSupportsChangeNotifications = 1;
protected const int ClassSupportsRefresh = 2;
protected const int ClassSupportsImpersonation = 4;
protected const int ClassSupportsRestrictedPermissions = 8;
protected const int ClassSupportsKeepInputs = 16;
protected const int ClassSupportsDelayedInit = 32;
protected const int ClassIgnoreLocalErrors = 64;
protected const int ProtectedDataInitialized = 1;
protected const int Closed = 2;
protected const int PrefetchAll = 8;
protected const int IsAboveApplication = 32;
private const int ContextEvaluated = 128;
private const int IsLocationListResolved = 256;
protected const int NamespacePresentInFile = 512;
protected const int IsTrusted = 8192;
protected const int SupportsChangeNotifications = 65536;
protected const int SupportsRefresh = 131072;
protected const int SupportsPath = 262144;
protected const int SupportsKeepInputs = 524288;
protected const int SupportsLocation = 1048576;
protected const int ForceLocationWritten = 16777216;
protected const int SuggestLocationRemoval = 33554432;
protected const int NamespacePresentCurrent = 67108864;
internal const char ConfigPathSeparatorChar = '/';
internal const string ConfigPathSeparatorString = "/";
private const string InvalidFirstSubPathCharacters = "\\./";
private const string InvalidLastSubPathCharacters = "\\./";
private const string InvalidSubPathCharactersString = "\\?:*\"<>|";
private const string ProtectedConfigurationSectionTypeName = "System.Configuration.ProtectedConfigurationSection, System.Configuration.ConfigurationManager";
internal const string ReservedSectionProtectedConfiguration = "configProtectedData";
internal static readonly char[] s_configPathSeparatorParams = new char[1] {
'/'
};
private static string s_appConfigPath;
private static readonly IComparer<SectionInput> s_indirectInputsComparer = new IndirectLocationInputComparer();
private static readonly char[] s_invalidSubPathCharactersArray = "\\?:*\"<>|".ToCharArray();
protected Hashtable _children;
private object _configContext;
protected string _configName;
protected string _configPath;
protected InternalConfigRoot _configRoot;
private ConfigRecordStreamInfo _configStreamInfo;
protected Hashtable _factoryRecords;
protected SafeBitVector32 _flags;
private BaseConfigurationRecord _initDelayedRoot;
private ConfigurationSchemaErrors _initErrors;
protected ArrayList _locationSections;
protected string _locationSubPath;
protected BaseConfigurationRecord _parent;
private ProtectedConfigurationSection _protectedConfig;
protected Hashtable _sectionRecords;
protected abstract SimpleBitVector32 ClassFlags { get; }
internal bool HasStream => ConfigStreamInfo.HasStream;
private bool IsInitDelayed => _initDelayedRoot != null;
internal IInternalConfigHost Host => _configRoot.Host;
internal BaseConfigurationRecord Parent => _parent;
internal bool IsRootConfig => _parent == null;
internal bool IsMachineConfig => _parent == _configRoot.RootConfigRecord;
internal string LocationSubPath => _locationSubPath;
internal bool IsLocationConfig => _locationSubPath != null;
protected ConfigRecordStreamInfo ConfigStreamInfo {
get {
if (!IsLocationConfig)
return _configStreamInfo;
return _parent._configStreamInfo;
}
}
internal string DefaultProviderName => ProtectedConfig.DefaultProvider;
private ProtectedConfigurationSection ProtectedConfig {
get {
if (!_flags[1])
InitProtectedConfigurationSection();
return _protectedConfig;
}
}
private bool HasFactoryRecords => _factoryRecords != null;
internal bool IsEmpty {
get {
if (_parent != null && !_initErrors.HasErrors(false) && (_sectionRecords == null || _sectionRecords.Count == 0) && (_factoryRecords == null || _factoryRecords.Count == 0)) {
if (_locationSections != null)
return _locationSections.Count == 0;
return true;
}
return false;
}
}
internal object ConfigContext {
get {
if (!_flags[128]) {
_configContext = Host.CreateConfigurationContext(ConfigPath, LocationSubPath);
_flags[128] = true;
}
return _configContext;
}
}
internal bool RecordSupportsLocation {
get {
if (!_flags[1048576])
return IsMachineConfig;
return true;
}
}
internal Configuration CurrentConfiguration => _configRoot.CurrentConfiguration;
internal bool TypeStringTransformerIsSet => CurrentConfiguration?.TypeStringTransformerIsSet ?? false;
internal bool AssemblyStringTransformerIsSet => CurrentConfiguration?.AssemblyStringTransformerIsSet ?? false;
internal Func<string, string> TypeStringTransformer => CurrentConfiguration?.TypeStringTransformer;
internal Func<string, string> AssemblyStringTransformer => CurrentConfiguration?.AssemblyStringTransformer;
internal FrameworkName TargetFramework => CurrentConfiguration?.TargetFramework;
internal Stack SectionsStack {
get {
if (CurrentConfiguration != null)
return CurrentConfiguration.SectionsStack;
return new Stack();
}
}
public string ConfigPath => _configPath;
public string StreamName => ConfigStreamInfo.StreamName;
public bool HasInitErrors => _initErrors.HasErrors(ClassFlags[64]);
internal BaseConfigurationRecord()
{
_flags = default(SafeBitVector32);
}
public void ThrowIfInitErrors()
{
ThrowIfParseErrors(_initErrors);
}
public object GetSection(string configKey)
{
return GetSection(configKey, false, true);
}
public object GetLkgSection(string configKey)
{
return GetSection(configKey, true, true);
}
public void RefreshSection(string configKey)
{
_configRoot.ClearResult(this, configKey, true);
}
public void Remove()
{
_configRoot.RemoveConfigRecord(this);
}
protected abstract object CreateSectionFactory(FactoryRecord factoryRecord);
protected abstract object CreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader);
protected abstract object UseParentResult(string configKey, object parentResult, SectionRecord sectionRecord);
protected abstract object GetRuntimeObject(object result);
private bool ShouldPrefetchRawXml(FactoryRecord factoryRecord)
{
if (!_flags[8]) {
switch (factoryRecord.ConfigKey) {
case "configProtectedData":
case "system.diagnostics":
case "appSettings":
case "connectionStrings":
return true;
default:
return Host.PrefetchSection(factoryRecord.Group, factoryRecord.Name);
}
}
return true;
}
internal void Init(IInternalConfigRoot configRoot, BaseConfigurationRecord parent, string configPath, string locationSubPath)
{
_initErrors = new ConfigurationSchemaErrors();
try {
_configRoot = (InternalConfigRoot)configRoot;
_parent = parent;
_configPath = configPath;
_locationSubPath = locationSubPath;
_configName = ConfigPathUtility.GetName(configPath);
_configStreamInfo = (IsLocationConfig ? _parent.ConfigStreamInfo : new ConfigRecordStreamInfo());
if (!IsRootConfig) {
ref SafeBitVector32 flags = ref _flags;
SimpleBitVector32 classFlags = ClassFlags;
flags[65536] = (classFlags[1] && Host.SupportsChangeNotifications);
ref SafeBitVector32 flags2 = ref _flags;
classFlags = ClassFlags;
flags2[131072] = (classFlags[2] && Host.SupportsRefresh);
ref SafeBitVector32 flags3 = ref _flags;
classFlags = ClassFlags;
flags3[524288] = (classFlags[16] || _flags[131072]);
_flags[262144] = Host.SupportsPath;
_flags[1048576] = Host.SupportsLocation;
if (_flags[1048576])
_flags[32] = Host.IsAboveApplication(_configPath);
_flags[8192] = true;
ArrayList arrayList = null;
if (_flags[1048576]) {
if (IsLocationConfig && _parent._locationSections != null) {
_parent.ResolveLocationSections();
int num = 0;
while (num < _parent._locationSections.Count) {
LocationSectionRecord locationSectionRecord = (LocationSectionRecord)_parent._locationSections[num];
if (!StringUtil.EqualsIgnoreCase(locationSectionRecord.SectionXmlInfo.TargetConfigPath, ConfigPath))
num++;
else {
_parent._locationSections.RemoveAt(num);
if (arrayList == null)
arrayList = new ArrayList();
arrayList.Add(locationSectionRecord);
}
}
}
if (IsLocationConfig && Host.IsLocationApplicable(_configPath)) {
Dictionary<string, List<SectionInput>> dictionary = null;
BaseConfigurationRecord parent2 = _parent;
while (!parent2.IsRootConfig) {
if (parent2._locationSections != null) {
parent2.ResolveLocationSections();
foreach (LocationSectionRecord locationSection in parent2._locationSections) {
if (IsLocationConfig && UrlPath.IsSubpath(locationSection.SectionXmlInfo.TargetConfigPath, ConfigPath) && UrlPath.IsSubpath(parent.ConfigPath, locationSection.SectionXmlInfo.TargetConfigPath) && !ShouldSkipDueToInheritInChildApplications(locationSection.SectionXmlInfo.SkipInChildApps, locationSection.SectionXmlInfo.TargetConfigPath)) {
if (dictionary == null)
dictionary = new Dictionary<string, List<SectionInput>>(1);
string configKey = locationSection.SectionXmlInfo.ConfigKey;
if (!((IDictionary)dictionary).Contains((object)configKey))
dictionary.Add(configKey, new List<SectionInput>(1));
dictionary[configKey].Add(new SectionInput(locationSection.SectionXmlInfo, locationSection.ErrorsList));
if (locationSection.HasErrors)
_initErrors.AddSavedLocalErrors(locationSection.Errors);
}
}
}
parent2 = parent2._parent;
}
if (dictionary != null) {
foreach (KeyValuePair<string, List<SectionInput>> item in dictionary) {
List<SectionInput> value = item.Value;
string key = item.Key;
value.Sort(s_indirectInputsComparer);
SectionRecord sectionRecord = EnsureSectionRecord(key, true);
foreach (SectionInput item2 in value) {
sectionRecord.AddIndirectLocationInput(item2);
}
}
}
}
if (Host.IsLocationApplicable(_configPath)) {
BaseConfigurationRecord parent3 = _parent;
while (!parent3.IsRootConfig) {
if (parent3._locationSections != null) {
parent3.ResolveLocationSections();
foreach (LocationSectionRecord locationSection2 in parent3._locationSections) {
if (StringUtil.EqualsIgnoreCase(locationSection2.SectionXmlInfo.TargetConfigPath, _configPath) && !ShouldSkipDueToInheritInChildApplications(locationSection2.SectionXmlInfo.SkipInChildApps)) {
SectionRecord sectionRecord2 = EnsureSectionRecord(locationSection2.ConfigKey, true);
SectionInput sectionInput = new SectionInput(locationSection2.SectionXmlInfo, locationSection2.ErrorsList);
sectionRecord2.AddLocationInput(sectionInput);
if (locationSection2.HasErrors)
_initErrors.AddSavedLocalErrors(locationSection2.Errors);
}
}
}
parent3 = parent3._parent;
}
}
}
if (!IsLocationConfig)
InitConfigFromFile();
else if (arrayList != null) {
foreach (LocationSectionRecord item3 in arrayList) {
SectionRecord sectionRecord3 = EnsureSectionRecord(item3.ConfigKey, true);
SectionInput sectionInput2 = new SectionInput(item3.SectionXmlInfo, item3.ErrorsList);
sectionRecord3.AddFileInput(sectionInput2);
if (item3.HasErrors)
_initErrors.AddSavedLocalErrors(item3.Errors);
}
}
}
} catch (Exception e) {
string filename = ConfigStreamInfo?.StreamName;
_initErrors.AddError(ExceptionUtil.WrapAsConfigException(System.SR.Config_error_loading_XML_file, e, filename, 0), ExceptionAction.Global);
}
}
private void InitConfigFromFile()
{
bool flag = false;
try {
if (ClassFlags[32] && Host.IsInitDelayed(this))
_initDelayedRoot = (_parent._initDelayedRoot ?? this);
else {
ConfigStreamInfo.StreamName = Host.GetStreamName(_configPath);
if (!string.IsNullOrEmpty(ConfigStreamInfo.StreamName)) {
ConfigStreamInfo.StreamVersion = MonitorStream(null, null, ConfigStreamInfo.StreamName);
using (Stream stream = Host.OpenStreamForRead(ConfigStreamInfo.StreamName)) {
if (stream == null)
return;
ConfigStreamInfo.HasStream = true;
_flags[8] = Host.PrefetchAll(_configPath, ConfigStreamInfo.StreamName);
using (XmlUtil xmlUtil = new XmlUtil(stream, ConfigStreamInfo.StreamName, true, _initErrors)) {
ConfigStreamInfo.StreamEncoding = xmlUtil.Reader.Encoding;
Hashtable hashtable = _factoryRecords = ScanFactories(xmlUtil);
AddImplicitSections(null);
flag = true;
if (xmlUtil.Reader.Depth == 1)
ScanSections(xmlUtil);
}
}
}
}
} catch (XmlException e) {
_initErrors.SetSingleGlobalError(ExceptionUtil.WrapAsConfigException(System.SR.Config_error_loading_XML_file, e, ConfigStreamInfo.StreamName, 0));
} catch (Exception e2) {
_initErrors.AddError(ExceptionUtil.WrapAsConfigException(System.SR.Config_error_loading_XML_file, e2, ConfigStreamInfo.StreamName, 0), ExceptionAction.Global);
}
if (_initErrors.HasGlobalErrors) {
_initErrors.ResetLocalErrors();
HybridDictionary hybridDictionary = null;
lock (this) {
if (ConfigStreamInfo.HasStreamInfos) {
hybridDictionary = ConfigStreamInfo.StreamInfos;
ConfigStreamInfo.ClearStreamInfos();
if (!string.IsNullOrEmpty(ConfigStreamInfo.StreamName)) {
StreamInfo streamInfo = (StreamInfo)hybridDictionary[ConfigStreamInfo.StreamName];
if (streamInfo != null) {
hybridDictionary.Remove(ConfigStreamInfo.StreamName);
ConfigStreamInfo.StreamInfos.Add(ConfigStreamInfo.StreamName, streamInfo);
}
}
}
}
if (hybridDictionary != null) {
foreach (StreamInfo value in hybridDictionary.Values) {
if (value.IsMonitored)
Host.StopMonitoringStreamForChanges(value.StreamName, ConfigStreamInfo.CallbackDelegate);
}
}
if (_sectionRecords != null) {
List<SectionRecord> list = null;
foreach (SectionRecord value2 in _sectionRecords.Values) {
if (value2.HasLocationInputs)
value2.RemoveFileInput();
else {
if (list == null)
list = new List<SectionRecord>();
list.Add(value2);
}
}
if (list != null) {
foreach (SectionRecord item in list) {
_sectionRecords.Remove(item.ConfigKey);
}
}
}
_locationSections?.Clear();
_factoryRecords?.Clear();
}
if (!flag)
AddImplicitSections(null);
}
private void RefreshFactoryRecord(string configKey)
{
Hashtable hashtable = null;
FactoryRecord factoryRecord = null;
ConfigurationSchemaErrors configurationSchemaErrors = new ConfigurationSchemaErrors();
int line = 0;
try {
using (Stream stream = Host.OpenStreamForRead(ConfigStreamInfo.StreamName)) {
if (stream != null) {
ConfigStreamInfo.HasStream = true;
using (XmlUtil xmlUtil = new XmlUtil(stream, ConfigStreamInfo.StreamName, true, configurationSchemaErrors))
try {
hashtable = ScanFactories(xmlUtil);
ThrowIfParseErrors(xmlUtil.SchemaErrors);
} catch {
line = xmlUtil.LineNumber;
throw;
}
}
}
if (hashtable == null)
hashtable = new Hashtable();
AddImplicitSections(hashtable);
factoryRecord = (FactoryRecord)hashtable[configKey];
} catch (Exception e) {
configurationSchemaErrors.AddError(ExceptionUtil.WrapAsConfigException(System.SR.Config_error_loading_XML_file, e, ConfigStreamInfo.StreamName, line), ExceptionAction.Global);
}
if (factoryRecord != null || HasFactoryRecords)
EnsureFactories()[configKey] = factoryRecord;
ThrowIfParseErrors(configurationSchemaErrors);
}
private object GetSection(string configKey, bool getLkg, bool checkPermission)
{
GetSectionRecursive(configKey, getLkg, checkPermission, true, true, out object _, out object resultRuntimeObject);
return resultRuntimeObject;
}
private void GetSectionRecursive(string configKey, bool getLkg, bool checkPermission, bool getRuntimeObject, bool requestIsHere, out object result, out object resultRuntimeObject)
{
result = null;
resultRuntimeObject = null;
object result2 = null;
object resultRuntimeObject2 = null;
if (!getLkg)
ThrowIfInitErrors();
bool flag = false;
SectionRecord sectionRecord = GetSectionRecord(configKey, getLkg);
if (sectionRecord != null && sectionRecord.HasResult) {
if (getRuntimeObject && !sectionRecord.HasResultRuntimeObject)
try {
sectionRecord.ResultRuntimeObject = GetRuntimeObject(sectionRecord.Result);
} catch {
if (!getLkg)
throw;
}
if (!getRuntimeObject || sectionRecord.HasResultRuntimeObject) {
result2 = sectionRecord.Result;
if (getRuntimeObject)
resultRuntimeObject2 = sectionRecord.ResultRuntimeObject;
flag = true;
}
}
if (!flag) {
bool flag2 = sectionRecord?.HasInput ?? false;
bool flag3 = requestIsHere | flag2;
try {
FactoryRecord factoryRecord;
bool isRootDeclaredHere;
if (requestIsHere) {
factoryRecord = FindAndEnsureFactoryRecord(configKey, out isRootDeclaredHere);
if (IsInitDelayed && (factoryRecord == null || _initDelayedRoot.IsDefinitionAllowed(factoryRecord.AllowDefinition, factoryRecord.AllowExeDefinition))) {
string configPath = _configPath;
InternalConfigRoot configRoot = _configRoot;
Host.RequireCompleteInit(_initDelayedRoot);
_initDelayedRoot.Remove();
BaseConfigurationRecord baseConfigurationRecord = (BaseConfigurationRecord)configRoot.GetConfigRecord(configPath);
baseConfigurationRecord.GetSectionRecursive(configKey, getLkg, checkPermission, getRuntimeObject, requestIsHere, out result, out resultRuntimeObject);
return;
}
if (factoryRecord == null || factoryRecord.IsGroup)
return;
configKey = factoryRecord.ConfigKey;
} else if (flag2) {
factoryRecord = FindAndEnsureFactoryRecord(configKey, out isRootDeclaredHere);
} else {
factoryRecord = GetFactoryRecord(configKey, false);
if (factoryRecord == null)
isRootDeclaredHere = false;
else
factoryRecord = FindAndEnsureFactoryRecord(configKey, out isRootDeclaredHere);
}
if (isRootDeclaredHere)
flag3 = true;
if ((sectionRecord == null) & flag3)
sectionRecord = EnsureSectionRecord(configKey, true);
bool getRuntimeObject2 = getRuntimeObject && !flag2;
object result3;
object resultRuntimeObject3;
if (isRootDeclaredHere) {
SectionRecord sectionRecord2 = flag2 ? null : sectionRecord;
CreateSectionDefault(configKey, getRuntimeObject2, factoryRecord, sectionRecord2, out result3, out resultRuntimeObject3);
} else
_parent.GetSectionRecursive(configKey, false, false, getRuntimeObject2, false, out result3, out resultRuntimeObject3);
if (flag2) {
if (!Evaluate(factoryRecord, sectionRecord, result3, getLkg, getRuntimeObject, out result2, out resultRuntimeObject2))
flag3 = false;
} else if (sectionRecord != null) {
result2 = UseParentResult(configKey, result3, sectionRecord);
if (getRuntimeObject)
resultRuntimeObject2 = ((result3 != resultRuntimeObject3) ? UseParentResult(configKey, resultRuntimeObject3, sectionRecord) : result2);
} else {
result2 = result3;
resultRuntimeObject2 = resultRuntimeObject3;
}
if (flag3 | checkPermission) {
bool requirePermission = factoryRecord.RequirePermission;
if (flag3) {
if (sectionRecord == null)
sectionRecord = EnsureSectionRecord(configKey, true);
sectionRecord.Result = result2;
if (getRuntimeObject)
sectionRecord.ResultRuntimeObject = resultRuntimeObject2;
sectionRecord.RequirePermission = requirePermission;
}
}
flag = true;
} catch {
if (!getLkg)
throw;
}
if (!flag) {
_parent.GetSectionRecursive(configKey, true, checkPermission, true, true, out result, out resultRuntimeObject);
return;
}
}
result = result2;
if (getRuntimeObject)
resultRuntimeObject = resultRuntimeObject2;
}
protected void CreateSectionDefault(string configKey, bool getRuntimeObject, FactoryRecord factoryRecord, SectionRecord sectionRecord, out object result, out object resultRuntimeObject)
{
SectionRecord sectionRecord2 = sectionRecord ?? new SectionRecord(configKey);
object obj = CallCreateSection(true, factoryRecord, sectionRecord2, null, null, null, -1);
object obj2 = getRuntimeObject ? GetRuntimeObject(obj) : null;
result = obj;
resultRuntimeObject = obj2;
}
private bool ShouldSkipDueToInheritInChildApplications(bool skipInChildApps)
{
if (skipInChildApps)
return _flags[32];
return false;
}
private bool ShouldSkipDueToInheritInChildApplications(bool skipInChildApps, string configPath)
{
if (skipInChildApps)
return Host.IsAboveApplication(configPath);
return false;
}
private bool Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentResult, bool getLkg, bool getRuntimeObject, out object result, out object resultRuntimeObject)
{
result = null;
resultRuntimeObject = null;
object obj = null;
object obj2 = null;
List<SectionInput> locationInputs = sectionRecord.LocationInputs;
List<SectionInput> indirectLocationInputs = sectionRecord.IndirectLocationInputs;
SectionInput fileInput = sectionRecord.FileInput;
bool flag = false;
if (sectionRecord.HasResult) {
if (getRuntimeObject && !sectionRecord.HasResultRuntimeObject)
try {
sectionRecord.ResultRuntimeObject = GetRuntimeObject(sectionRecord.Result);
} catch {
if (!getLkg)
throw;
}
if (!getRuntimeObject || sectionRecord.HasResultRuntimeObject) {
obj = sectionRecord.Result;
if (getRuntimeObject)
obj2 = sectionRecord.ResultRuntimeObject;
flag = true;
}
}
if (!flag) {
Exception ex = null;
try {
string configKey = factoryRecord.ConfigKey;
string[] keys = configKey.Split(s_configPathSeparatorParams);
object parentResult2 = parentResult;
if (indirectLocationInputs != null) {
foreach (SectionInput item in indirectLocationInputs) {
if (!item.HasResult) {
item.ThrowOnErrors();
item.Result = EvaluateOne(keys, item, true, factoryRecord, sectionRecord, parentResult2);
}
parentResult2 = item.Result;
}
}
if (locationInputs != null) {
foreach (SectionInput item2 in locationInputs) {
if (!item2.HasResult) {
item2.ThrowOnErrors();
item2.Result = EvaluateOne(keys, item2, true, factoryRecord, sectionRecord, parentResult2);
}
parentResult2 = item2.Result;
}
}
if (fileInput != null) {
if (!fileInput.HasResult) {
fileInput.ThrowOnErrors();
bool isTrusted = _flags[8192];
fileInput.Result = EvaluateOne(keys, fileInput, isTrusted, factoryRecord, sectionRecord, parentResult2);
}
parentResult2 = fileInput.Result;
} else
parentResult2 = UseParentResult(configKey, parentResult2, sectionRecord);
if (getRuntimeObject)
obj2 = GetRuntimeObject(parentResult2);
obj = parentResult2;
flag = true;
} catch (Exception ex2) {
if (!getLkg || locationInputs == null)
throw;
ex = ex2;
}
if (!flag) {
int num = locationInputs.Count;
while (--num >= 0) {
SectionInput sectionInput = locationInputs[num];
if (sectionInput.HasResult) {
if (getRuntimeObject && !sectionInput.HasResultRuntimeObject)
try {
sectionInput.ResultRuntimeObject = GetRuntimeObject(sectionInput.Result);
} catch {
}
if (!getRuntimeObject || sectionInput.HasResultRuntimeObject) {
obj = sectionInput.Result;
if (getRuntimeObject)
obj2 = sectionInput.ResultRuntimeObject;
break;
}
}
}
if (num < 0)
throw ex;
}
}
if (flag && !_flags[524288])
sectionRecord.ClearRawXml();
result = obj;
if (getRuntimeObject)
resultRuntimeObject = obj2;
return flag;
}
private object EvaluateOne(string[] keys, SectionInput input, bool isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentResult)
{
try {
ConfigXmlReader sectionXmlReader = GetSectionXmlReader(keys, input);
if (sectionXmlReader != null)
return CallCreateSection(isTrusted, factoryRecord, sectionRecord, parentResult, sectionXmlReader, input.SectionXmlInfo.Filename, input.SectionXmlInfo.LineNumber);
return UseParentResult(factoryRecord.ConfigKey, parentResult, sectionRecord);
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Format(System.SR.Config_exception_creating_section, factoryRecord.ConfigKey), e, input.SectionXmlInfo);
}
}
private ConfigXmlReader FindSection(string[] keys, SectionXmlInfo sectionXmlInfo, out int lineNumber)
{
lineNumber = 0;
ConfigXmlReader configXmlReader = null;
using (Stream stream = Host.OpenStreamForRead(sectionXmlInfo.Filename)) {
if (!_flags[131072] && (stream == null || HasStreamChanged(sectionXmlInfo.Filename, sectionXmlInfo.StreamVersion)))
throw new ConfigurationErrorsException(System.SR.Config_file_has_changed, sectionXmlInfo.Filename, 0);
if (stream != null) {
using (XmlUtil xmlUtil = new XmlUtil(stream, sectionXmlInfo.Filename, true)) {
if (sectionXmlInfo.SubPath == null)
configXmlReader = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
else {
xmlUtil.ReadToNextElement();
while (xmlUtil.Reader.Depth > 0) {
if (xmlUtil.Reader.Name == "location") {
bool flag = false;
string text = xmlUtil.Reader.GetAttribute("path");
try {
text = NormalizeLocationSubPath(text, xmlUtil);
flag = true;
} catch (ConfigurationException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.NonSpecific);
}
if (flag && StringUtil.EqualsIgnoreCase(sectionXmlInfo.SubPath, text)) {
configXmlReader = FindSectionRecursive(keys, 0, xmlUtil, ref lineNumber);
if (configXmlReader != null)
break;
}
}
xmlUtil.SkipToNextElement();
}
}
ThrowIfParseErrors(xmlUtil.SchemaErrors);
return configXmlReader;
}
}
return null;
}
}
private ConfigXmlReader FindSectionRecursive(string[] keys, int iKey, XmlUtil xmlUtil, ref int lineNumber)
{
string b = keys[iKey];
ConfigXmlReader configXmlReader = null;
int depth = xmlUtil.Reader.Depth;
xmlUtil.ReadToNextElement();
while (xmlUtil.Reader.Depth > depth) {
if (xmlUtil.Reader.Name == b) {
if (iKey >= keys.Length - 1) {
string filename = xmlUtil.Filename;
int lineNumber2 = xmlUtil.Reader.LineNumber;
string rawXml = xmlUtil.CopySection();
configXmlReader = new ConfigXmlReader(rawXml, filename, lineNumber2);
break;
}
configXmlReader = FindSectionRecursive(keys, iKey + 1, xmlUtil, ref lineNumber);
if (configXmlReader != null)
break;
} else {
if (iKey == 0 && xmlUtil.Reader.Name == "location") {
string text = xmlUtil.Reader.GetAttribute("path");
bool flag = false;
try {
text = NormalizeLocationSubPath(text, xmlUtil);
flag = true;
} catch (ConfigurationException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.NonSpecific);
}
if (flag && text == null) {
configXmlReader = FindSectionRecursive(keys, iKey, xmlUtil, ref lineNumber);
if (configXmlReader != null)
break;
continue;
}
}
xmlUtil.SkipToNextElement();
}
}
return configXmlReader;
}
private ConfigXmlReader LoadConfigSource(string name, SectionXmlInfo sectionXmlInfo)
{
string configSourceStreamName = sectionXmlInfo.ConfigSourceStreamName;
using (Stream stream = Host.OpenStreamForRead(configSourceStreamName)) {
if (stream == null)
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_cannot_open_config_source, sectionXmlInfo.ConfigSource), sectionXmlInfo);
using (XmlUtil xmlUtil = new XmlUtil(stream, configSourceStreamName, true)) {
if (xmlUtil.Reader.Name != name)
throw new ConfigurationErrorsException(System.SR.Config_source_file_format, xmlUtil);
string attribute = xmlUtil.Reader.GetAttribute("configProtectionProvider");
if (attribute != null) {
if (xmlUtil.Reader.AttributeCount != 1)
throw new ConfigurationErrorsException(System.SR.Protection_provider_syntax_error, xmlUtil);
sectionXmlInfo.ProtectionProviderName = ValidateProtectionProviderAttribute(attribute, xmlUtil);
}
int lineNumber = xmlUtil.Reader.LineNumber;
string rawXml = xmlUtil.CopySection();
while (!xmlUtil.Reader.EOF) {
XmlNodeType nodeType = xmlUtil.Reader.NodeType;
if (nodeType != XmlNodeType.Comment)
throw new ConfigurationErrorsException(System.SR.Config_source_file_format, xmlUtil);
xmlUtil.Reader.Read();
}
return new ConfigXmlReader(rawXml, configSourceStreamName, lineNumber);
}
}
}
protected ConfigXmlReader GetSectionXmlReader(string[] keys, SectionInput input)
{
string filename = input.SectionXmlInfo.Filename;
int lineNumber = input.SectionXmlInfo.LineNumber;
try {
string name = keys[keys.Length - 1];
string rawXml = input.SectionXmlInfo.RawXml;
ConfigXmlReader configXmlReader;
if (rawXml != null)
configXmlReader = new ConfigXmlReader(rawXml, input.SectionXmlInfo.Filename, input.SectionXmlInfo.LineNumber);
else if (!string.IsNullOrEmpty(input.SectionXmlInfo.ConfigSource)) {
filename = input.SectionXmlInfo.ConfigSourceStreamName;
lineNumber = 0;
configXmlReader = LoadConfigSource(name, input.SectionXmlInfo);
} else {
lineNumber = 0;
configXmlReader = FindSection(keys, input.SectionXmlInfo, out lineNumber);
}
if (configXmlReader == null)
return configXmlReader;
if (!input.IsProtectionProviderDetermined)
input.ProtectionProvider = GetProtectionProviderFromName(input.SectionXmlInfo.ProtectionProviderName, false);
if (input.ProtectionProvider == null)
return configXmlReader;
return DecryptConfigSection(configXmlReader, input.ProtectionProvider);
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Config_error_loading_XML_file, e, filename, lineNumber);
}
}
internal ProtectedConfigurationProvider GetProtectionProviderFromName(string providerName, bool throwIfNotFound)
{
if (!string.IsNullOrEmpty(providerName))
return ProtectedConfig.GetProviderFromName(providerName);
if (!throwIfNotFound)
return null;
throw new ConfigurationErrorsException(System.SR.Format(System.SR.ProtectedConfigurationProvider_not_found, providerName));
}
internal void InitProtectedConfigurationSection()
{
if (!_flags[1]) {
_protectedConfig = (GetSection("configProtectedData", false, false) as ProtectedConfigurationSection);
_flags[1] = true;
}
}
protected object CallCreateSection(bool inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader, string filename, int line)
{
try {
object obj = CreateSection(inputIsTrusted, factoryRecord, sectionRecord, parentConfig, reader);
if (obj != null)
return obj;
if (parentConfig != null)
throw new ConfigurationErrorsException(System.SR.Config_object_is_null, filename, line);
return obj;
} catch (ThreadAbortException) {
throw;
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Format(System.SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), e, filename, line);
}
}
internal bool IsRootDeclaration(string configKey, bool implicitIsRooted)
{
if (!implicitIsRooted && IsImplicitSection(configKey))
return false;
if (!_parent.IsRootConfig)
return _parent.FindFactoryRecord(configKey, true) == null;
return true;
}
internal FactoryRecord FindFactoryRecord(string configKey, bool permitErrors, out BaseConfigurationRecord configRecord)
{
configRecord = null;
BaseConfigurationRecord baseConfigurationRecord = this;
while (!baseConfigurationRecord.IsRootConfig) {
FactoryRecord factoryRecord = baseConfigurationRecord.GetFactoryRecord(configKey, permitErrors);
if (factoryRecord != null) {
configRecord = baseConfigurationRecord;
return factoryRecord;
}
baseConfigurationRecord = baseConfigurationRecord._parent;
}
return null;
}
internal FactoryRecord FindFactoryRecord(string configKey, bool permitErrors)
{
BaseConfigurationRecord configRecord;
return FindFactoryRecord(configKey, permitErrors, out configRecord);
}
private FactoryRecord FindAndEnsureFactoryRecord(string configKey, out bool isRootDeclaredHere)
{
isRootDeclaredHere = false;
BaseConfigurationRecord configRecord;
FactoryRecord factoryRecord = FindFactoryRecord(configKey, false, out configRecord);
if (factoryRecord == null || factoryRecord.IsGroup)
return factoryRecord;
FactoryRecord factoryRecord2 = factoryRecord;
BaseConfigurationRecord baseConfigurationRecord = configRecord;
BaseConfigurationRecord parent = configRecord._parent;
while (!parent.IsRootConfig) {
BaseConfigurationRecord configRecord2;
FactoryRecord factoryRecord3 = parent.FindFactoryRecord(configKey, false, out configRecord2);
if (factoryRecord3 == null)
break;
factoryRecord2 = factoryRecord3;
baseConfigurationRecord = configRecord2;
parent = configRecord2.Parent;
}
if (factoryRecord2.Factory == null)
try {
object obj2 = factoryRecord2.Factory = baseConfigurationRecord.CreateSectionFactory(factoryRecord2);
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Format(System.SR.Config_exception_creating_section_handler, factoryRecord.ConfigKey), e, factoryRecord);
}
FactoryRecord factoryRecord4 = factoryRecord;
if (factoryRecord4.Factory == null) {
object obj3 = factoryRecord4.Factory = factoryRecord2.Factory;
}
isRootDeclaredHere = (this == baseConfigurationRecord);
return factoryRecord;
}
private Hashtable ScanFactories(XmlUtil xmlUtil)
{
Hashtable hashtable = new Hashtable();
if (xmlUtil.Reader.NodeType != XmlNodeType.Element || xmlUtil.Reader.Name != "configuration")
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_file_doesnt_have_root_configuration, xmlUtil.Filename), xmlUtil);
while (xmlUtil.Reader.MoveToNextAttribute()) {
string name = xmlUtil.Reader.Name;
if (name == "xmlns") {
if (xmlUtil.Reader.Value == "http://schemas.microsoft.com/.NetConfiguration/v2.0") {
_flags[512] = true;
_flags[67108864] = true;
} else {
ConfigurationErrorsException ce = new ConfigurationErrorsException(System.SR.Format(System.SR.Config_namespace_invalid, xmlUtil.Reader.Value, "http://schemas.microsoft.com/.NetConfiguration/v2.0"), xmlUtil);
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Global);
}
} else
xmlUtil.AddErrorUnrecognizedAttribute(ExceptionAction.NonSpecific);
}
xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
if (xmlUtil.Reader.Depth != 1 || xmlUtil.Reader.Name != "configSections")
return hashtable;
xmlUtil.VerifyNoUnrecognizedAttributes(ExceptionAction.NonSpecific);
ScanFactoriesRecursive(xmlUtil, string.Empty, hashtable);
return hashtable;
}
private void ScanFactoriesRecursive(XmlUtil xmlUtil, string parentConfigKey, Hashtable factoryList)
{
xmlUtil.SchemaErrors.ResetLocalErrors();
int depth = xmlUtil.Reader.Depth;
xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
while (xmlUtil.Reader.Depth == depth + 1) {
bool flag = false;
switch (xmlUtil.Reader.Name) {
case "sectionGroup": {
string text4 = null;
string newValue5 = null;
int lineNumber2 = xmlUtil.Reader.LineNumber;
while (xmlUtil.Reader.MoveToNextAttribute()) {
string name2 = xmlUtil.Reader.Name;
if (!(name2 == "name")) {
if (name2 == "type")
xmlUtil.VerifyAndGetNonEmptyStringAttribute(ExceptionAction.Local, out newValue5);
else
xmlUtil.AddErrorUnrecognizedAttribute(ExceptionAction.Local);
} else {
text4 = xmlUtil.Reader.Value;
VerifySectionName(text4, xmlUtil, ExceptionAction.Local, false);
}
}
xmlUtil.Reader.MoveToElement();
if (!xmlUtil.VerifyRequiredAttribute(text4, "name", ExceptionAction.NonSpecific)) {
xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true);
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
} else {
string text5 = CombineConfigKey(parentConfigKey, text4);
FactoryRecord factoryRecord3 = (FactoryRecord)factoryList[text5];
if (factoryRecord3 != null)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_tag_name_already_defined_at_this_level, text4), xmlUtil), ExceptionAction.Local);
else {
FactoryRecord factoryRecord4 = _parent.FindFactoryRecord(text5, true);
if (factoryRecord4 != null) {
text5 = factoryRecord4.ConfigKey;
if (factoryRecord4 != null && (!factoryRecord4.IsGroup || !factoryRecord4.IsEquivalentSectionGroupFactory(Host, newValue5))) {
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_tag_name_already_defined, text4), xmlUtil), ExceptionAction.Local);
factoryRecord4 = null;
}
}
factoryRecord3 = (FactoryRecord)(factoryList[text5] = (factoryRecord4?.CloneSectionGroup(newValue5, xmlUtil.Filename, lineNumber2) ?? new FactoryRecord(text5, parentConfigKey, text4, newValue5, xmlUtil.Filename, lineNumber2)));
}
factoryRecord3.AddErrors(xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true));
ScanFactoriesRecursive(xmlUtil, text5, factoryList);
}
break;
}
case "section": {
string text2 = null;
string newValue = null;
ConfigurationAllowDefinition allowDefinition = ConfigurationAllowDefinition.Everywhere;
ConfigurationAllowExeDefinition allowExeDefinition = ConfigurationAllowExeDefinition.MachineToApplication;
OverrideModeSetting overrideModeDefault = OverrideModeSetting.s_sectionDefault;
bool newValue2 = true;
bool newValue3 = true;
bool newValue4 = true;
bool flag2 = false;
int lineNumber = xmlUtil.Reader.LineNumber;
while (xmlUtil.Reader.MoveToNextAttribute()) {
string name = xmlUtil.Reader.Name;
if (name != null) {
switch (name.Length) {
case 4:
break;
case 13:
goto IL_02ed;
case 18:
goto IL_0303;
case 15:
goto IL_0319;
case 24:
goto IL_032f;
case 17:
goto IL_0345;
case 19:
goto IL_035b;
default:
goto IL_044b;
}
switch (name[0]) {
case 'n':
break;
case 't':
goto IL_02d7;
default:
goto IL_044b;
}
if (name == "name") {
text2 = xmlUtil.Reader.Value;
VerifySectionName(text2, xmlUtil, ExceptionAction.Local, false);
continue;
}
}
goto IL_044b;
IL_0319:
if (name == "allowDefinition") {
try {
allowDefinition = AllowDefinitionToEnum(xmlUtil);
} catch (ConfigurationException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
}
continue;
}
goto IL_044b;
IL_02ed:
if (name == "allowLocation") {
xmlUtil.VerifyAndGetBooleanAttribute(ExceptionAction.Local, true, out newValue2);
continue;
}
goto IL_044b;
IL_035b:
if (name == "overrideModeDefault") {
try {
overrideModeDefault = OverrideModeSetting.CreateFromXmlReadValue(OverrideModeSetting.ParseOverrideModeXmlValue(xmlUtil.Reader.Value, xmlUtil));
if (overrideModeDefault.OverrideMode == OverrideMode.Inherit)
overrideModeDefault.ChangeModeInternal(OverrideMode.Allow);
} catch (ConfigurationException ce2) {
xmlUtil.SchemaErrors.AddError(ce2, ExceptionAction.Local);
}
continue;
}
goto IL_044b;
IL_0303:
if (name == "allowExeDefinition") {
try {
allowExeDefinition = AllowExeDefinitionToEnum(xmlUtil.Reader.Value, xmlUtil);
} catch (ConfigurationException ce3) {
xmlUtil.SchemaErrors.AddError(ce3, ExceptionAction.Local);
}
continue;
}
goto IL_044b;
IL_0345:
if (name == "requirePermission") {
xmlUtil.VerifyAndGetBooleanAttribute(ExceptionAction.Local, true, out newValue4);
continue;
}
goto IL_044b;
IL_02d7:
if (name == "type") {
xmlUtil.VerifyAndGetNonEmptyStringAttribute(ExceptionAction.Local, out newValue);
flag2 = true;
continue;
}
goto IL_044b;
IL_032f:
if (name == "restartOnExternalChanges") {
xmlUtil.VerifyAndGetBooleanAttribute(ExceptionAction.Local, true, out newValue3);
continue;
}
goto IL_044b;
IL_044b:
xmlUtil.AddErrorUnrecognizedAttribute(ExceptionAction.Local);
}
xmlUtil.Reader.MoveToElement();
if (!xmlUtil.VerifyRequiredAttribute(text2, "name", ExceptionAction.NonSpecific))
xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true);
else {
if (!flag2)
xmlUtil.AddErrorRequiredAttribute("type", ExceptionAction.Local);
string text3 = CombineConfigKey(parentConfigKey, text2);
FactoryRecord factoryRecord = (FactoryRecord)factoryList[text3];
if (factoryRecord != null)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_tag_name_already_defined_at_this_level, text2), xmlUtil), ExceptionAction.Local);
else {
FactoryRecord factoryRecord2 = _parent.FindFactoryRecord(text3, true);
if (factoryRecord2 != null) {
text3 = factoryRecord2.ConfigKey;
if (factoryRecord2.IsGroup) {
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_tag_name_already_defined, text2), xmlUtil), ExceptionAction.Local);
factoryRecord2 = null;
} else if (!factoryRecord2.IsEquivalentSectionFactory(Host, newValue, newValue2, allowDefinition, allowExeDefinition, newValue3, newValue4)) {
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_tag_name_already_defined, text2), xmlUtil), ExceptionAction.Local);
factoryRecord2 = null;
}
}
factoryRecord = (FactoryRecord)(factoryList[text3] = (factoryRecord2?.CloneSection(xmlUtil.Filename, lineNumber) ?? new FactoryRecord(text3, parentConfigKey, text2, newValue, newValue2, allowDefinition, allowExeDefinition, overrideModeDefault, newValue3, newValue4, _flags[8192], false, xmlUtil.Filename, lineNumber)));
}
factoryRecord.AddErrors(xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true));
}
goto IL_064d;
}
case "remove": {
string text = null;
while (xmlUtil.Reader.MoveToNextAttribute()) {
if (xmlUtil.Reader.Name != "name")
xmlUtil.AddErrorUnrecognizedAttribute(ExceptionAction.NonSpecific);
else
text = xmlUtil.Reader.Value;
}
xmlUtil.Reader.MoveToElement();
if (xmlUtil.VerifyRequiredAttribute(text, "name", ExceptionAction.NonSpecific))
VerifySectionName(text, xmlUtil, ExceptionAction.NonSpecific, false);
goto IL_064d;
}
case "clear":
xmlUtil.VerifyNoUnrecognizedAttributes(ExceptionAction.NonSpecific);
goto IL_064d;
default:
{
xmlUtil.AddErrorUnrecognizedElement(ExceptionAction.NonSpecific);
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
flag = true;
goto IL_064d;
}
IL_064d:
if (!flag) {
xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
if (xmlUtil.Reader.Depth > depth + 1) {
xmlUtil.AddErrorUnrecognizedElement(ExceptionAction.NonSpecific);
while (xmlUtil.Reader.Depth > depth + 1) {
xmlUtil.ReadToNextElement();
}
}
}
break;
}
}
}
internal static ConfigurationAllowExeDefinition AllowExeDefinitionToEnum(string allowExeDefinition, XmlUtil xmlUtil)
{
if (allowExeDefinition == "MachineOnly")
return ConfigurationAllowExeDefinition.MachineOnly;
if (allowExeDefinition == "MachineToApplication")
return ConfigurationAllowExeDefinition.MachineToApplication;
if (allowExeDefinition == "MachineToRoamingUser")
return ConfigurationAllowExeDefinition.MachineToRoamingUser;
if (!(allowExeDefinition == "MachineToLocalUser"))
throw new ConfigurationErrorsException(System.SR.Config_section_allow_exe_definition_attribute_invalid, xmlUtil);
return ConfigurationAllowExeDefinition.MachineToLocalUser;
}
internal static ConfigurationAllowDefinition AllowDefinitionToEnum(XmlUtil xmlUtil)
{
switch (xmlUtil.Reader.Value) {
case "Everywhere":
return ConfigurationAllowDefinition.Everywhere;
case "MachineOnly":
return ConfigurationAllowDefinition.MachineOnly;
case "MachineToApplication":
return ConfigurationAllowDefinition.MachineToApplication;
case "MachineToWebRoot":
return ConfigurationAllowDefinition.MachineToWebRoot;
default:
throw new ConfigurationErrorsException(System.SR.Config_section_allow_definition_attribute_invalid, xmlUtil);
}
}
internal static string CombineConfigKey(string parentConfigKey, string tagName)
{
if (string.IsNullOrEmpty(parentConfigKey))
return tagName;
if (string.IsNullOrEmpty(tagName))
return parentConfigKey;
return parentConfigKey + "/" + tagName;
}
internal static void SplitConfigKey(string configKey, out string group, out string name)
{
int num = configKey.LastIndexOf('/');
if (num == -1) {
group = string.Empty;
name = configKey;
} else {
group = configKey.Substring(0, num);
name = configKey.Substring(num + 1);
}
}
[Conditional("DEBUG")]
private void DebugValidateIndirectInputs(SectionRecord sectionRecord)
{
if (!_parent.IsRootConfig) {
for (int num = sectionRecord.IndirectLocationInputs.Count - 1; num >= 0; num--) {
SectionInput sectionInput = sectionRecord.IndirectLocationInputs[num];
}
}
}
private OverrideMode ResolveOverrideModeFromParent(string configKey, out OverrideMode childLockMode)
{
OverrideMode overrideMode = OverrideMode.Inherit;
BaseConfigurationRecord parent = Parent;
BaseConfigurationRecord parent2 = Parent;
childLockMode = OverrideMode.Inherit;
while (!parent.IsRootConfig && overrideMode == OverrideMode.Inherit) {
SectionRecord sectionRecord = parent.GetSectionRecord(configKey, true);
if (sectionRecord != null) {
if (!IsLocationConfig || parent2 != parent)
overrideMode = (childLockMode = ((!sectionRecord.LockChildren) ? OverrideMode.Allow : OverrideMode.Deny));
else {
overrideMode = ((!sectionRecord.Locked) ? OverrideMode.Allow : OverrideMode.Deny);
childLockMode = ((!sectionRecord.LockChildren) ? OverrideMode.Allow : OverrideMode.Deny);
}
}
parent = parent._parent;
}
if (overrideMode == OverrideMode.Inherit) {
OverrideMode overrideMode2 = FindFactoryRecord(configKey, true).OverrideModeDefault.OverrideMode;
if (!((!IsLocationConfig) ? (GetFactoryRecord(configKey, true) != null) : (Parent.GetFactoryRecord(configKey, true) != null)))
overrideMode = (childLockMode = overrideMode2);
else {
overrideMode = OverrideMode.Allow;
childLockMode = overrideMode2;
}
}
return overrideMode;
}
protected OverrideMode GetSectionLockedMode(string configKey)
{
OverrideMode childLockMode;
return GetSectionLockedMode(configKey, out childLockMode);
}
protected OverrideMode GetSectionLockedMode(string configKey, out OverrideMode childLockMode)
{
SectionRecord sectionRecord = GetSectionRecord(configKey, true);
OverrideMode result;
if (sectionRecord != null) {
result = ((!sectionRecord.Locked) ? OverrideMode.Allow : OverrideMode.Deny);
childLockMode = ((!sectionRecord.LockChildren) ? OverrideMode.Allow : OverrideMode.Deny);
} else
result = ResolveOverrideModeFromParent(configKey, out childLockMode);
return result;
}
private void ScanSections(XmlUtil xmlUtil)
{
ScanSectionsRecursive(xmlUtil, string.Empty, false, null, OverrideModeSetting.s_locationDefault, false);
}
private void ScanSectionsRecursive(XmlUtil xmlUtil, string parentConfigKey, bool inLocation, string locationSubPath, OverrideModeSetting overrideMode, bool skipInChildApps)
{
xmlUtil.SchemaErrors.ResetLocalErrors();
int num;
if (parentConfigKey.Length == 0 && !inLocation)
num = 0;
else {
num = xmlUtil.Reader.Depth;
xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
}
while (xmlUtil.Reader.Depth == num + 1) {
string name = xmlUtil.Reader.Name;
if (name == "configSections") {
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_client_config_too_many_configsections_elements, name), xmlUtil), ExceptionAction.NonSpecific);
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
continue;
}
if (name == "location") {
if ((parentConfigKey.Length > 0) | inLocation) {
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_location_location_not_allowed, xmlUtil), ExceptionAction.Global);
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
} else
ScanLocationSection(xmlUtil);
continue;
}
string text = CombineConfigKey(parentConfigKey, name);
FactoryRecord factoryRecord = FindFactoryRecord(text, true);
if (factoryRecord == null) {
if (!ClassFlags[64])
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Format(System.SR.Config_unrecognized_configuration_section, text), xmlUtil), ExceptionAction.Local);
VerifySectionName(name, xmlUtil, ExceptionAction.Local, false);
factoryRecord = new FactoryRecord(text, parentConfigKey, name, typeof(DefaultSection).AssemblyQualifiedName, true, ConfigurationAllowDefinition.Everywhere, ConfigurationAllowExeDefinition.MachineToRoamingUser, OverrideModeSetting.s_sectionDefault, true, true, _flags[8192], true, null, -1);
factoryRecord.AddErrors(xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(true));
EnsureFactories()[text] = factoryRecord;
}
if (factoryRecord.IsGroup) {
if (factoryRecord.HasErrors)
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
else {
if (xmlUtil.Reader.AttributeCount > 0) {
while (xmlUtil.Reader.MoveToNextAttribute()) {
if (IsReservedAttributeName(xmlUtil.Reader.Name))
xmlUtil.AddErrorReservedAttribute(ExceptionAction.NonSpecific);
}
xmlUtil.Reader.MoveToElement();
}
ScanSectionsRecursive(xmlUtil, text, inLocation, locationSubPath, overrideMode, skipInChildApps);
}
continue;
}
text = factoryRecord.ConfigKey;
string filename = xmlUtil.Filename;
int lineNumber = xmlUtil.LineNumber;
string rawXml = null;
string text2 = null;
string text3 = null;
string protectionProviderName = null;
OverrideMode overrideMode2 = OverrideMode.Inherit;
OverrideMode childLockMode = OverrideMode.Inherit;
bool flag = false;
bool flag2 = locationSubPath == null;
if (!factoryRecord.HasErrors) {
if (inLocation && !factoryRecord.AllowLocation)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_section_cannot_be_used_in_location, xmlUtil), ExceptionAction.Local);
if (flag2) {
SectionRecord sectionRecord = GetSectionRecord(text, true);
if (sectionRecord != null && sectionRecord.HasFileInput && !factoryRecord.IsIgnorable())
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_sections_must_be_unique, xmlUtil), ExceptionAction.Local);
try {
VerifyDefinitionAllowed(factoryRecord, _configPath, xmlUtil);
} catch (ConfigurationException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Local);
}
}
overrideMode2 = GetSectionLockedMode(text, out childLockMode);
if (overrideMode2 == OverrideMode.Deny)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_section_locked, xmlUtil), ExceptionAction.Local);
if (xmlUtil.Reader.AttributeCount >= 1) {
string attribute = xmlUtil.Reader.GetAttribute("configSource");
if (attribute != null) {
try {
text2 = NormalizeConfigSource(attribute, xmlUtil);
} catch (ConfigurationException ce2) {
xmlUtil.SchemaErrors.AddError(ce2, ExceptionAction.Local);
}
if (xmlUtil.Reader.AttributeCount != 1)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_source_syntax_error, xmlUtil), ExceptionAction.Local);
}
string attribute2 = xmlUtil.Reader.GetAttribute("configProtectionProvider");
if (attribute2 != null) {
try {
protectionProviderName = ValidateProtectionProviderAttribute(attribute2, xmlUtil);
} catch (ConfigurationException ce3) {
xmlUtil.SchemaErrors.AddError(ce3, ExceptionAction.Local);
}
if (xmlUtil.Reader.AttributeCount != 1)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Protection_provider_syntax_error, xmlUtil), ExceptionAction.Local);
}
if (attribute != null && !xmlUtil.Reader.IsEmptyElement) {
while (xmlUtil.Reader.Read()) {
XmlNodeType nodeType = xmlUtil.Reader.NodeType;
switch (nodeType) {
default:
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Config_source_syntax_error, xmlUtil), ExceptionAction.Local);
if (nodeType == XmlNodeType.Element)
xmlUtil.StrictSkipToOurParentsEndElement(ExceptionAction.NonSpecific);
else
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
flag = true;
goto IL_03f0;
case XmlNodeType.Comment:
break;
case XmlNodeType.EndElement:
goto IL_03f0;
}
}
}
}
goto IL_03f0;
}
goto IL_048e;
IL_03f0:
if (text2 != null)
try {
try {
text3 = Host.GetStreamNameForConfigSource(ConfigStreamInfo.StreamName, text2);
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Config_source_invalid, e, xmlUtil);
}
ValidateUniqueConfigSource(text, text3, text2, xmlUtil);
object obj = MonitorStream(text, text2, text3);
} catch (ConfigurationException ce4) {
xmlUtil.SchemaErrors.AddError(ce4, ExceptionAction.Local);
}
if (!xmlUtil.SchemaErrors.HasLocalErrors && text2 == null && ShouldPrefetchRawXml(factoryRecord)) {
rawXml = xmlUtil.CopySection();
if (xmlUtil.Reader.NodeType != XmlNodeType.Element) {
xmlUtil.VerifyIgnorableNodeType(ExceptionAction.NonSpecific);
xmlUtil.StrictReadToNextElement(ExceptionAction.NonSpecific);
}
flag = true;
}
goto IL_048e;
IL_048e:
List<ConfigurationException> errors = xmlUtil.SchemaErrors.RetrieveAndResetLocalErrors(flag2);
if (!flag)
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
bool flag3 = true;
if (flag2) {
if (ShouldSkipDueToInheritInChildApplications(skipInChildApps))
flag3 = false;
} else if (!_flags[1048576]) {
flag3 = false;
}
if (flag3) {
string targetConfigPath = (locationSubPath == null) ? _configPath : null;
SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(text, _configPath, targetConfigPath, locationSubPath, filename, lineNumber, ConfigStreamInfo.StreamVersion, rawXml, text2, text3, protectionProviderName, overrideMode, skipInChildApps);
if (locationSubPath == null) {
SectionRecord sectionRecord2 = EnsureSectionRecordUnsafe(text, true);
sectionRecord2.ChangeLockSettings(overrideMode2, childLockMode);
SectionInput sectionInput = new SectionInput(sectionXmlInfo, errors);
sectionRecord2.AddFileInput(sectionInput);
} else {
LocationSectionRecord value = new LocationSectionRecord(sectionXmlInfo, errors);
EnsureLocationSections().Add(value);
}
}
}
}
private void ScanLocationSection(XmlUtil xmlUtil)
{
string text = null;
bool newValue = true;
int globalErrorCount = xmlUtil.SchemaErrors.GlobalErrorCount;
OverrideModeSetting overrideMode = OverrideModeSetting.s_locationDefault;
bool flag = false;
while (xmlUtil.Reader.MoveToNextAttribute()) {
switch (xmlUtil.Reader.Name) {
case "path":
text = xmlUtil.Reader.Value;
break;
case "allowOverride":
if (flag)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Invalid_override_mode_declaration, xmlUtil), ExceptionAction.Global);
else {
xmlUtil.VerifyAndGetBooleanAttribute(ExceptionAction.Global, true, out bool newValue2);
overrideMode = OverrideModeSetting.CreateFromXmlReadValue(newValue2);
flag = true;
}
break;
case "overrideMode":
if (flag)
xmlUtil.SchemaErrors.AddError(new ConfigurationErrorsException(System.SR.Invalid_override_mode_declaration, xmlUtil), ExceptionAction.Global);
else {
overrideMode = OverrideModeSetting.CreateFromXmlReadValue(OverrideModeSetting.ParseOverrideModeXmlValue(xmlUtil.Reader.Value, xmlUtil));
flag = true;
}
break;
case "inheritInChildApplications":
xmlUtil.VerifyAndGetBooleanAttribute(ExceptionAction.Global, true, out newValue);
break;
default:
xmlUtil.AddErrorUnrecognizedAttribute(ExceptionAction.Global);
break;
}
}
xmlUtil.Reader.MoveToElement();
try {
text = NormalizeLocationSubPath(text, xmlUtil);
if (text == null && !newValue && Host.IsDefinitionAllowed(_configPath, ConfigurationAllowDefinition.MachineToWebRoot, ConfigurationAllowExeDefinition.MachineOnly))
throw new ConfigurationErrorsException(System.SR.Location_invalid_inheritInChildApplications_in_machine_or_root_web_config, xmlUtil);
} catch (ConfigurationErrorsException ce) {
xmlUtil.SchemaErrors.AddError(ce, ExceptionAction.Global);
}
if (xmlUtil.SchemaErrors.GlobalErrorCount > globalErrorCount)
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
else if (text == null) {
ScanSectionsRecursive(xmlUtil, string.Empty, true, null, overrideMode, !newValue);
} else if (!_flags[1048576]) {
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
} else {
IInternalConfigHost host = Host;
if (this is RuntimeConfigurationRecord && host != null && text.Length != 0 && text[0] != '.') {
if (s_appConfigPath == null) {
object configContext = ConfigContext;
if (configContext != null) {
string value = configContext.ToString();
Interlocked.CompareExchange(ref s_appConfigPath, value, null);
}
}
string configPathFromLocationSubPath = host.GetConfigPathFromLocationSubPath(_configPath, text);
if (!StringUtil.StartsWithOrdinalIgnoreCase(s_appConfigPath, configPathFromLocationSubPath) && !StringUtil.StartsWithOrdinalIgnoreCase(configPathFromLocationSubPath, s_appConfigPath)) {
xmlUtil.StrictSkipToNextElement(ExceptionAction.NonSpecific);
return;
}
}
AddLocation(text);
ScanSectionsRecursive(xmlUtil, string.Empty, true, text, overrideMode, !newValue);
}
}
protected virtual void AddLocation(string locationSubPath)
{
}
private void ResolveLocationSections()
{
if (!_flags[256]) {
if (!_parent.IsRootConfig)
_parent.ResolveLocationSections();
lock (this) {
if (!_flags[256] && _locationSections != null) {
HybridDictionary hybridDictionary = new HybridDictionary(true);
foreach (LocationSectionRecord locationSection in _locationSections) {
string configPathFromLocationSubPath = Host.GetConfigPathFromLocationSubPath(_configPath, locationSection.SectionXmlInfo.SubPath);
locationSection.SectionXmlInfo.TargetConfigPath = configPathFromLocationSubPath;
HybridDictionary hybridDictionary2 = (HybridDictionary)hybridDictionary[configPathFromLocationSubPath];
if (hybridDictionary2 == null) {
hybridDictionary2 = new HybridDictionary(false);
hybridDictionary.Add(configPathFromLocationSubPath, hybridDictionary2);
}
LocationSectionRecord locationSectionRecord2 = (LocationSectionRecord)hybridDictionary2[locationSection.ConfigKey];
FactoryRecord factoryRecord = null;
if (locationSectionRecord2 == null)
hybridDictionary2.Add(locationSection.ConfigKey, locationSection);
else {
factoryRecord = FindFactoryRecord(locationSection.ConfigKey, true);
if (factoryRecord == null || !factoryRecord.IsIgnorable()) {
if (!locationSectionRecord2.HasErrors)
locationSectionRecord2.AddError(new ConfigurationErrorsException(System.SR.Config_sections_must_be_unique, locationSectionRecord2.SectionXmlInfo));
locationSection.AddError(new ConfigurationErrorsException(System.SR.Config_sections_must_be_unique, locationSection.SectionXmlInfo));
}
}
if (factoryRecord == null)
factoryRecord = FindFactoryRecord(locationSection.ConfigKey, true);
if (!factoryRecord.HasErrors)
try {
VerifyDefinitionAllowed(factoryRecord, configPathFromLocationSubPath, locationSection.SectionXmlInfo);
} catch (ConfigurationException e) {
locationSection.AddError(e);
}
}
BaseConfigurationRecord parent = _parent;
while (!parent.IsRootConfig) {
foreach (LocationSectionRecord locationSection2 in _locationSections) {
bool flag = false;
SectionRecord sectionRecord = parent.GetSectionRecord(locationSection2.ConfigKey, true);
if (sectionRecord != null && (sectionRecord.LockChildren || sectionRecord.Locked))
flag = true;
else if (parent._locationSections != null) {
string targetConfigPath = locationSection2.SectionXmlInfo.TargetConfigPath;
foreach (LocationSectionRecord locationSection3 in parent._locationSections) {
string targetConfigPath2 = locationSection3.SectionXmlInfo.TargetConfigPath;
if (locationSection3.SectionXmlInfo.OverrideModeSetting.IsLocked && locationSection2.ConfigKey == locationSection3.ConfigKey && UrlPath.IsEqualOrSubpath(targetConfigPath, targetConfigPath2)) {
flag = true;
break;
}
}
}
if (flag)
locationSection2.AddError(new ConfigurationErrorsException(System.SR.Config_section_locked, locationSection2.SectionXmlInfo));
}
parent = parent._parent;
}
}
_flags[256] = true;
}
}
}
private void VerifyDefinitionAllowed(FactoryRecord factoryRecord, string configPath, IConfigErrorInfo errorInfo)
{
Host.VerifyDefinitionAllowed(configPath, factoryRecord.AllowDefinition, factoryRecord.AllowExeDefinition, errorInfo);
}
internal bool IsDefinitionAllowed(ConfigurationAllowDefinition allowDefinition, ConfigurationAllowExeDefinition allowExeDefinition)
{
return Host.IsDefinitionAllowed(_configPath, allowDefinition, allowExeDefinition);
}
protected static void VerifySectionName(string name, XmlUtil xmlUtil, ExceptionAction action, bool allowImplicit)
{
try {
VerifySectionName(name, xmlUtil, allowImplicit);
} catch (ConfigurationErrorsException ce) {
xmlUtil.SchemaErrors.AddError(ce, action);
}
}
protected static void VerifySectionName(string name, IConfigErrorInfo errorInfo, bool allowImplicit)
{
if (string.IsNullOrEmpty(name))
throw new ConfigurationErrorsException(System.SR.Config_tag_name_invalid, errorInfo);
try {
XmlConvert.VerifyName(name);
} catch (Exception e) {
throw ExceptionUtil.WrapAsConfigException(System.SR.Config_tag_name_invalid, e, errorInfo);
}
if (IsImplicitSection(name)) {
if (!allowImplicit)
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Cannot_declare_or_remove_implicit_section, name), errorInfo);
} else {
if (StringUtil.StartsWithOrdinal(name, "config"))
throw new ConfigurationErrorsException(System.SR.Config_tag_name_cannot_begin_with_config, errorInfo);
if (name == "location")
throw new ConfigurationErrorsException(System.SR.Config_tag_name_cannot_be_location, errorInfo);
}
}
internal static string NormalizeLocationSubPath(string subPath, IConfigErrorInfo errorInfo)
{
if (string.IsNullOrEmpty(subPath))
return null;
if (subPath == ".")
return null;
string text = subPath.TrimStart();
if (text.Length != subPath.Length)
throw new ConfigurationErrorsException(System.SR.Config_location_path_invalid_first_character, errorInfo);
if ("\\./".IndexOf(subPath[0]) != -1)
throw new ConfigurationErrorsException(System.SR.Config_location_path_invalid_first_character, errorInfo);
text = subPath.TrimEnd();
if (text.Length != subPath.Length)
throw new ConfigurationErrorsException(System.SR.Config_location_path_invalid_last_character, errorInfo);
if ("\\./".IndexOf(subPath[subPath.Length - 1]) != -1)
throw new ConfigurationErrorsException(System.SR.Config_location_path_invalid_last_character, errorInfo);
if (subPath.IndexOfAny(s_invalidSubPathCharactersArray) != -1)
throw new ConfigurationErrorsException(System.SR.Config_location_path_invalid_character, errorInfo);
return subPath;
}
protected SectionRecord GetSectionRecord(string configKey, bool permitErrors)
{
SectionRecord sectionRecord = (_sectionRecords == null) ? null : ((SectionRecord)_sectionRecords[configKey]);
if (sectionRecord != null && !permitErrors)
sectionRecord.ThrowOnErrors();
return sectionRecord;
}
protected SectionRecord EnsureSectionRecord(string configKey, bool permitErrors)
{
return EnsureSectionRecordImpl(configKey, permitErrors, true);
}
protected SectionRecord EnsureSectionRecordUnsafe(string configKey, bool permitErrors)
{
return EnsureSectionRecordImpl(configKey, permitErrors, false);
}
private SectionRecord EnsureSectionRecordImpl(string configKey, bool permitErrors, bool setLockSettings)
{
SectionRecord sectionRecord = GetSectionRecord(configKey, permitErrors);
if (sectionRecord != null)
return sectionRecord;
lock (this) {
if (_sectionRecords == null)
_sectionRecords = new Hashtable();
else
sectionRecord = GetSectionRecord(configKey, permitErrors);
if (sectionRecord == null) {
sectionRecord = new SectionRecord(configKey);
_sectionRecords.Add(configKey, sectionRecord);
}
}
if (setLockSettings) {
OverrideMode childLockMode;
OverrideMode forSelf = ResolveOverrideModeFromParent(configKey, out childLockMode);
sectionRecord.ChangeLockSettings(forSelf, childLockMode);
}
return sectionRecord;
}
internal FactoryRecord GetFactoryRecord(string configKey, bool permitErrors)
{
if (_factoryRecords == null)
return null;
FactoryRecord factoryRecord = (FactoryRecord)_factoryRecords[configKey];
if (factoryRecord != null && !permitErrors)
factoryRecord.ThrowOnErrors();
return factoryRecord;
}
protected Hashtable EnsureFactories()
{
return _factoryRecords ?? (_factoryRecords = new Hashtable());
}
private ArrayList EnsureLocationSections()
{
return _locationSections ?? (_locationSections = new ArrayList());
}
internal static string NormalizeConfigSource(string configSource, IConfigErrorInfo errorInfo)
{
if (string.IsNullOrEmpty(configSource))
throw new ConfigurationErrorsException(System.SR.Config_source_invalid_format, errorInfo);
string text = configSource.Trim();
if (text.Length != configSource.Length)
throw new ConfigurationErrorsException(System.SR.Config_source_invalid_format, errorInfo);
if (string.IsNullOrEmpty(configSource) || Path.IsPathRooted(configSource))
throw new ConfigurationErrorsException(System.SR.Config_source_invalid_format, errorInfo);
if (configSource.IndexOf('\\') != -1 || configSource.IndexOf('/') != -1) {
string configPath = configSource.Replace('\\', '/');
if (!ConfigPathUtility.IsValid(configPath))
throw new ConfigurationErrorsException(System.SR.Config_source_invalid_format, errorInfo);
}
return configSource;
}
protected object MonitorStream(string configKey, string configSource, string streamname)
{
lock (this) {
if (_flags[2])
return null;
StreamInfo streamInfo = (StreamInfo)ConfigStreamInfo.StreamInfos[streamname];
if (streamInfo != null) {
if (streamInfo.SectionName != configKey)
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_source_cannot_be_shared, streamname));
if (streamInfo.IsMonitored)
return streamInfo.Version;
} else {
streamInfo = new StreamInfo(configKey, configSource, streamname);
ConfigStreamInfo.StreamInfos.Add(streamname, streamInfo);
}
}
object streamVersion = Host.GetStreamVersion(streamname);
StreamChangeCallback callback = null;
lock (this) {
if (_flags[2])
return null;
StreamInfo streamInfo2 = (StreamInfo)ConfigStreamInfo.StreamInfos[streamname];
if (streamInfo2.IsMonitored)
return streamInfo2.Version;
streamInfo2.IsMonitored = true;
streamInfo2.Version = streamVersion;
if (_flags[65536]) {
ConfigRecordStreamInfo configStreamInfo = ConfigStreamInfo;
object streamChangeCallback = configStreamInfo.CallbackDelegate;
if (streamChangeCallback == null) {
StreamChangeCallback streamChangeCallback3 = configStreamInfo.CallbackDelegate = OnStreamChanged;
streamChangeCallback = streamChangeCallback3;
}
callback = (StreamChangeCallback)streamChangeCallback;
}
}
if (_flags[65536])
Host.StartMonitoringStreamForChanges(streamname, callback);
return streamVersion;
}
private void OnStreamChanged(string streamname)
{
string sectionName = default(string);
lock (this) {
if (_flags[2])
return;
StreamInfo streamInfo = (StreamInfo)ConfigStreamInfo.StreamInfos[streamname];
if (streamInfo == null || !streamInfo.IsMonitored)
return;
sectionName = streamInfo.SectionName;
}
bool flag;
if (sectionName == null)
flag = true;
else {
FactoryRecord factoryRecord = FindFactoryRecord(sectionName, false);
flag = factoryRecord.RestartOnExternalChanges;
}
if (flag)
_configRoot.FireConfigChanged(_configPath);
else
_configRoot.ClearResult(this, sectionName, false);
}
private void ValidateUniqueConfigSource(string configKey, string configSourceStreamName, string configSourceArg, IConfigErrorInfo errorInfo)
{
lock (this) {
if (ConfigStreamInfo.HasStreamInfos) {
StreamInfo streamInfo = (StreamInfo)ConfigStreamInfo.StreamInfos[configSourceStreamName];
if (streamInfo != null && streamInfo.SectionName != configKey)
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_source_cannot_be_shared, configSourceArg), errorInfo);
}
}
ValidateUniqueChildConfigSource(configSourceStreamName, configSourceArg, errorInfo);
}
protected void ValidateUniqueChildConfigSource(string configSourceStreamName, string configSourceArg, IConfigErrorInfo errorInfo)
{
BaseConfigurationRecord baseConfigurationRecord = IsLocationConfig ? _parent._parent : _parent;
while (!baseConfigurationRecord.IsRootConfig) {
lock (baseConfigurationRecord) {
if (baseConfigurationRecord.ConfigStreamInfo.HasStreamInfos) {
StreamInfo streamInfo = (StreamInfo)baseConfigurationRecord.ConfigStreamInfo.StreamInfos[configSourceStreamName];
if (streamInfo != null)
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Config_source_parent_conflict, configSourceArg), errorInfo);
}
}
baseConfigurationRecord = baseConfigurationRecord.Parent;
}
}
internal void HlClearResultRecursive(string configKey, bool forceEvaluatation)
{
RefreshFactoryRecord(configKey);
SectionRecord sectionRecord = GetSectionRecord(configKey, false);
if (sectionRecord != null) {
sectionRecord.ClearResult();
sectionRecord.ClearRawXml();
}
if (forceEvaluatation && !IsInitDelayed && !string.IsNullOrEmpty(ConfigStreamInfo.StreamName)) {
if (_flags[262144])
throw ExceptionUtil.UnexpectedError("BaseConfigurationRecord::hlClearResultRecursive");
FactoryRecord factoryRecord = FindFactoryRecord(configKey, false);
if (factoryRecord != null && !factoryRecord.IsGroup) {
configKey = factoryRecord.ConfigKey;
sectionRecord = EnsureSectionRecord(configKey, false);
if (!sectionRecord.HasFileInput) {
SectionXmlInfo sectionXmlInfo = new SectionXmlInfo(configKey, _configPath, _configPath, null, ConfigStreamInfo.StreamName, 0, null, null, null, null, null, OverrideModeSetting.s_locationDefault, false);
SectionInput sectionInput = new SectionInput(sectionXmlInfo, null);
sectionRecord.AddFileInput(sectionInput);
}
}
}
if (_children != null) {
IEnumerable values = _children.Values;
foreach (BaseConfigurationRecord item in values) {
item.HlClearResultRecursive(configKey, forceEvaluatation);
}
}
}
internal BaseConfigurationRecord HlGetChild(string configName)
{
return (BaseConfigurationRecord)(_children?[configName]);
}
internal void HlAddChild(string configName, BaseConfigurationRecord child)
{
if (_children == null)
_children = new Hashtable(StringComparer.OrdinalIgnoreCase);
_children.Add(configName, child);
}
internal void HlRemoveChild(string configName)
{
_children?.Remove(configName);
}
internal bool HlNeedsChildFor(string configName)
{
if (IsRootConfig)
return true;
if (HasInitErrors)
return false;
string text = ConfigPathUtility.Combine(_configPath, configName);
if (Host.IsConfigRecordRequired(text))
return true;
if (!_flags[1048576])
return false;
BaseConfigurationRecord baseConfigurationRecord = this;
while (!baseConfigurationRecord.IsRootConfig) {
if (baseConfigurationRecord._locationSections != null) {
baseConfigurationRecord.ResolveLocationSections();
foreach (LocationSectionRecord locationSection in baseConfigurationRecord._locationSections) {
if (UrlPath.IsEqualOrSubpath(text, locationSection.SectionXmlInfo.TargetConfigPath))
return true;
}
}
baseConfigurationRecord = baseConfigurationRecord._parent;
}
return false;
}
internal void CloseRecursive()
{
if (!_flags[2]) {
bool flag = false;
HybridDictionary hybridDictionary = null;
StreamChangeCallback callback = null;
lock (this) {
if (!_flags[2]) {
_flags[2] = true;
flag = true;
if (!IsLocationConfig && ConfigStreamInfo.HasStreamInfos) {
callback = ConfigStreamInfo.CallbackDelegate;
hybridDictionary = ConfigStreamInfo.StreamInfos;
ConfigStreamInfo.CallbackDelegate = null;
ConfigStreamInfo.ClearStreamInfos();
}
}
}
if (flag) {
if (_children != null) {
foreach (BaseConfigurationRecord value in _children.Values) {
value.CloseRecursive();
}
}
if (hybridDictionary != null) {
foreach (StreamInfo value2 in hybridDictionary.Values) {
if (value2.IsMonitored) {
Host.StopMonitoringStreamForChanges(value2.StreamName, callback);
value2.IsMonitored = false;
}
}
}
}
}
}
internal string FindChangedConfigurationStream()
{
BaseConfigurationRecord baseConfigurationRecord = this;
while (!baseConfigurationRecord.IsRootConfig) {
lock (baseConfigurationRecord) {
if (baseConfigurationRecord.ConfigStreamInfo.HasStreamInfos) {
foreach (StreamInfo value in baseConfigurationRecord.ConfigStreamInfo.StreamInfos.Values) {
if (value.IsMonitored && HasStreamChanged(value.StreamName, value.Version))
return value.StreamName;
}
}
}
baseConfigurationRecord = baseConfigurationRecord._parent;
}
return null;
}
private bool HasStreamChanged(string streamname, object lastVersion)
{
object streamVersion = Host.GetStreamVersion(streamname);
if (lastVersion != null) {
if (streamVersion != null)
return !lastVersion.Equals(streamVersion);
return true;
}
return streamVersion != null;
}
protected virtual string CallHostDecryptSection(string encryptedXml, ProtectedConfigurationProvider protectionProvider, ProtectedConfigurationSection protectedConfig)
{
return Host.DecryptSection(encryptedXml, protectionProvider, protectedConfig);
}
internal static string ValidateProtectionProviderAttribute(string protectionProvider, IConfigErrorInfo errorInfo)
{
if (string.IsNullOrEmpty(protectionProvider))
throw new ConfigurationErrorsException(System.SR.Protection_provider_invalid_format, errorInfo);
return protectionProvider;
}
private ConfigXmlReader DecryptConfigSection(ConfigXmlReader reader, ProtectedConfigurationProvider protectionProvider)
{
ConfigXmlReader configXmlReader = reader.Clone();
IConfigErrorInfo configErrorInfo = configXmlReader;
configXmlReader.Read();
string filename = configErrorInfo.Filename;
int lineNumber = configErrorInfo.LineNumber;
int lineOffset = lineNumber;
if (!configXmlReader.IsEmptyElement) {
while (true) {
configXmlReader.Read();
XmlNodeType nodeType = configXmlReader.NodeType;
if (nodeType == XmlNodeType.Element && configXmlReader.Name == "EncryptedData")
break;
switch (nodeType) {
case XmlNodeType.Comment:
case XmlNodeType.Whitespace:
break;
case XmlNodeType.EndElement:
throw new ConfigurationErrorsException(System.SR.EncryptedNode_not_found, filename, lineNumber);
default:
throw new ConfigurationErrorsException(System.SR.EncryptedNode_is_in_invalid_format, filename, lineNumber);
}
}
lineNumber = configErrorInfo.LineNumber;
string encryptedXml = configXmlReader.ReadOuterXml();
string rawXml;
try {
rawXml = CallHostDecryptSection(encryptedXml, protectionProvider, ProtectedConfig);
} catch (Exception ex) {
throw new ConfigurationErrorsException(System.SR.Format(System.SR.Decryption_failed, protectionProvider.Name, ex.Message), ex, filename, lineNumber);
}
while (true) {
switch (configXmlReader.NodeType) {
default:
throw new ConfigurationErrorsException(System.SR.EncryptedNode_is_in_invalid_format, filename, lineNumber);
case XmlNodeType.Comment:
case XmlNodeType.Whitespace:
if (configXmlReader.Read())
break;
goto case XmlNodeType.EndElement;
case XmlNodeType.EndElement:
return new ConfigXmlReader(rawXml, filename, lineOffset, true);
}
}
}
throw new ConfigurationErrorsException(System.SR.EncryptedNode_not_found, filename, lineNumber);
}
private void ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
{
schemaErrors.ThrowIfErrors(ClassFlags[64]);
}
internal static bool IsImplicitSection(string configKey)
{
return string.Equals(configKey, "configProtectedData", StringComparison.Ordinal);
}
private void AddImplicitSections(Hashtable factoryList)
{
if (_parent.IsRootConfig) {
if (factoryList == null)
factoryList = EnsureFactories();
FactoryRecord factoryRecord = (FactoryRecord)factoryList["configProtectedData"];
if (factoryRecord == null)
factoryList["configProtectedData"] = new FactoryRecord("configProtectedData", string.Empty, "configProtectedData", "System.Configuration.ProtectedConfigurationSection, System.Configuration.ConfigurationManager", true, ConfigurationAllowDefinition.Everywhere, ConfigurationAllowExeDefinition.MachineToApplication, OverrideModeSetting.s_sectionDefault, true, true, true, true, null, -1);
}
}
internal static bool IsReservedAttributeName(string name)
{
if (!StringUtil.StartsWithOrdinal(name, "config"))
return StringUtil.StartsWithOrdinal(name, "lock");
return true;
}
}
}