Ver código fonte

2002-10-08 Gonzalo Paniagua Javier <[email protected]>

	* list: Modified file.

	* System.Web/HttpApplication.cs: fixed type and handle factories when
	creating IHttpHandler for a request.

	* System.Web.Configuration/HttpHandlersSectionHandler.cs: made a
	couple of static methods be part of a class used in other handlers.
	* System.Web.Configuration/HttpModulesConfigurationHandler.cs: handler
	for modules.
	* System.Web.Configuration/ModuleItem.cs: added IsMatch method.
	* System.Web.Configuration/ModulesConfiguration.cs: made it similar to
	the handlers class: added Clear, Remove.

	* System.Web.Handlers/ChangeLog: New file.
	* System.Web.Handlers/TraceHandler.cs: stubbed out. This should generate
	the trace page when tracing is enabled.

	* System.Web.SessionState/SessionStateModule.cs: don't throw exception.
	Just for testing the configuration stuff until we implement this.

svn path=/trunk/mcs/; revision=8074
Gonzalo Paniagua Javier 23 anos atrás
pai
commit
18be21e855

+ 4 - 0
mcs/class/System.Web/ChangeLog

@@ -1,3 +1,7 @@
+2002-10-06  Gonzalo Paniagua Javier <[email protected]>
+
+	* list: added new file in System.Web.Handlers.
+
 2002-10-06  Gonzalo Paniagua Javier <[email protected]>
 
 	* list: added new files in System.Web.Configuration.

+ 8 - 0
mcs/class/System.Web/System.Web.Configuration/ChangeLog

@@ -1,3 +1,11 @@
+2002-10-08  Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpHandlersSectionHandler.cs: made a couple of static methods be
+	part of a class used in other handlers.
+	* HttpModulesConfigurationHandler.cs: handler for modules.
+	* ModuleItem.cs: added IsMatch method.
+	* ModulesConfiguration.cs: made it similar to the handlers class: added 	Clear, Remove.
+
 2002-10-08  Gonzalo Paniagua Javier <[email protected]>
 
 	* HttpHandlerTypeMapper.cs: removed.

+ 27 - 17
mcs/class/System.Web/System.Web.Configuration/HttpHandlersSectionHandler.cs

@@ -25,7 +25,7 @@ namespace System.Web.Configuration
 				mapper = new HandlerFactoryConfiguration ();
 			
 			if (section.Attributes != null && section.Attributes.Count != 0)
-				ThrowException ("Unrecognized attribute", section);
+				HandlersUtil.ThrowException ("Unrecognized attribute", section);
 
 			XmlNodeList httpHandlers = section.ChildNodes;
 			foreach (XmlNode child in httpHandlers) {
@@ -34,36 +34,34 @@ namespace System.Web.Configuration
 					continue;
 
 				if (ntype != XmlNodeType.Element)
-					ThrowException ("Only elements allowed", child);
+					HandlersUtil.ThrowException ("Only elements allowed", child);
 				
-				if (ntype != XmlNodeType.Element)
-					ThrowException ("Unexpected node type", child);
-
 				string name = child.Name;
 				if (name == "clear") {
 					if (child.Attributes.Count != 0)
-						ThrowException ("Unrecognized attribute", child);
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
 
 					mapper.Clear ();
 					continue;
 				}
 					
-				string verb = ExtractAttributeValue ("verb", child, false);
-				string path = ExtractAttributeValue ("path", child, false);
-				string validateStr = ExtractAttributeValue ("validate", child, true);
+				string verb = HandlersUtil.ExtractAttributeValue ("verb", child);
+				string path = HandlersUtil.ExtractAttributeValue ("path", child);
+				string validateStr = HandlersUtil.ExtractAttributeValue ("validate", child, true);
 				bool validate;
 				if (validateStr == null) {
 					validate = true;
 				} else {
 					validate = validateStr == "true";
 					if (!validate && validateStr != "false")
-						ThrowException ("Invalid value for validate attribute.", child);
+						HandlersUtil.ThrowException (
+								"Invalid value for validate attribute.", child);
 				}
 
 				if (name == "add") {
-					string type = ExtractAttributeValue ("type", child, false);
+					string type = HandlersUtil.ExtractAttributeValue ("type", child);
 					if (child.Attributes.Count != 0)
-						ThrowException ("Unrecognized attribute", child);
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
 
 					HandlerItem item = new HandlerItem (verb, path, type, validate);
 					mapper.Add (item);
@@ -72,20 +70,32 @@ namespace System.Web.Configuration
 
 				if (name == "remove") {
 					if (child.Attributes.Count != 0)
-						ThrowException ("Unrecognized attribute", child);
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
 
 					if (validate && mapper.Remove (verb, path) == null)
-						ThrowException ("There's no mapping to remove", child);
+						HandlersUtil.ThrowException ("There's no mapping to remove", child);
 					
 					continue;
 				}
-				ThrowException ("Unexpected element", child);
+				HandlersUtil.ThrowException ("Unexpected element", child);
 			}
 
 			return mapper;
 		}
+	}
+
+	internal class HandlersUtil
+	{
+		private HandlersUtil ()
+		{
+		}
 
-		static string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
+		static internal string ExtractAttributeValue (string attKey, XmlNode node)
+		{
+			return ExtractAttributeValue (attKey, node, false);
+		}
+			
+		static internal string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
 		{
 			XmlNode att = node.Attributes.RemoveNamedItem (attKey);
 			if (att == null) {
@@ -103,7 +113,7 @@ namespace System.Web.Configuration
 			return value;
 		}
 
-		static void ThrowException (string msg, XmlNode node)
+		static internal void ThrowException (string msg, XmlNode node)
 		{
 			if (node != null && node.Name != String.Empty)
 				msg = msg + " (node name: " + node.Name + ") ";

+ 80 - 0
mcs/class/System.Web/System.Web.Configuration/HttpModulesConfigurationHandler.cs

@@ -0,0 +1,80 @@
+//
+// System.Web.Configuration.HttpModulesConfigurationHandler
+//
+// Authors:
+//	Gonzalo Paniagua Javier ([email protected])
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+using System.Configuration;
+using System.Xml;
+using System.Web.Security;
+
+namespace System.Web.Configuration
+{
+	class HttpModulesConfigurationHandler : IConfigurationSectionHandler
+	{
+		public virtual object Create (object parent, object configContext, XmlNode section)
+		{
+			ModulesConfiguration mapper;
+			
+			if (parent is ModulesConfiguration)
+				mapper = new ModulesConfiguration ((ModulesConfiguration) parent);
+			else
+				mapper = new ModulesConfiguration ();
+			
+			if (section.Attributes != null && section.Attributes.Count != 0)
+				HandlersUtil.ThrowException ("Unrecognized attribute", section);
+
+			XmlNodeList httpModules = section.ChildNodes;
+
+			foreach (XmlNode child in httpModules) {
+				XmlNodeType ntype = child.NodeType;
+				if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
+					continue;
+
+				if (ntype != XmlNodeType.Element)
+					HandlersUtil.ThrowException ("Only elements allowed", child);
+
+				string name = child.Name;
+				if (name == "clear") {
+					if (child.Attributes.Count != 0)
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+					mapper.Clear ();
+					continue;
+				}
+
+				string nameAtt = HandlersUtil.ExtractAttributeValue ("name", child);
+				if (name == "add") {
+					string type = HandlersUtil.ExtractAttributeValue ("type", child);
+					if (child.Attributes.Count != 0)
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+					// FIXME: gotta remove this. Just here to make it work with my local config
+					if (type.StartsWith ("System.Web.Mobile"))
+						continue;
+
+					ModuleItem item = new ModuleItem (nameAtt, type);
+					mapper.Add (item);
+					continue;
+				}
+
+				if (name == "remove") {
+					if (child.Attributes.Count != 0)
+						HandlersUtil.ThrowException ("Unrecognized attribute", child);
+
+					if (mapper.Remove (nameAtt) == null)
+						HandlersUtil.ThrowException ("Module not loaded", child);
+					continue;
+				}
+
+				HandlersUtil.ThrowException ("Unrecognized element", child);
+			}
+
+			return mapper;
+		}
+	}
+}
+

+ 6 - 1
mcs/class/System.Web/System.Web.Configuration/ModuleItem.cs

@@ -16,7 +16,7 @@ namespace System.Web.Configuration {
 			_typeName = type;
 			_name = name;
 
-			_type = Type.GetType(type, true);
+			_type = Type.GetType (type, true);
 			if (!typeof(IHttpModule).IsAssignableFrom(_type))
 				throw new HttpException(HttpRuntime.FormatResourceString("type_not_module"));
 		}
@@ -31,6 +31,11 @@ namespace System.Web.Configuration {
 			}
 		}
 
+		public bool IsMatch (string name)
+		{
+			return (_type.Name == name || _type.FullName == name);
+		}
+
 		public string ModuleName {
 			get {
 				return _name;

+ 57 - 17
mcs/class/System.Web/System.Web.Configuration/ModulesConfiguration.cs

@@ -1,35 +1,75 @@
 // 
 // System.Web.Configuration.ModulesConfiguration
 //
-// Author:
-//   Patrik Torstensson ([email protected])
+// Authors:
+// 	Patrik Torstensson ([email protected])
+// 	Gonzalo Paniagua Javier ([email protected])
+//
+// (c) 2002 Ximian, Inc. (http://www.ximian.com)
 //
 using System;
 using System.Collections;
 
-namespace System.Web.Configuration {
-	[MonoTODO]
-	public class ModulesConfiguration {
-		static private ArrayList _items = new ArrayList();
+namespace System.Web.Configuration
+{
+	public class ModulesConfiguration
+	{
+		ArrayList modules;
 
-		static public void Add(string name, string type) {
-			ModuleItem item = new ModuleItem(name, type);
-			_items.Add(item);
+		public ModulesConfiguration () : this (null)
+		{
 		}
 
-		public ModulesConfiguration() {
+		public ModulesConfiguration (ModulesConfiguration parent)
+		{
+			if (parent != null)
+				modules = new ArrayList (parent.modules);
+			else
+				modules = new ArrayList ();
 		}
 
-		public HttpModuleCollection CreateCollection() {
-			HttpModuleCollection items = new HttpModuleCollection();
-			int pos = 0;
-			int count = _items.Count;
+		public void Add (ModuleItem item)
+		{
+			modules.Add (item);
+		}
 
-			for (pos = 0; pos != count; pos++) {
-				items.AddModule(((ModuleItem) _items[pos]).ModuleName, ((ModuleItem) _items[pos]).Create());
-			}
+		public ModuleItem Remove (string name)
+		{
+			int i = GetIndex (name);
+			if (i == -1)
+				return null;
+			
+			ModuleItem item = (ModuleItem) modules [i];
+			modules.RemoveAt (i);
+			return item;
+		}
+
+		public void Clear ()
+		{
+			modules.Clear ();
+		}
+
+		public HttpModuleCollection CreateCollection ()
+		{
+			HttpModuleCollection items = new HttpModuleCollection ();
+			foreach (ModuleItem item in modules)
+				items.AddModule (item.ModuleName, item.Create ());
 
 			return items;
 		}
+
+		int GetIndex (string name)
+		{
+			int end = modules.Count;
+
+			for (int i = 0; i < end; i++) {
+				ModuleItem item = (ModuleItem) modules [i];
+				if (item.IsMatch (name))
+					return i;
+			}
+
+			return -1;
+		}
 	}
 }
+

+ 6 - 0
mcs/class/System.Web/System.Web.Handlers/ChangeLog

@@ -0,0 +1,6 @@
+2002-10-08  Gonzalo Paniagua Javier <[email protected]>
+
+	* ChangeLog: New file.
+	* TraceHandler.cs: stubbed out. This should generate the trace page
+	when tracing is enabled.
+

+ 32 - 0
mcs/class/System.Web/System.Web.Handlers/TraceHandler.cs

@@ -0,0 +1,32 @@
+//
+// System.Web.Handlers.TraceHandler
+//
+// Authors:
+//	Gonzalo Paniagua Javier ([email protected])
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.Handlers
+{
+	public class TraceHandler : IHttpHandler
+	{
+		[MonoTODO]
+		void IHttpHandler.ProcessRequest (HttpContext context)
+		{
+			//TODO: This should generate the trace page.
+			throw new NotImplementedException ();
+		}
+
+		bool IHttpHandler.IsReusable
+		{
+			get {
+				return false;
+			}
+		}
+	}
+}
+

+ 5 - 0
mcs/class/System.Web/System.Web.SessionState/ChangeLog

@@ -1,3 +1,8 @@
+2002-10-08  Gonzalo Paniagua Javier <[email protected]>
+
+	* SessionStateModule.cs: don't throw exception.  Just for testing the
+	configuration stuff until we implement this.
+
 2002-08-18  Gonzalo Paniagua Javier <[email protected]>
 
 	* HttpSessionState.cs: IsAbandoned is internal.

+ 2 - 2
mcs/class/System.Web/System.Web.SessionState/SessionStateModule.cs

@@ -19,13 +19,13 @@ namespace System.Web.SessionState
 		[MonoTODO()]
 		public void Dispose ()
 		{
-			throw new NotImplementedException ();
+			//throw new NotImplementedException ();
 		}
 
 		[MonoTODO()]
 		public void Init (HttpApplication app)
 		{
-			throw new NotImplementedException ();
+			//throw new NotImplementedException ();
 		}
 
 		public event EventHandler Start;

+ 5 - 0
mcs/class/System.Web/System.Web/ChangeLog

@@ -1,3 +1,8 @@
+2002-10-08  Gonzalo Paniagua Javier <[email protected]>
+
+	* HttpApplication.cs: fixed type and handle factories when creating
+	IHttpHandler for a request.
+
 2002-10-08  Gonzalo Paniagua Javier <[email protected]>
 
 	* HttpApplication.cs: use handlers from configuration.

+ 11 - 2
mcs/class/System.Web/System.Web/HttpApplication.cs

@@ -689,7 +689,16 @@ namespace System.Web {
 			if (handler == null)
 				throw new HttpException ("Cannot get system.web/httpHandlers handler.");
 
-			return (IHttpHandler) handler.FindHandler (type, path).Create ();
+			object result = handler.FindHandler (type, path).Create ();
+			if (result is IHttpHandler)
+				return (IHttpHandler) result;
+
+			if (result is IHttpHandlerFactory) {
+				IHttpHandlerFactory factory = (IHttpHandlerFactory) result;
+				return factory.GetHandler (context, type, file, path);
+			}
+
+			return null;
 		}
 
 		[MonoTODO()]
@@ -700,7 +709,7 @@ namespace System.Web {
 		internal void InitModules() {
 			ModulesConfiguration modules;
 
-			modules = (ModulesConfiguration) HttpContext.GetAppConfig("system.web/httpmodules");
+			modules = (ModulesConfiguration) HttpContext.GetAppConfig("system.web/httpModules");
 			if (null == modules)
 				throw new HttpException(HttpRuntime.FormatResourceString("missing_modules_config"));
 

+ 2 - 0
mcs/class/System.Web/list

@@ -70,6 +70,7 @@ System.Web.Configuration/HandlerFactoryConfiguration.cs
 System.Web.Configuration/HandlerFactoryProxy.cs
 System.Web.Configuration/HttpConfigurationContext.cs
 System.Web.Configuration/HttpHandlersSectionHandler.cs
+System.Web.Configuration/HttpModulesConfigurationHandler.cs
 System.Web.Configuration/HandlerItem.cs
 System.Web.Configuration/ModulesConfiguration.cs
 System.Web.Configuration/ModuleItem.cs
@@ -352,3 +353,4 @@ System.Web.Compilation/AspTokenizer.cs
 System.Web.Compilation/PageCompiler.cs
 System.Web.Compilation/TemplateFactory.cs
 System.Web.Compilation/WebServiceCompiler.cs
+System.Web.Handlers/TraceHandler.cs