* System.Web/HttpApplication.cs: use handlers from configuration.
* System.Web/HttpContext.cs: get handlers from ConfigurationSettings.
* System.Web.Caching/Cache.cs: little fixes.
* System.Web.Configuration/HttpHandlerTypeMapper.cs: removed.
* System.Web.Configuration/HandlerFactoryConfiguration.cs: readded. I
removed it by mistake.
* System.Web.Configuration/HandlerItem.cs: only load the type if
we gotta validate it. Implemented initial IsMatch.
* System.Web.Configuration/HttpConfigurationContext.cs: New file.
* System.Web.Configuration/HttpHandlersSectionHandler.cs: validate is
optional (default true). Use HttpHandlerTypeMapper.
* System.Web.UI/SimpleHandlerFactory.cs: new handler for .ashx files.
svn path=/trunk/mcs/; revision=8053
/// <summary>\r
/// Virtual override of the IEnumerable.GetEnumerator() method, returns a specialized enumerator.\r
/// </summary>\r
- public virtual System.Collections.IDictionaryEnumerator GetEnumerator()\r
+ public System.Collections.IDictionaryEnumerator GetEnumerator()\r
{\r
return CreateEnumerator();\r
}\r
/// <summary>\r
/// Gets the number of items stored in the cache.\r
/// </summary>\r
- long Count\r
+ public long Count\r
{\r
get \r
{\r
+2002-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>\r
+\r
+ * Cache.cs: little fixes.\r
+\r
2002-07-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>\r
\r
* CacheDefinitions.cs: fixed a couple of enums.\r
+2002-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * HttpHandlerTypeMapper.cs: removed.
+ * HandlerFactoryConfiguration.cs: readded. I removed it by mistake.
+ * HandlerItem.cs: only load the type if we gotta validate it.
+ Implemented initial IsMatch.
+ * HttpConfigurationContext.cs: New file.
+ * HttpHandlersSectionHandler.cs: validate is optional (default true).
+ Use HttpHandlerTypeMapper.
+
2002-10-06 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* System.Web.Configuration/HandlerFactoryConfiguration.cs: removed.
--- /dev/null
+//
+// System.Web.Configuration.HandlerFactoryConfiguration
+//
+// Authors:
+// Patrik Torstensson (ptorsten@hotmail.com)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+using System.Collections;
+
+namespace System.Web.Configuration
+{
+ class HandlerFactoryConfiguration
+ {
+ ArrayList mappings;
+
+ public HandlerFactoryConfiguration () : this (null)
+ {
+ }
+
+ public HandlerFactoryConfiguration (HandlerFactoryConfiguration parent)
+ {
+ if (parent != null)
+ mappings = new ArrayList (parent.mappings);
+ else
+ mappings = new ArrayList ();
+ }
+
+ public void Add (HandlerItem mapping)
+ {
+ mappings.Add (mapping);
+ }
+
+ public HandlerItem Remove (string verb, string path)
+ {
+ int i = GetIndex (verb, path);
+ if (i == -1)
+ return null;
+
+ HandlerItem item = (HandlerItem) mappings [i];
+ mappings.RemoveAt (i);
+ return item;
+ }
+
+ public void Clear ()
+ {
+ mappings.Clear ();
+ }
+
+ public HandlerItem FindHandler (string verb, string path)
+ {
+ int i = GetIndex (verb, path);
+ if (i == -1)
+ return null;
+
+ return (HandlerItem) mappings [i];
+ }
+
+ int GetIndex (string verb, string path)
+ {
+ int end = mappings.Count;
+
+ for (int i = 0; i < end; i++) {
+ HandlerItem item = (HandlerItem) mappings [i];
+ if (item.IsMatch (verb, path))
+ return i;
+ }
+
+ return -1;
+ }
+ }
+}
+
//
// System.Web.Configuration.HandlerItem
//
-// Author:
-// Patrik Torstensson (ptorsten@hotmail.com)
+// Authors:
+// Patrik Torstensson (ptorsten@hotmail.com)
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (c) 2002 Ximian, Inc. (http://www.ximian.com)
//
using System;
+using System.Collections;
+using System.Text;
+using System.Text.RegularExpressions;
-namespace System.Web.Configuration {
- public class HandlerItem {
+namespace System.Web.Configuration
+{
+ public class HandlerItem
+ {
private Type _type;
private string _typeName;
private string _path;
private string _requestType;
- bool validate;
+ private Regex requestRegex;
+ private Regex pathRegex;
+ static Hashtable regexCache;
- public HandlerItem(string requestType, string path, string type, bool validate) {
+ public HandlerItem (string requestType, string path, string type, bool validate)
+ {
_typeName = type;
_path = path;
- _requestType = requestType.Replace(" ", "");
- this.validate = validate;
-
- _type = Type.GetType(type, true);
- if (!typeof(IHttpHandler).IsAssignableFrom(_type)) {
- if (!typeof(IHttpHandlerFactory).IsAssignableFrom(_type)) {
- throw new HttpException(HttpRuntime.FormatResourceString("type_not_factory_or_handler"));
- }
- }
+ _requestType = requestType.Replace (" ", "");
+ requestRegex = GetRegex (_requestType);
+ pathRegex = GetRegex (_path);
+ if (validate)
+ DoValidation ();
}
- public object Create() {
- return HttpRuntime.CreateInternalObject(_type);
+ public object Create ()
+ {
+ if (_type == null)
+ DoValidation ();
+
+ return HttpRuntime.CreateInternalObject (_type);
}
- public Type Type {
+ public Type Type
+ {
get {
+ if (_type == null)
+ DoValidation ();
return _type;
}
}
public bool IsMatch (string type, string path)
{
- return (MatchVerb (type) && MatchExtension (path));
+ return (MatchVerb (type) && MatchPath (path));
}
bool MatchVerb (string verb)
{
- //FIXME: implement me
- return true;
+ return requestRegex.IsMatch (verb);
+ }
+
+ bool MatchPath (string path)
+ {
+ return pathRegex.IsMatch (path);
}
- bool MatchExtension (string path)
+ void DoValidation ()
{
- //FIXME: implement me
- return true;
+ _type = Type.GetType (_typeName, true);
+ if (typeof (IHttpHandler).IsAssignableFrom (_type))
+ return;
+
+ if (typeof (IHttpHandlerFactory).IsAssignableFrom (_type))
+ return;
+
+ throw new HttpException (HttpRuntime.FormatResourceString ("type_not_factory_or_handler"));
+ }
+
+ static string ToRegexPattern (string dosPattern)
+ {
+ string result = dosPattern.Replace (".", "\\.");
+ result = result.Replace ("*", ".*");
+ result = result.Replace ('?', '.');
+ return result;
+ }
+
+ static Regex GetRegex (string verb)
+ {
+ EnsureCache ();
+ if (regexCache.ContainsKey (verb))
+ return (Regex) regexCache [verb];
+
+ StringBuilder result = new StringBuilder ("\\A");
+ string [] expressions = verb.Split (',');
+ int end = expressions.Length;
+ for (int i = 0; i < end; i++) {
+ string regex = ToRegexPattern (expressions [i]);
+ if (i + 1 < end) {
+ result.AppendFormat ("{0}\\z|\\A", regex);
+ } else {
+ result.AppendFormat ("({0})\\z", regex);
+ }
+ }
+
+ Regex r = new Regex (result.ToString ());
+ regexCache [verb] = r;
+ return r;
+ }
+
+ static void EnsureCache ()
+ {
+ if (regexCache == null)
+ regexCache = new Hashtable ();
}
}
}
+
--- /dev/null
+//
+// System.Web.Configuration.HttpConfigurationContext
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+namespace System.Web.Configuration
+{
+ public class HttpConfigurationContext
+ {
+ private string virtualPath;
+
+ internal HttpConfigurationContext (string virtualPath)
+ {
+ this.virtualPath = virtualPath;
+ }
+
+ public string VirtualPath
+ {
+ get {
+ return virtualPath;
+ }
+ }
+ }
+}
+
+++ /dev/null
-//
-// System.Web.Configuration.HttpHandlerTypeMapper
-//
-// Authors:
-// Gonzalo Paniagua Javier (gonzalo@ximian.com)
-//
-// (C) 2002 Ximian, Inc (http://www.ximian.com)
-//
-
-using System.Collections;
-
-namespace System.Web.Configuration
-{
- class HttpHandlerTypeMapper
- {
- ArrayList mappings;
-
- public HttpHandlerTypeMapper () : this (null)
- {
- }
-
- public HttpHandlerTypeMapper (HttpHandlerTypeMapper parent)
- {
- if (parent != null)
- mappings = new ArrayList (parent.mappings);
- else
- mappings = new ArrayList ();
- }
-
- public void Add (HandlerItem mapping)
- {
- mappings.Add (mapping);
- }
-
- public HandlerItem Remove (string verb, string path)
- {
- int i = SearchHandler (verb, path);
- if (i == -1)
- return null;
-
- HandlerItem item = (HandlerItem) mappings [i];
- mappings.RemoveAt (i);
- return item;
- }
-
- public void Clear ()
- {
- mappings.Clear ();
- }
-
- public HandlerItem FindHandler (string verb, string path)
- {
- int i = SearchHandler (verb, path);
- if (i == -1)
- return null;
-
- return (HandlerItem) mappings [i];
- }
-
- int SearchHandler (string verb, string path)
- {
- int end = mappings.Count;
-
- for (int i = 0; i < end; i++) {
- HandlerItem item = (HandlerItem) mappings [i];
- if (item.IsMatch (verb, path))
- return i;
- }
-
- return -1;
- }
-
- }
-}
-
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
+using System.Collections;
using System.Configuration;
using System.Xml;
{
public virtual object Create (object parent, object configContext, XmlNode section)
{
- HttpHandlerTypeMapper mapper;
+ HandlerFactoryConfiguration mapper;
- if (parent is HttpHandlerTypeMapper)
- mapper = new HttpHandlerTypeMapper ((HttpHandlerTypeMapper) parent);
+ if (parent is HandlerFactoryConfiguration)
+ mapper = new HandlerFactoryConfiguration ((HandlerFactoryConfiguration) parent);
else
- mapper = new HttpHandlerTypeMapper ();
+ mapper = new HandlerFactoryConfiguration ();
if (section.Attributes != null && section.Attributes.Count != 0)
- throw new ConfigurationException ("Unrecognized attribute", section);
+ ThrowException ("Unrecognized attribute", section);
- foreach (XmlNode child in section.ChildNodes) {
+ XmlNodeList httpHandlers = section.ChildNodes;
+ foreach (XmlNode child in httpHandlers) {
XmlNodeType ntype = child.NodeType;
if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
continue;
+
+ if (ntype != XmlNodeType.Element)
+ ThrowException ("Only elements allowed", child);
if (ntype != XmlNodeType.Element)
- throw new ConfigurationException ("Unexpected node type", child);
+ ThrowException ("Unexpected node type", child);
string name = child.Name;
if (name == "clear") {
if (child.Attributes.Count != 0)
- throw new ConfigurationException ("Unrecognized attribute", child);
+ ThrowException ("Unrecognized attribute", child);
mapper.Clear ();
continue;
}
- string verb = ExtractAttributeValue ("verb", child);
- string path = ExtractAttributeValue ("path", child);
- string validateStr = ExtractAttributeValue ("validate", child);
- bool validate = (validateStr == "true");
- if (!validate && validateStr != "false")
- throw new ConfigurationException ("Invalid value for validate attribute.",
- child);
+ string verb = ExtractAttributeValue ("verb", child, false);
+ string path = ExtractAttributeValue ("path", child, false);
+ string validateStr = 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);
+ }
if (name == "add") {
- string type = ExtractAttributeValue ("type", child);
+ string type = ExtractAttributeValue ("type", child, false);
if (child.Attributes.Count != 0)
- throw new ConfigurationException ("Unrecognized attribute", child);
+ ThrowException ("Unrecognized attribute", child);
HandlerItem item = new HandlerItem (verb, path, type, validate);
mapper.Add (item);
if (name == "remove") {
if (child.Attributes.Count != 0)
- throw new ConfigurationException ("Unrecognized attribute", child);
+ ThrowException ("Unrecognized attribute", child);
if (validate && mapper.Remove (verb, path) == null)
- throw new ConfigurationException ("There's no mapping to remove",
- child);
+ ThrowException ("There's no mapping to remove", child);
continue;
}
- throw new ConfigurationException ("Unexpected element", child);
+ ThrowException ("Unexpected element", child);
}
return mapper;
}
- static string ExtractAttributeValue (string attKey, XmlNode node)
+ static string ExtractAttributeValue (string attKey, XmlNode node, bool optional)
{
XmlNode att = node.Attributes.RemoveNamedItem (attKey);
- if (att == null)
- throw new ConfigurationException ("Required attribute not found.", node);
+ if (att == null) {
+ if (optional)
+ return null;
+ ThrowException ("Required attribute not found: " + attKey, node);
+ }
string value = att.Value;
- if (value == String.Empty)
- throw new ConfigurationException ("Required attribute is empty.", node);
+ if (value == String.Empty) {
+ string opt = optional ? "Optional" : "Required";
+ ThrowException (opt + " attribute is empty: " + attKey, node);
+ }
return value;
}
+
+ static void ThrowException (string msg, XmlNode node)
+ {
+ if (node != null && node.Name != String.Empty)
+ msg = msg + " (node name: " + node.Name + ") ";
+ throw new ConfigurationException (msg, node);
+ }
}
}
+2002-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * SimpleHandlerFactory.cs: new handler for .ashx files.
+
2002-09-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* System.Web.UI/PageHandlerFactory.cs: new file.
--- /dev/null
+//
+// System.Web.UI.SimpleHandlerFactory
+//
+// Authors:
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//
+// (C) 2002 Ximian, Inc (http://www.ximian.com)
+//
+
+using System.Web;
+
+namespace System.Web.UI
+{
+ class SimpleHandlerFactory : IHttpHandlerFactory
+ {
+ [MonoTODO]
+ public virtual IHttpHandler GetHandler (HttpContext context,
+ string requestType,
+ string virtualPath,
+ string path)
+ {
+ // This should handle *.ashx files
+ throw new NotImplementedException ();
+ }
+
+ public virtual void ReleaseHandler (System.Web.IHttpHandler handler)
+ {
+ }
+ }
+}
+
+2002-10-08 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * HttpApplication.cs: use handlers from configuration.
+ * HttpContext.cs: get handlers from ConfigurationSettings.
+
2002-10-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HttpMethodNotAllowedHandler.cs:
#endregion\r
\r
#region Methods\r
- [MonoTODO("Deal with other handlers")]\r
- private IHttpHandler CreateHttpHandler(HttpContext context, string type, string file, string path) {\r
- //return (IHttpHandler) HandlerFactoryConfiguration.FindHandler(type, path).Create();\r
- // FIXME: dummy stuff that should be replaced with machine.config + web.config stuff\r
- if (file.EndsWith (".aspx"))\r
- return new PageHandlerFactory ().GetHandler (context, type, file, path);\r
- else\r
- return new StaticFileHandler ();\r
+ private IHttpHandler CreateHttpHandler (HttpContext context, string type, string file, string path)\r
+ {\r
+ HandlerFactoryConfiguration handler = HttpContext.GetAppConfig ("system.web/httpHandlers")\r
+ as HandlerFactoryConfiguration;\r
+ if (handler == null)\r
+ throw new HttpException ("Cannot get system.web/httpHandlers handler.");\r
+\r
+ return (IHttpHandler) handler.FindHandler (type, path).Create ();\r
}\r
\r
[MonoTODO()]\r
//
using System;
using System.Collections;
+using System.Configuration;
using System.Security.Principal;
using System.Web.Caching;
using System.Web.Configuration;
throw new NotImplementedException();
}
- [MonoTODO("GetAppConfig(string name)")]
+ [MonoTODO("We gotta deal with web.config files too")]
public static object GetAppConfig (string name)
{
- if (null == name)
- throw new NotImplementedException();
-
- // This is a temp hack to fix the config stuff
- if (name.ToLower() == "system.web/httpmodules") {
- return new ModulesConfiguration();
- }
-
- if (name.ToLower() == "system.web/globalization") {
- return new System.Web.Configuration.GlobalizationConfiguration();
- }
-
- throw new NotImplementedException();
+ return ConfigurationSettings.GetConfig (name);
}
object IServiceProvider.GetService (Type service)
System.Web.Configuration/FormsProtectionEnum.cs
System.Web.Configuration/GlobalizationConfiguration.cs
System.Web.Configuration/HttpCapabilitiesBase.cs
+System.Web.Configuration/HandlerFactoryConfiguration.cs
System.Web.Configuration/HandlerFactoryProxy.cs
-System.Web.Configuration/HttpHandlerTypeMapper.cs
+System.Web.Configuration/HttpConfigurationContext.cs
System.Web.Configuration/HttpHandlersSectionHandler.cs
System.Web.Configuration/HandlerItem.cs
System.Web.Configuration/ModulesConfiguration.cs
System.Web.UI/PartialCachingAttribute.cs
System.Web.UI/PersistChildrenAttribute.cs
System.Web.UI/PersistenceModeAttribute.cs
+System.Web.UI/SimpleHandlerFactory.cs
System.Web.UI/TagPrefixAttribute.cs
System.Web.UI/TemplateContainerAttribute.cs
System.Web.UI/TemplateControlParser.cs