Exemple #1
0
        public void OnStartElement(string name, SmallXmlParser.IAttrList attrs)
        {
            SecurityElement newel = new SecurityElement(name);

            if (root == null)
            {
                root = newel;
                current = newel;

            }
            else
            {
                SecurityElement parent = (SecurityElement)stack.Peek();
                parent.AddChild(newel);
            }

            stack.Push(newel);
            current = newel;
            // attributes
            int n = attrs.Length;

            for (int i = 0; i < n; i++)
            {
                string attrName = SecurityElement.Escape(attrs.GetName(i));
                string attrValue = SecurityElement.Escape(attrs.GetValue(i));
                current.AddAttribute(attrName, attrValue);
            }
        }
Exemple #2
0
 public void OnStartElement (string name, SmallXmlParser.IAttrList attrs) {
     if (reading) {
         currentName = name;
     } else if (name == seeking) {
         currentAttributes = new Dictionary<string, string>();
         for (int t = 0; t < attrs.Length; t++) {
             currentAttributes[attrs.Names[t]] = attrs.Values[t];
         }
         currentKvps = new Dictionary<string, string>();
         reading = true;
     }
 }
 public void OnStartElement(string name, SmallXmlParser.IAttrList attrs)
 {
 }
Exemple #4
0
		public void OnStartElement (string name, SmallXmlParser.IAttrList attrs)
		{
			switch (level) {
			case 0:
				if (name == "configuration")
					level++;
				break;
			case 1:
				if (name == "mscorlib")
					level++;
				break;
			case 2:
				if (name == "cryptographySettings")
					level++;
				break;
			case 3:
				if (name == "oidMap")
					level++;
				else if (name == "cryptoNameMapping")
					level++;
				break;
			case 4:
				if (name == "oidEntry") {
					oid [Get (attrs, "name")] = Get (attrs, "OID");
				} else if (name == "nameEntry") {
					names [Get (attrs, "name")] = Get (attrs, "class");
				} else if (name == "cryptoClasses") {
					level++;
				}
				break;
			case 5:
				if (name == "cryptoClass")
					classnames [attrs.Names[0]] = attrs.Values[0];
				break;
			}
		}
Exemple #5
0
		public void OnEndParsing (SmallXmlParser parser)
		{
			foreach (var kpv in names) {
				try {
					algorithms [kpv.Key] = Type.GetType (classnames [kpv.Value]);
				}
				catch {
				}
			}
			// matching is done, data no more required
			names.Clear ();
			classnames.Clear ();
		}
Exemple #6
0
	private static void LoadConfig (string filename, IDictionary<string,Type> algorithms, IDictionary<string,string> oid)
	{
		if (!File.Exists (filename))
			return;

		try {
			using (TextReader reader = new StreamReader (filename)) {
				CryptoHandler handler = new CryptoHandler (algorithms, oid);
				SmallXmlParser parser = new SmallXmlParser ();
				parser.Parse (reader, handler);
			}
		}
		catch {
		}
	}
		string GetNotNull (SmallXmlParser.IAttrList attrs, string name)
		{
			string value = attrs.GetValue (name);
			if (value == null || value == "") 
				throw new RemotingException (name + " attribute is required");
			return value;
		}
		void ReadInteropXml (SmallXmlParser.IAttrList attrs, bool isElement)
		{
			Type t = Type.GetType (GetNotNull (attrs, "clr"));
			string[] xmlName = GetNotNull (attrs, "xml").Split (',');
			string localName = xmlName [0].Trim ();
			string ns = xmlName.Length > 0 ? xmlName[1].Trim() : null;
			
			if (isElement) SoapServices.RegisterInteropXmlElement (localName, ns, t);
			else SoapServices.RegisterInteropXmlType (localName, ns, t);
		}
		public void OnStartElement (string name, SmallXmlParser.IAttrList attrs)
		{
			try
			{
				if (currentXmlPath.StartsWith ("/configuration/system.runtime.remoting"))
					ParseElement (name, attrs);
					
				currentXmlPath += "/" + name;
			}
			catch (Exception ex)
			{
				throw new RemotingException ("Error in element " + name + ": " + ex.Message, ex);
			}
		}
		internal static void LoadDefaultDelayedChannels ()
		{
			lock (channelTemplates)
			{
				if (defaultDelayedConfigRead || defaultConfigRead) return;
				
				SmallXmlParser parser = new SmallXmlParser ();
				using (TextReader rreader = new StreamReader (Environment.GetMachineConfigPath ())) {
					ConfigHandler handler = new ConfigHandler (true);
					parser.Parse (rreader, handler);
				}
				defaultDelayedConfigRead = true;
			}
		}
		private static void ReadConfigFile (string filename)
		{
			try
			{
				SmallXmlParser parser = new SmallXmlParser ();
				using (TextReader rreader = new StreamReader (filename)) {
					ConfigHandler handler = new ConfigHandler (false);
					parser.Parse (rreader, handler);
				}
			}
			catch (Exception ex)
			{
				throw new RemotingException ("Configuration file '" + filename + "' could not be loaded: " + ex.Message, ex);
			}
		}
Exemple #12
0
		public void OnEndParsing (SmallXmlParser parser)
		{
			foreach (DictionaryEntry de in names) {
				try {
					algorithms.Add (de.Key, classnames[de.Value]);
				}
				catch {
				}
			}
			// matching is done, data no more required
			names.Clear ();
			classnames.Clear ();
		}
Exemple #13
0
 public void OnStartParsing(SmallXmlParser parser)
 {
 }
Exemple #14
0
 public void OnEndParsing(SmallXmlParser parser)
 {
 }
		void ReadClientWellKnown (SmallXmlParser.IAttrList attrs)
		{
			string url = GetNotNull (attrs, "url");
			string type = GetNotNull (attrs, "type");
			string assm = ExtractAssembly (ref type);
			
			typeEntries.Add (new WellKnownClientTypeEntry (type, assm, url));
		}
		public void ParseElement (string name, SmallXmlParser.IAttrList attrs)
		{
			if (currentProviderData != null)
			{
				ReadCustomProviderData (name, attrs);
				return;
			}
			
			switch (name) 
			{
				case "application":
					ValidatePath (name, "system.runtime.remoting");
					if (attrs.Names.Length > 0)
						appName = attrs.Values[0];
					break;
					
				case "lifetime":
					ValidatePath (name, "application");
					ReadLifetine (attrs);
					break;
					
				case "channels":
					ValidatePath (name, "system.runtime.remoting", "application");
					break;
					
				case "channel":
					ValidatePath (name, "channels");
					if (currentXmlPath.IndexOf ("application") != -1)
						ReadChannel (attrs, false);
					else
						ReadChannel (attrs, true);
					break;
					
				case "serverProviders":
					ValidatePath (name, "channelSinkProviders", "channel");
					break;
					
				case "clientProviders":
					ValidatePath (name, "channelSinkProviders", "channel");
					break;
					
				case "provider":
				case "formatter":
					ProviderData prov;
					
					if (CheckPath ("application/channels/channel/serverProviders") ||
						CheckPath ("channels/channel/serverProviders"))
					{
						prov = ReadProvider (name, attrs, false);
						currentChannel.ServerProviders.Add (prov);
					}
					else if (CheckPath ("application/channels/channel/clientProviders") ||
						CheckPath ("channels/channel/clientProviders"))
					{
						prov = ReadProvider (name, attrs, false);
						currentChannel.ClientProviders.Add (prov);
					}
					else if (CheckPath ("channelSinkProviders/serverProviders"))
					{
						prov = ReadProvider (name, attrs, true);
						RemotingConfiguration.RegisterServerProviderTemplate (prov);
					}
					else if (CheckPath ("channelSinkProviders/clientProviders"))
					{
						prov = ReadProvider (name, attrs, true);
						RemotingConfiguration.RegisterClientProviderTemplate (prov);
					}
					else 
						ValidatePath (name);
					break;
					
				case "client":
					ValidatePath (name, "application");
					currentClientUrl = attrs.GetValue ("url");
					break;
					
				case "service":
					ValidatePath (name, "application");
					break;
					
				case "wellknown":
					ValidatePath (name, "client", "service");
					if (CheckPath ("client"))
						ReadClientWellKnown (attrs);
					else
						ReadServiceWellKnown (attrs);
					break;
					
				case "activated":
					ValidatePath (name, "client", "service");
					if (CheckPath ("client"))
						ReadClientActivated (attrs);
					else
						ReadServiceActivated (attrs);
					break;
					
				case "soapInterop":
					ValidatePath (name, "application");
					break;
					
				case "interopXmlType":
					ValidatePath (name, "soapInterop");
					ReadInteropXml (attrs, false);
					break;
					
				case "interopXmlElement":
					ValidatePath (name, "soapInterop");
					ReadInteropXml (attrs, false);
					break;
					
				case "preLoad":
					ValidatePath (name, "soapInterop");
					ReadPreload (attrs);
					break;
					
				case "debug":
					ValidatePath (name, "system.runtime.remoting");
					break;
					
				case "channelSinkProviders":
					ValidatePath (name, "system.runtime.remoting");
					break;
					
				case "customErrors":
					ValidatePath (name, "system.runtime.remoting");
					RemotingConfiguration.SetCustomErrorsMode (attrs.GetValue ("mode"));
					break;
					
				default:
					throw new RemotingException ("Element '" + name + "' is not valid in system.remoting.configuration section");
			}
		}
		void ReadServiceWellKnown (SmallXmlParser.IAttrList attrs)
		{
			string objectUri = GetNotNull (attrs, "objectUri");
			string smode = GetNotNull (attrs, "mode");
			string type = GetNotNull (attrs, "type");
			string assm = ExtractAssembly (ref type);
			
			WellKnownObjectMode mode;
			if (smode == "SingleCall") mode = WellKnownObjectMode.SingleCall;
			else if (smode == "Singleton") mode = WellKnownObjectMode.Singleton;
			else throw new RemotingException ("wellknown object mode '" + smode + "' is invalid");
			
			typeEntries.Add (new WellKnownServiceTypeEntry (type, assm, objectUri, mode));
		}
		void ReadCustomProviderData (string name, SmallXmlParser.IAttrList attrs)
		{
			SinkProviderData parent = (SinkProviderData) currentProviderData.Peek ();
			
			SinkProviderData data = new SinkProviderData (name);
			for (int i=0; i < attrs.Names.Length; ++i) 
				data.Properties [attrs.Names[i]] = attrs.GetValue (i);
				
			parent.Children.Add (data);
			currentProviderData.Push (data);
		}
		void ReadPreload (SmallXmlParser.IAttrList attrs)
		{
			string type = attrs.GetValue ("type");
			string assm = attrs.GetValue ("assembly");
			
			if (type != null && assm != null)
				throw new RemotingException ("Type and assembly attributes cannot be specified together");
				
			if (type != null)
				SoapServices.PreLoad (Type.GetType (type));
			else if (assm != null)
				SoapServices.PreLoad (Assembly.Load (assm));
			else
				throw new RemotingException ("Either type or assembly attributes must be specified");
		}
		void ReadLifetine (SmallXmlParser.IAttrList attrs)
		{
			for (int i=0; i < attrs.Names.Length; ++i) {
				switch (attrs.Names[i]) {
				case "leaseTime":
					LifetimeServices.LeaseTime = ParseTime (attrs.GetValue(i));
					break;
				case "sponsorshipTimeout":
					LifetimeServices.SponsorshipTimeout = ParseTime (attrs.GetValue(i));
					break;
				case "renewOnCallTime":
					LifetimeServices.RenewOnCallTime = ParseTime (attrs.GetValue(i));
					break;
				case "leaseManagerPollTime":
					LifetimeServices.LeaseManagerPollTime = ParseTime (attrs.GetValue(i));
					break;
				default:
					throw new RemotingException ("Invalid attribute: " + attrs.Names[i]);
				}
			}
		}
		public void OnEndParsing (SmallXmlParser parser)
		{
			RemotingConfiguration.RegisterChannels (channelInstances, onlyDelayedChannels);
			if (appName != null) RemotingConfiguration.ApplicationName = appName;
			
			if (!onlyDelayedChannels)
				RemotingConfiguration.RegisterTypes (typeEntries);
		}
		void ReadChannel (SmallXmlParser.IAttrList attrs, bool isTemplate)
		{
			ChannelData channel = new ChannelData ();
			
			for (int i=0; i < attrs.Names.Length; ++i) 
			{
				string at = attrs.Names[i];
				string val = attrs.Values[i];
				
				if (at == "ref" && !isTemplate)
					channel.Ref = val;
				else if (at == "delayLoadAsClientChannel")
					channel.DelayLoadAsClientChannel = val;
				else if (at == "id" && isTemplate)
					channel.Id = val;
				else if (at == "type")
					channel.Type = val;
				else
					channel.CustomProperties.Add (at, val);
			}
			
			if (isTemplate)
			{
				if (channel.Id == null) throw new RemotingException ("id attribute is required");
				if (channel.Type == null) throw new RemotingException ("id attribute is required");
				RemotingConfiguration.RegisterChannelTemplate (channel);
			}
			else
				channelInstances.Add (channel);
				
			currentChannel = channel;
		}
Exemple #23
0
		public void OnStartParsing (SmallXmlParser parser)
		{
			// don't care
		}
		ProviderData ReadProvider (string name, SmallXmlParser.IAttrList attrs, bool isTemplate)
		{
			ProviderData prov = (name == "provider") ? new ProviderData () : new FormatterData ();
			SinkProviderData data = new SinkProviderData ("root");
			prov.CustomData = data.Children;
			
			currentProviderData = new Stack ();
			currentProviderData.Push (data);
			
			for (int i=0; i < attrs.Names.Length; ++i) 
			{
				string at = attrs.Names[i];
				string val = attrs.Values[i];
				
				if (at == "id" && isTemplate)
					prov.Id = val;
				else if (at == "type")
					prov.Type = val;
				else if (at == "ref" && !isTemplate)
					prov.Ref = val;
				else
					prov.CustomProperties.Add (at, val);
			}
			
			if (prov.Id == null && isTemplate) throw new RemotingException ("id attribute is required");
			return prov;
		}
Exemple #25
0
		private string Get (SmallXmlParser.IAttrList attrs, string name)
		{
			for (int i = 0; i < attrs.Names.Length; i++) {
				if (attrs.Names[i] == name)
					return attrs.Values[i];
			}
			return String.Empty;
		}
		void ReadClientActivated (SmallXmlParser.IAttrList attrs)
		{
			string type = GetNotNull (attrs, "type");
			string assm = ExtractAssembly (ref type);
			
			if (currentClientUrl == null || currentClientUrl == "") 
				throw new RemotingException ("url attribute is required in client element when it contains activated entries");

			typeEntries.Add (new ActivatedClientTypeEntry (type, assm, currentClientUrl));
		}
 public void OnEndParsing(SmallXmlParser parser)
 {
 }
		void ReadServiceActivated (SmallXmlParser.IAttrList attrs)
		{
			string type = GetNotNull (attrs, "type");
			string assm = ExtractAssembly (ref type);
			
			typeEntries.Add (new ActivatedServiceTypeEntry (type, assm));
		}
 public void OnStartParsing(SmallXmlParser parser)
 {
 }
Exemple #30
0
 public UnibillXmlParser (SmallXmlParser parser, IResourceLoader loader) {
     this.loader = loader;
     this.parser = parser;
 }