Files
Dec2017-Script-Dump/mscorlib/System/Runtime/Remoting/ConfigHandler.cs
T
2026-06-04 11:42:34 +02:00

607 lines
17 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Lifetime;
using Mono.Xml;
namespace System.Runtime.Remoting
{
// Token: 0x02000446 RID: 1094
internal class ConfigHandler : SmallXmlParser.IContentHandler
{
// Token: 0x06002A27 RID: 10791 RVA: 0x000878D4 File Offset: 0x00085AD4
public ConfigHandler(bool onlyDelayedChannels)
{
this.onlyDelayedChannels = onlyDelayedChannels;
}
// Token: 0x06002A28 RID: 10792 RVA: 0x00087910 File Offset: 0x00085B10
private void ValidatePath(string element, params string[] paths)
{
foreach (string text in paths)
{
if (this.CheckPath(text))
{
return;
}
}
throw new RemotingException("Element " + element + " not allowed in this context");
}
// Token: 0x06002A29 RID: 10793 RVA: 0x0008795C File Offset: 0x00085B5C
private bool CheckPath(string path)
{
CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
if (compareInfo.IsPrefix(path, "/", CompareOptions.Ordinal))
{
return path == this.currentXmlPath;
}
return compareInfo.IsSuffix(this.currentXmlPath, path, CompareOptions.Ordinal);
}
// Token: 0x06002A2A RID: 10794 RVA: 0x000879AC File Offset: 0x00085BAC
public void OnStartParsing(SmallXmlParser parser)
{
}
// Token: 0x06002A2B RID: 10795 RVA: 0x000879B0 File Offset: 0x00085BB0
public void OnProcessingInstruction(string name, string text)
{
}
// Token: 0x06002A2C RID: 10796 RVA: 0x000879B4 File Offset: 0x00085BB4
public void OnIgnorableWhitespace(string s)
{
}
// Token: 0x06002A2D RID: 10797 RVA: 0x000879B8 File Offset: 0x00085BB8
public void OnStartElement(string name, SmallXmlParser.IAttrList attrs)
{
try
{
if (this.currentXmlPath.StartsWith("/configuration/system.runtime.remoting"))
{
this.ParseElement(name, attrs);
}
this.currentXmlPath = this.currentXmlPath + "/" + name;
}
catch (Exception ex)
{
throw new RemotingException("Error in element " + name + ": " + ex.Message, ex);
}
}
// Token: 0x06002A2E RID: 10798 RVA: 0x00087A40 File Offset: 0x00085C40
public void ParseElement(string name, SmallXmlParser.IAttrList attrs)
{
if (this.currentProviderData != null)
{
this.ReadCustomProviderData(name, attrs);
return;
}
if (name != null)
{
if (ConfigHandler.<>f__switch$map27 == null)
{
ConfigHandler.<>f__switch$map27 = new Dictionary<string, int>(19)
{
{ "application", 0 },
{ "lifetime", 1 },
{ "channels", 2 },
{ "channel", 3 },
{ "serverProviders", 4 },
{ "clientProviders", 5 },
{ "provider", 6 },
{ "formatter", 6 },
{ "client", 7 },
{ "service", 8 },
{ "wellknown", 9 },
{ "activated", 10 },
{ "soapInterop", 11 },
{ "interopXmlType", 12 },
{ "interopXmlElement", 13 },
{ "preLoad", 14 },
{ "debug", 15 },
{ "channelSinkProviders", 16 },
{ "customErrors", 17 }
};
}
int num;
if (ConfigHandler.<>f__switch$map27.TryGetValue(name, out num))
{
switch (num)
{
case 0:
this.ValidatePath(name, new string[] { "system.runtime.remoting" });
if (attrs.Names.Length > 0)
{
this.appName = attrs.Values[0];
}
break;
case 1:
this.ValidatePath(name, new string[] { "application" });
this.ReadLifetine(attrs);
break;
case 2:
this.ValidatePath(name, new string[] { "system.runtime.remoting", "application" });
break;
case 3:
this.ValidatePath(name, new string[] { "channels" });
if (this.currentXmlPath.IndexOf("application") != -1)
{
this.ReadChannel(attrs, false);
}
else
{
this.ReadChannel(attrs, true);
}
break;
case 4:
this.ValidatePath(name, new string[] { "channelSinkProviders", "channel" });
break;
case 5:
this.ValidatePath(name, new string[] { "channelSinkProviders", "channel" });
break;
case 6:
if (this.CheckPath("application/channels/channel/serverProviders") || this.CheckPath("channels/channel/serverProviders"))
{
ProviderData providerData = this.ReadProvider(name, attrs, false);
this.currentChannel.ServerProviders.Add(providerData);
}
else if (this.CheckPath("application/channels/channel/clientProviders") || this.CheckPath("channels/channel/clientProviders"))
{
ProviderData providerData = this.ReadProvider(name, attrs, false);
this.currentChannel.ClientProviders.Add(providerData);
}
else if (this.CheckPath("channelSinkProviders/serverProviders"))
{
ProviderData providerData = this.ReadProvider(name, attrs, true);
RemotingConfiguration.RegisterServerProviderTemplate(providerData);
}
else if (this.CheckPath("channelSinkProviders/clientProviders"))
{
ProviderData providerData = this.ReadProvider(name, attrs, true);
RemotingConfiguration.RegisterClientProviderTemplate(providerData);
}
else
{
this.ValidatePath(name, new string[0]);
}
break;
case 7:
this.ValidatePath(name, new string[] { "application" });
this.currentClientUrl = attrs.GetValue("url");
break;
case 8:
this.ValidatePath(name, new string[] { "application" });
break;
case 9:
this.ValidatePath(name, new string[] { "client", "service" });
if (this.CheckPath("client"))
{
this.ReadClientWellKnown(attrs);
}
else
{
this.ReadServiceWellKnown(attrs);
}
break;
case 10:
this.ValidatePath(name, new string[] { "client", "service" });
if (this.CheckPath("client"))
{
this.ReadClientActivated(attrs);
}
else
{
this.ReadServiceActivated(attrs);
}
break;
case 11:
this.ValidatePath(name, new string[] { "application" });
break;
case 12:
this.ValidatePath(name, new string[] { "soapInterop" });
this.ReadInteropXml(attrs, false);
break;
case 13:
this.ValidatePath(name, new string[] { "soapInterop" });
this.ReadInteropXml(attrs, false);
break;
case 14:
this.ValidatePath(name, new string[] { "soapInterop" });
this.ReadPreload(attrs);
break;
case 15:
this.ValidatePath(name, new string[] { "system.runtime.remoting" });
break;
case 16:
this.ValidatePath(name, new string[] { "system.runtime.remoting" });
break;
case 17:
this.ValidatePath(name, new string[] { "system.runtime.remoting" });
RemotingConfiguration.SetCustomErrorsMode(attrs.GetValue("mode"));
break;
default:
goto IL_512;
}
return;
}
}
IL_512:
throw new RemotingException("Element '" + name + "' is not valid in system.remoting.configuration section");
}
// Token: 0x06002A2F RID: 10799 RVA: 0x00087F78 File Offset: 0x00086178
public void OnEndElement(string name)
{
if (this.currentProviderData != null)
{
this.currentProviderData.Pop();
if (this.currentProviderData.Count == 0)
{
this.currentProviderData = null;
}
}
this.currentXmlPath = this.currentXmlPath.Substring(0, this.currentXmlPath.Length - name.Length - 1);
}
// Token: 0x06002A30 RID: 10800 RVA: 0x00087FDC File Offset: 0x000861DC
private void ReadCustomProviderData(string name, SmallXmlParser.IAttrList attrs)
{
SinkProviderData sinkProviderData = (SinkProviderData)this.currentProviderData.Peek();
SinkProviderData sinkProviderData2 = new SinkProviderData(name);
for (int i = 0; i < attrs.Names.Length; i++)
{
sinkProviderData2.Properties[attrs.Names[i]] = attrs.GetValue(i);
}
sinkProviderData.Children.Add(sinkProviderData2);
this.currentProviderData.Push(sinkProviderData2);
}
// Token: 0x06002A31 RID: 10801 RVA: 0x00088050 File Offset: 0x00086250
private void ReadLifetine(SmallXmlParser.IAttrList attrs)
{
int i = 0;
while (i < attrs.Names.Length)
{
string text = attrs.Names[i];
if (text != null)
{
if (ConfigHandler.<>f__switch$map28 == null)
{
ConfigHandler.<>f__switch$map28 = new Dictionary<string, int>(4)
{
{ "leaseTime", 0 },
{ "sponsorshipTimeout", 1 },
{ "renewOnCallTime", 2 },
{ "leaseManagerPollTime", 3 }
};
}
int num;
if (ConfigHandler.<>f__switch$map28.TryGetValue(text, out num))
{
switch (num)
{
case 0:
LifetimeServices.LeaseTime = this.ParseTime(attrs.GetValue(i));
break;
case 1:
LifetimeServices.SponsorshipTimeout = this.ParseTime(attrs.GetValue(i));
break;
case 2:
LifetimeServices.RenewOnCallTime = this.ParseTime(attrs.GetValue(i));
break;
case 3:
LifetimeServices.LeaseManagerPollTime = this.ParseTime(attrs.GetValue(i));
break;
default:
goto IL_E6;
}
i++;
continue;
}
}
IL_E6:
throw new RemotingException("Invalid attribute: " + attrs.Names[i]);
}
}
// Token: 0x06002A32 RID: 10802 RVA: 0x00088170 File Offset: 0x00086370
private TimeSpan ParseTime(string s)
{
if (s == string.Empty || s == null)
{
throw new RemotingException("Invalid time value");
}
int num = s.IndexOfAny(new char[] { 'D', 'H', 'M', 'S' });
string text;
if (num == -1)
{
text = "S";
}
else
{
text = s.Substring(num);
s = s.Substring(0, num);
}
double num2;
try
{
num2 = double.Parse(s);
}
catch
{
throw new RemotingException("Invalid time value: " + s);
}
if (text == "D")
{
return TimeSpan.FromDays(num2);
}
if (text == "H")
{
return TimeSpan.FromHours(num2);
}
if (text == "M")
{
return TimeSpan.FromMinutes(num2);
}
if (text == "S")
{
return TimeSpan.FromSeconds(num2);
}
if (text == "MS")
{
return TimeSpan.FromMilliseconds(num2);
}
throw new RemotingException("Invalid time unit: " + text);
}
// Token: 0x06002A33 RID: 10803 RVA: 0x0008829C File Offset: 0x0008649C
private void ReadChannel(SmallXmlParser.IAttrList attrs, bool isTemplate)
{
ChannelData channelData = new ChannelData();
for (int i = 0; i < attrs.Names.Length; i++)
{
string text = attrs.Names[i];
string text2 = attrs.Values[i];
if (text == "ref" && !isTemplate)
{
channelData.Ref = text2;
}
else if (text == "delayLoadAsClientChannel")
{
channelData.DelayLoadAsClientChannel = text2;
}
else if (text == "id" && isTemplate)
{
channelData.Id = text2;
}
else if (text == "type")
{
channelData.Type = text2;
}
else
{
channelData.CustomProperties.Add(text, text2);
}
}
if (isTemplate)
{
if (channelData.Id == null)
{
throw new RemotingException("id attribute is required");
}
if (channelData.Type == null)
{
throw new RemotingException("id attribute is required");
}
RemotingConfiguration.RegisterChannelTemplate(channelData);
}
else
{
this.channelInstances.Add(channelData);
}
this.currentChannel = channelData;
}
// Token: 0x06002A34 RID: 10804 RVA: 0x000883B4 File Offset: 0x000865B4
private ProviderData ReadProvider(string name, SmallXmlParser.IAttrList attrs, bool isTemplate)
{
ProviderData providerData = ((!(name == "provider")) ? new FormatterData() : new ProviderData());
SinkProviderData sinkProviderData = new SinkProviderData("root");
providerData.CustomData = sinkProviderData.Children;
this.currentProviderData = new Stack();
this.currentProviderData.Push(sinkProviderData);
for (int i = 0; i < attrs.Names.Length; i++)
{
string text = attrs.Names[i];
string text2 = attrs.Values[i];
if (text == "id" && isTemplate)
{
providerData.Id = text2;
}
else if (text == "type")
{
providerData.Type = text2;
}
else if (text == "ref" && !isTemplate)
{
providerData.Ref = text2;
}
else
{
providerData.CustomProperties.Add(text, text2);
}
}
if (providerData.Id == null && isTemplate)
{
throw new RemotingException("id attribute is required");
}
return providerData;
}
// Token: 0x06002A35 RID: 10805 RVA: 0x000884CC File Offset: 0x000866CC
private void ReadClientActivated(SmallXmlParser.IAttrList attrs)
{
string notNull = this.GetNotNull(attrs, "type");
string text = this.ExtractAssembly(ref notNull);
if (this.currentClientUrl == null || this.currentClientUrl == string.Empty)
{
throw new RemotingException("url attribute is required in client element when it contains activated entries");
}
this.typeEntries.Add(new ActivatedClientTypeEntry(notNull, text, this.currentClientUrl));
}
// Token: 0x06002A36 RID: 10806 RVA: 0x00088534 File Offset: 0x00086734
private void ReadServiceActivated(SmallXmlParser.IAttrList attrs)
{
string notNull = this.GetNotNull(attrs, "type");
string text = this.ExtractAssembly(ref notNull);
this.typeEntries.Add(new ActivatedServiceTypeEntry(notNull, text));
}
// Token: 0x06002A37 RID: 10807 RVA: 0x0008856C File Offset: 0x0008676C
private void ReadClientWellKnown(SmallXmlParser.IAttrList attrs)
{
string notNull = this.GetNotNull(attrs, "url");
string notNull2 = this.GetNotNull(attrs, "type");
string text = this.ExtractAssembly(ref notNull2);
this.typeEntries.Add(new WellKnownClientTypeEntry(notNull2, text, notNull));
}
// Token: 0x06002A38 RID: 10808 RVA: 0x000885B0 File Offset: 0x000867B0
private void ReadServiceWellKnown(SmallXmlParser.IAttrList attrs)
{
string notNull = this.GetNotNull(attrs, "objectUri");
string notNull2 = this.GetNotNull(attrs, "mode");
string notNull3 = this.GetNotNull(attrs, "type");
string text = this.ExtractAssembly(ref notNull3);
WellKnownObjectMode wellKnownObjectMode;
if (notNull2 == "SingleCall")
{
wellKnownObjectMode = WellKnownObjectMode.SingleCall;
}
else
{
if (!(notNull2 == "Singleton"))
{
throw new RemotingException("wellknown object mode '" + notNull2 + "' is invalid");
}
wellKnownObjectMode = WellKnownObjectMode.Singleton;
}
this.typeEntries.Add(new WellKnownServiceTypeEntry(notNull3, text, notNull, wellKnownObjectMode));
}
// Token: 0x06002A39 RID: 10809 RVA: 0x0008864C File Offset: 0x0008684C
private void ReadInteropXml(SmallXmlParser.IAttrList attrs, bool isElement)
{
Type type = Type.GetType(this.GetNotNull(attrs, "clr"));
string[] array = this.GetNotNull(attrs, "xml").Split(new char[] { ',' });
string text = array[0].Trim();
string text2 = ((array.Length <= 0) ? null : array[1].Trim());
if (isElement)
{
SoapServices.RegisterInteropXmlElement(text, text2, type);
}
else
{
SoapServices.RegisterInteropXmlType(text, text2, type);
}
}
// Token: 0x06002A3A RID: 10810 RVA: 0x000886C4 File Offset: 0x000868C4
private void ReadPreload(SmallXmlParser.IAttrList attrs)
{
string value = attrs.GetValue("type");
string value2 = attrs.GetValue("assembly");
if (value != null && value2 != null)
{
throw new RemotingException("Type and assembly attributes cannot be specified together");
}
if (value != null)
{
SoapServices.PreLoad(Type.GetType(value));
}
else
{
if (value2 == null)
{
throw new RemotingException("Either type or assembly attributes must be specified");
}
SoapServices.PreLoad(Assembly.Load(value2));
}
}
// Token: 0x06002A3B RID: 10811 RVA: 0x00088738 File Offset: 0x00086938
private string GetNotNull(SmallXmlParser.IAttrList attrs, string name)
{
string value = attrs.GetValue(name);
if (value == null || value == string.Empty)
{
throw new RemotingException(name + " attribute is required");
}
return value;
}
// Token: 0x06002A3C RID: 10812 RVA: 0x00088778 File Offset: 0x00086978
private string ExtractAssembly(ref string type)
{
int num = type.IndexOf(',');
if (num == -1)
{
return string.Empty;
}
string text = type.Substring(num + 1).Trim();
type = type.Substring(0, num).Trim();
return text;
}
// Token: 0x06002A3D RID: 10813 RVA: 0x000887C0 File Offset: 0x000869C0
public void OnChars(string ch)
{
}
// Token: 0x06002A3E RID: 10814 RVA: 0x000887C4 File Offset: 0x000869C4
public void OnEndParsing(SmallXmlParser parser)
{
RemotingConfiguration.RegisterChannels(this.channelInstances, this.onlyDelayedChannels);
if (this.appName != null)
{
RemotingConfiguration.ApplicationName = this.appName;
}
if (!this.onlyDelayedChannels)
{
RemotingConfiguration.RegisterTypes(this.typeEntries);
}
}
// Token: 0x0400102B RID: 4139
private ArrayList typeEntries = new ArrayList();
// Token: 0x0400102C RID: 4140
private ArrayList channelInstances = new ArrayList();
// Token: 0x0400102D RID: 4141
private ChannelData currentChannel;
// Token: 0x0400102E RID: 4142
private Stack currentProviderData;
// Token: 0x0400102F RID: 4143
private string currentClientUrl;
// Token: 0x04001030 RID: 4144
private string appName;
// Token: 0x04001031 RID: 4145
private string currentXmlPath = string.Empty;
// Token: 0x04001032 RID: 4146
private bool onlyDelayedChannels;
}
}